Package org.openstack.model.compute

Examples of org.openstack.model.compute.ServerForCreate


        }
      }

      AsyncServerOperation createServerOperation;
      {
        ServerForCreate create = new ServerForCreate();

        create.setName(serverName);

        if (request.sshPublicKey != null) {
          if (cloudBehaviours.supportsPublicKeys()) {
            OpenstackCloudHelpers cloudHelpers = new OpenstackCloudHelpers();
            KeyPair keyPair = cloudHelpers.ensurePublicKeyUploaded(computeClient, request.sshPublicKeyName,
                request.sshPublicKey);
            create.setKeyName(keyPair.getName());
          } else if (cloudBehaviours.supportsFileInjection()) {
            String fileContents = SshKeys.serialize(request.sshPublicKey);
            create.addUploadFile("/root/.ssh/authorized_keys", Utf8.getBytes(fileContents));
          } else {
            throw new OpsException("No supported SSH key mechanism on cloud");
          }
        }

        create.setImageRef(foundImage.getId());

        Flavor flavor = getClosestInstanceType(computeClient, request);
        if (flavor == null) {
          throw new OpsException("Cannot determine instance type for request");
        }
        create.setFlavorRef(flavor.getId());

        if (request.securityGroups != null) {
          // TODO: Reimplement if needed
          throw new UnsupportedOperationException();
        }

        if (createdSecurityGroup != null) {
          ServerForCreate.SecurityGroup serverSecurityGroup = new ServerForCreate.SecurityGroup();
          serverSecurityGroup.setName(createdSecurityGroup.getName());
          create.getSecurityGroups().add(serverSecurityGroup);
        }

        create.setConfigDrive(cloudBehaviours.useConfigDrive());

        log.info("Launching new server: " + create.getName());
        createServerOperation = computeClient.createServer(create);
      }

      log.info("Waiting for server to be ready");
      Server server = createServerOperation.waitComplete();
View Full Code Here

TOP

Related Classes of org.openstack.model.compute.ServerForCreate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.