本文整理汇总了Java中org.openstack4j.model.compute.builder.ServerCreateBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ServerCreateBuilder类的具体用法?Java ServerCreateBuilder怎么用?Java ServerCreateBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerCreateBuilder类属于org.openstack4j.model.compute.builder包,在下文中一共展示了ServerCreateBuilder类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServerConfig
import org.openstack4j.model.compute.builder.ServerCreateBuilder; //导入依赖的package包/类
private static ServerCreate getServerConfig(Instance instance) {
ServerCreateBuilder builder = Builders.server()
.name(instance.getName())
.flavor(instance.getFlavor().getId())
.image(instance.getImage().getRealId());
if (!instance.getKeypairs().isEmpty()) {
builder = builder.keypairName(instance.getKeypairs().get(0).getName());
}
if (!instance.getNetworks().isEmpty()) {
List<String> networks = instance.getNetworks().stream()
.map(org.meridor.perspective.beans.Network::getId)
.collect(Collectors.toList());
builder = builder.networks(networks);
}
Optional<AvailabilityZone> availabilityZoneCandidate = Optional.ofNullable(instance.getAvailabilityZone());
if (availabilityZoneCandidate.isPresent()) {
builder = builder.availabilityZone(availabilityZoneCandidate.get().getName());
}
return builder.build();
}
示例2: doRequest
import org.openstack4j.model.compute.builder.ServerCreateBuilder; //导入依赖的package包/类
@Override
public Server doRequest(OSClient api) throws NotFoundException, ResponseException {
ServerService serverService = api.compute().servers();
ServerCreateBuilder serverCreateBuilder = serverService.serverBuilder().name(this.serverName)
.flavor(getFlavorId()).image(getImageId()).keypairName(this.keyPair).addMetadata(this.metadata);
for (String securityGroup : this.securityGroups) {
serverCreateBuilder.addSecurityGroup(securityGroup);
}
if (this.networks != null && !this.networks.isEmpty()) {
serverCreateBuilder.networks(getNetworkIds());
}
if (this.encodedUserData != null) {
serverCreateBuilder.userData(this.encodedUserData);
}
ServerCreate serverCreate = serverCreateBuilder.build();
Server server = serverService.boot(serverCreate);
// first call to boot only seem to return a stripped Server object
// (missing fields such as status). re-fetch it before returning.
return serverService.get(server.getId());
}
示例3: apply
import org.openstack4j.model.compute.builder.ServerCreateBuilder; //导入依赖的package包/类
@Override
public VirtualMachine apply(VirtualMachineTemplate virtualMachineTemplate) {
//todo we currently simply assume that this is a zone (hosts may follow)
Location zone = locationGetStrategy.get(virtualMachineTemplate.locationId());
checkNotNull(zone, "zone is null");
checkState(LocationScope.ZONE.equals(zone.locationScope()), "zone is no zone");
checkState(zone.parent().isPresent(), "zone has no parent region");
Location region = zone.parent().get();
List<String> networks = new ArrayList<>(1);
if (networkStrategy.get() != null) {
networks.add(networkStrategy.get());
}
//keypair
String keyPairName = null;
Keypair keypair = null;
if (virtualMachineTemplate.templateOptions().isPresent()) {
keyPairName = virtualMachineTemplate.templateOptions().get().keyPairName();
}
if (keyPairName == null) {
keypair = osClient.compute().keypairs()
.create(namingStrategy.generateNameBasedOnName(null), null);
}
List<String> secGroups = new ArrayList<>(1);
if (virtualMachineTemplate.templateOptions().isPresent()) {
secGroups.add(createSecurityGroupFromTemplateOption
.create(virtualMachineTemplate.templateOptions().get(),
virtualMachineTemplate.locationId()));
}
if (defaultSecurityGroup != null) {
secGroups.add(defaultSecurityGroup);
}
//todo this code also assumes that location is always the availability zone
final ServerCreateBuilder serverCreateBuilder = Builders.server()
.name(namingStrategy.generateUniqueNameBasedOnName(virtualMachineTemplate.name()))
.flavor(IdScopeByLocations.from(virtualMachineTemplate.hardwareFlavorId()).getId())
.image(IdScopeByLocations.from(virtualMachineTemplate.imageId()).getId())
.availabilityZone(IdScopeByLocations.from(virtualMachineTemplate.locationId()).getId())
.networks(networks).keypairName(keyPairName);
for (String secGroup : secGroups) {
serverCreateBuilder.addSecurityGroup(secGroup);
}
final ServerCreate serverCreate = serverCreateBuilder.build();
//todo make timeout configurable
final Server createdServer = osClient.useRegion(region.id()).compute().servers()
.bootAndWaitActive(serverCreate, 120000);
// we retrieve the newly created server to get additional details the creation request does
// not contain
final Server retrievedServer = osClient.compute().servers().get(createdServer.getId());
checkState(retrievedServer != null,
"Could not retrieve newly created server with id " + createdServer.getId());
return virtualMachineConverter
.apply(new ServerInRegion(createdServer, retrievedServer, region, keypair));
}