当前位置: 首页>>代码示例>>Java>>正文


Java ServerCreate类代码示例

本文整理汇总了Java中org.openstack4j.model.compute.ServerCreate的典型用法代码示例。如果您正苦于以下问题:Java ServerCreate类的具体用法?Java ServerCreate怎么用?Java ServerCreate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ServerCreate类属于org.openstack4j.model.compute包,在下文中一共展示了ServerCreate类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import org.openstack4j.model.compute.ServerCreate; //导入依赖的package包/类
public Server create(String name, String keypairName, String imageId, String flavorId, 
		List<String> networks, boolean powerOn) {
	Assert.notNull(client());
	
	ServerCreate serverCreate = client().compute().servers().serverBuilder()
		.name(name)
		.keypairName(keypairName)
		.image(imageId)
		.flavor(flavorId)
		.networks(networks)
		.build();
	
	Server server = null;
	if (powerOn)
		server = client().compute().servers().boot(serverCreate) ;
	
	return server;
}
 
开发者ID:evoila,项目名称:cfsummiteu2017,代码行数:19,代码来源:NovaFluent.java

示例2: getServerConfig

import org.openstack4j.model.compute.ServerCreate; //导入依赖的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

示例3: doRequest

import org.openstack4j.model.compute.ServerCreate; //导入依赖的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

示例4: apply

import org.openstack4j.model.compute.ServerCreate; //导入依赖的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

示例5: createServer

import org.openstack4j.model.compute.ServerCreate; //导入依赖的package包/类
@Override
public Server createServer(String serverName, String imageId, String flavorId, String keyPairName) {
	try {

		Server newServer = null;
		String networkId = null;

		// Adhering to openstack format of subnet names 'subnet-<name>'.
		String networkName = "subnet-" + properties.getProperty(Constants.OS_NETWORK_NAME);

		for( Subnet net : os.networking().subnet().list() ) {
			if(net.getName().equals(networkName)) {
				networkId = net.getNetworkId();
				logger.info("Using network " + networkName + " with ID: " + networkId);
				break;
			}
		}

		if(networkId != null) {

			List<String> srvNet = new LinkedList<String>();
			srvNet.add(networkId);

			ServerCreate sc = Builders.server()
					.name(serverName)
					.flavor(flavorId)
					.image(imageId)
					.networks(srvNet)
					.keypairName(keyPairName)
					.build();

			//Boot the Server
			newServer = os.compute().servers().boot(sc);

			logger.info("New server created with ID: " + newServer.getId());

		}
		else {
			logger.error("Network with name " + networkName + " not found.");
		}
		return newServer;
	}
	catch( Exception ex ) {
		ex.printStackTrace();
		// TODO: Check with the team on how to handle exceptions.
		logger.error("Failed to create server.");
		return null;
	}
}
 
开发者ID:apache,项目名称:airavata,代码行数:50,代码来源:OpenstackIntfImpl.java


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