• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ServerCreateBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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();
}
 
开发者ID:meridor,项目名称:perspective-backend,代码行数:25,代码来源:AddInstanceOperation.java


示例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());
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:24,代码来源:CreateServerRequest.java


示例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));
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:60,代码来源:Openstack4jCreateVirtualMachineStrategy.java



注:本文中的org.openstack4j.model.compute.builder.ServerCreateBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CacheFlagProto类代码示例发布时间:2022-05-22
下一篇:
Java ProcStarter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap