Package org.openstack.client.compute

Examples of org.openstack.client.compute.AsyncServerOperation


          throw new OpsException("Unable to find assigned server: " + assignedInstanceId);
        }
      } else {
        server = openstack.ensureHasPublicIp(cloud, server);

        AsyncServerOperation powerOnOperation = openstack.ensurePoweredOn(cloud, server);
        if (powerOnOperation != null) {
          waitOperation(powerOnOperation);
        }

        machine = new OpenstackComputeMachine(openstack, cloud, server);

        SshKey sshKey = service.getSshKey();
        target = machine.getTarget(sshKey);
      }
    }

    if (!assignedInstanceIds.isEmpty() && OpsContext.isDelete()) {
      CloudBehaviours cloudBehaviours = new CloudBehaviours(cloud);
      boolean supportsSecurityGroups = cloudBehaviours.supportsSecurityGroups();

      for (String instanceId : assignedInstanceIds) {
        Server server = openstack.findServerById(cloud, instanceId);
        if (server == null) {
          log.warn("Could not find assigned server: " + instanceId + ", ignoring");
          continue;
        }

        SecurityGroup securityGroup = null;

        if (supportsSecurityGroups) {
          securityGroup = openstackHelpers.getMachineSecurityGroup(computeClient, server);
        }

        AsyncServerOperation terminateOperation = openstack.terminateInstance(cloud, instanceId);

        if (securityGroup != null) {
          // We need to terminate the instance before we delete the security group it uses
          if (terminateOperation != null) {
            waitOperation(terminateOperation);
View Full Code Here


            }
          }
        }
      }

      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();
      Server instanceInfo = null;
      String stateName = null;
      while (true) {
        instanceInfo = getInstanceInfo(computeClient, server.getId());
View Full Code Here

  public AsyncServerOperation terminateInstance(OpenstackCloud cloud, String instanceId) throws OpsException {
    try {
      OpenstackComputeClient computeClient = getComputeClient(cloud);

      log.info("Terminating server: " + instanceId);
      AsyncServerOperation deleteOperation = computeClient.deleteServer(instanceId);
      return deleteOperation;
    } catch (OpenstackNotFoundException e) {
      log.info("Could not find instance to be terminated, assuming already terminated: " + instanceId);
      return null;
    } catch (OpenstackException e) {
View Full Code Here

        OpenstackComputeClient computeClient = getComputeClient(cloud);

        String serverId = server.getId();
        log.info("Starting SHUTOFF server: " + serverId);

        AsyncServerOperation powerOnOperation = computeClient.powerServerOn(serverId);
        return powerOnOperation;
      } catch (OpenstackException e) {
        throw new OpsException("Error powering server on", e);
      }
    }
View Full Code Here

  // // }
  //

  public static AsyncServerOperation wrapServerCreate(OpenstackComputeClient client, Server server)
      throws OpenstackException {
    return new AsyncServerOperation(client, server, server.getId(), Lists.newArrayList("BUILD"),
        Lists.newArrayList("ACTIVE"));
  }
View Full Code Here

TOP

Related Classes of org.openstack.client.compute.AsyncServerOperation

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.