Package org.openstack.model.compute

Examples of org.openstack.model.compute.Server


        PlatformLayerKey instanceKey = instance.getKey();
        request.tags.add(Tag.buildParentTag(instanceKey));

        String serverName = buildServerName();

        Server created = openstack.createInstance(cloud, serverName, request);

        {
          Tag instanceTag = Tag.build(Tag.ASSIGNED, created.getId());
          platformLayer.addTag(instance.getKey(), instanceTag);
        }

        assignedInstanceIds.add(created.getId());
      }
    }

    if (assignedInstanceIds.isEmpty() && !OpsContext.isDelete()) {
      throw new OpsException("Instance not yet assigned");
    }

    Machine machine = null;
    OpsTarget target = null;

    if (!assignedInstanceIds.isEmpty()) {
      if (assignedInstanceIds.size() != 1) {
        log.warn("Multiple instance ids found: " + assignedInstanceIds);
      }

      // We just take the first instance id
      String assignedInstanceId = Iterables.getFirst(assignedInstanceIds, null);

      Server server = openstack.findServerById(cloud, assignedInstanceId);

      if (server == null) {
        if (OpsContext.isConfigure()) {
          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;
        }
View Full Code Here


  public Server findServerById(OpenstackCloud cloud, String serverId) throws OpsException {
    OpenstackComputeClient computeClient = getComputeClient(cloud);

    try {
      log.info("Getting server info for: " + serverId);
      Server server = computeClient.root().servers().server(serverId).show();
      return server;
    } catch (OpenstackNotFoundException e) {
      return null;
    } catch (OpenstackException e) {
      throw new OpsException("Error getting server", e);
View Full Code Here

        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());

        stateName = instanceInfo.getStatus();
        log.info("Instance state: " + stateName);

        // if (stateName.equals("scheduling")) {
        // continue;
        // }
        //
        if (stateName.equals("BUILD")) {
          break;
        }

        // if (stateName.equals("shutdown")) {
        // break;
        // }

        if (stateName.equals("ACTIVE")) {
          break;
        }

        Thread.sleep(1000);
      }

      // OpenstackComputeMachine machine = new OpenstackComputeMachine(instanceInfo.getAccessIPv4(), this,
      // server.getId());

      // Even if the machine is in 'error' state, we still want to associate it with us
      if (request.tags != null) {
        Server newServerInfo = new Server();
        Metadata metadata = new Metadata();
        for (Tag tag : request.tags) {
          Metadata.Item meta = new Metadata.Item();
          meta.setKey(tag.getKey());
          meta.setValue(tag.getValue());
          metadata.getItems().add(meta);
        }

        newServerInfo.setMetadata(metadata);
        log.info("Tagging server: " + server.getId());
        computeClient.root().servers().server(server.getId()).update(newServerInfo);
      }

      return server;
View Full Code Here

  // return instanceInfo;
  // }

  private static Server getInstanceInfo(OpenstackComputeClient computeClient, String serverId)
      throws OpenstackException {
    Server serverDetails = computeClient.root().servers().server(serverId).show();
    return serverDetails;
  }
View Full Code Here

    try {
      server = TimeoutPoll.poll(TimeSpan.FIVE_MINUTES, TimeSpan.TEN_SECONDS, new PollFunction<Server>() {
        @Override
        public Server call() throws Exception {
          log.info("Waiting for floating IP attach; polling server: " + serverId);
          Server server = compute.root().servers().server(serverId).show();

          List<Ip> publicIps = helpers.findPublicIps(cloud, server);
          if (publicIps.isEmpty()) {
            return null;
          }
View Full Code Here

    // Find the public address, although the OpenStack firewall may be blocking it
    publicAddress = machine.getNetworkPoint().getBestAddress(NetworkPoint.forPublicInternet());

    if (cloudBehaviours.supportsSecurityGroups()) {
      Server server = machine.getServer();
      SecurityGroup securityGroup = openstackHelpers.getMachineSecurityGroup(openstackComputeClient, server);

      securityGroup = openstackComputeClient.root().securityGroups().securityGroup(securityGroup.getId()).show();

      SecurityGroupRule matchingRule = findMatchingRule(securityGroup);
View Full Code Here

TOP

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

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.