Package com.amazonaws.services.ec2.model

Examples of com.amazonaws.services.ec2.model.Image


      final DescribeImagesResult result = amazonClient
          .describeImages(request);

      final List<Image> imageList = result.getImages();

      final Image image;

      if (isTimeoutPending(timeStart)) {
        image = newImageWithStatus(State.UNKNOWN.value, "timeout",
            "image create timeout while waiting");
      } else if (imageList == null || imageList.isEmpty()) {
        image = newImageWithStatus(State.UNKNOWN.value, "missing",
            "image create missing in descriptions");
      } else {
        image = imageList.get(0);
      }

      final String value = image.getState();

      final State state = State.fromValue(value);

      switch (state) {
View Full Code Here


       */

      if (newKey) {
        DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(KEY_PAIR_NAME);
        ec2.deleteKeyPair(deleteKeyPairRequest);
        ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(KEY_PAIR_NAME, encodedPublicKey);
        ec2.importKeyPair(importKeyPairRequest);
      }

    } catch (AmazonServiceException ase) {
      /*
       * Key doesn't exists, import new key.
       */
      if(ase.getErrorCode().equals("InvalidKeyPair.NotFound")){     
        ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(KEY_PAIR_NAME, encodedPublicKey);
        ec2.importKeyPair(importKeyPairRequest);
      }else{
        throw ase;
      }
    }
View Full Code Here

            /* If key exists and new key is created, delete old key and replace
             * with new one. Else, do nothing */
            if (newKey) {
                DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(keyPairName);
                ec2.deleteKeyPair(deleteKeyPairRequest);
                ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(keyPairName, encodedPublicKey);
                ec2.importKeyPair(importKeyPairRequest);
            }

        } catch (AmazonServiceException ase) {
            /* Key doesn't exists, import new key. */
            if (ase.getErrorCode().equals("InvalidKeyPair.NotFound")) {
                ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(keyPairName, encodedPublicKey);
                ec2.importKeyPair(importKeyPairRequest);
            } else {
                throw ase;
            }
        }
View Full Code Here

public class EC2RequestHandler extends AbstractRequestHandler {
    public void beforeRequest(Request<?> request) {
        AmazonWebServiceRequest originalRequest = request.getOriginalRequest();
        if (originalRequest instanceof ImportKeyPairRequest) {
            ImportKeyPairRequest importKeyPairRequest = (ImportKeyPairRequest)originalRequest;
            String publicKeyMaterial = importKeyPairRequest.getPublicKeyMaterial();
            String encodedKeyMaterial = new String(Base64.encodeBase64(publicKeyMaterial.getBytes()));
            importKeyPairRequest.setPublicKeyMaterial(encodedKeyMaterial);
        }
    }
View Full Code Here

    }
  }

  private boolean anyInstancesStateEqual(List<Instance> instances, InstanceStateName name) {
    for (Iterator<Instance> iterator = instances.iterator(); iterator.hasNext();) {
      Instance instance = (Instance) iterator.next();

      // if one of instance is not running, return false
      if (InstanceStateName.fromValue(instance.getState().getName()) == name) {
        return true;
      }
    }
    return false;
  }
View Full Code Here

    return false;
  }

  private boolean allInstancesStateEqual(List<Instance> instances, InstanceStateName name) {
    for (Iterator<Instance> iterator = instances.iterator(); iterator.hasNext();) {
      Instance instance = (Instance) iterator.next();

      // if one of instance is not running, return false
      if (InstanceStateName.fromValue(instance.getState().getName()) != name) {
        return false;
      }
    }
    return true;
  }
View Full Code Here

  }

  private List<String> getInstanceIDs(List<Instance> instances) {
    List<String> ret = new ArrayList<String>();
    for (Iterator<Instance> iterator = instances.iterator(); iterator.hasNext();) {
      Instance instance = (Instance) iterator.next();
      ret.add(instance.getInstanceId());
    }
    return ret;
 
View Full Code Here

        String ec2InstanceId = manager.findHost(host);
        if (ec2InstanceId == null) {
            throw new IllegalStateException("Unable to find EC2 instance for host: " + host);
        }

        Instance ec2Instance = describeInstance(ec2, ec2InstanceId);

        String subnetId = ec2Instance.getSubnetId();

        // Use the default network interface
        int networkInterfaceIndex = 0;

        InstanceNetworkInterface networkInterface = findNetworkInterface(ec2Instance, networkInterfaceIndex);
View Full Code Here

        }
        return networkInterface;
    }

    private Instance describeInstance(AmazonEC2Client ec2, String ec2InstanceId) {
        Instance ec2Instance = null;
        {
            DescribeInstancesRequest request = new DescribeInstancesRequest();
            request.setInstanceIds(Collections.singletonList(ec2InstanceId));
            DescribeInstancesResult response = ec2.describeInstances(request);
View Full Code Here

        String subnetId = ec2Instance.getSubnetId();

        // Use the default network interface
        int networkInterfaceIndex = 0;

        InstanceNetworkInterface networkInterface = findNetworkInterface(ec2Instance, networkInterfaceIndex);

        if (networkInterface == null) {
            throw new UnsupportedOperationException();

            /*
             * // TODO: Reuse unattached network interfaces (with the
             * fathomcloud // tag)???
             *
             * NetworkInterface created; { CreateNetworkInterfaceRequest request
             * = new CreateNetworkInterfaceRequest();
             * request.setSubnetId(subnetId);
             *
             * CreateNetworkInterfaceResult response =
             * ec2.createNetworkInterface(request); created =
             * response.getNetworkInterface();
             * log.info("Created network interface {}",
             * created.getNetworkInterfaceId()); }
             *
             * addTag(ec2, created, "fathomcloud", "1");
             *
             * { AttachNetworkInterfaceRequest request = new
             * AttachNetworkInterfaceRequest(); request.setDeviceIndex(1);
             * request.setInstanceId(ec2InstanceId);
             * request.setNetworkInterfaceId(created.getNetworkInterfaceId());
             *
             * AttachNetworkInterfaceResult response =
             * ec2.attachNetworkInterface(request);
             * log.info("Attached network interface as {}",
             * response.getAttachmentId()); }
             *
             * ec2Instance = describeInstance(ec2, ec2InstanceId);
             *
             * networkInterface = findNetworkInterface(ec2Instance, 1);
             *
             * if (networkInterface == null) { throw new IllegalStateException(
             * "Did not find network interface after attaching: " +
             * created.getNetworkInterfaceId()); }
             */
        }

        InstancePrivateIpAddress privateIp = findUnusedIp(networkInterface);

        if (privateIp == null) {
            // TODO: Prune private ip addresses from NICs?
            // TODO: Need to tag??

            {
                AssignPrivateIpAddressesRequest request = new AssignPrivateIpAddressesRequest();
                request.setNetworkInterfaceId(networkInterface.getNetworkInterfaceId());
                request.setSecondaryPrivateIpAddressCount(1);
                ec2.assignPrivateIpAddresses(request);
            }

            ec2Instance = describeInstance(ec2, ec2InstanceId);
            networkInterface = findNetworkInterface(ec2Instance, networkInterfaceIndex);
            privateIp = findUnusedIp(networkInterface);

            if (privateIp == null) {
                throw new IllegalStateException("Unable to find private IP address");
            }
        }

        String privateIpAddress = privateIp.getPrivateIpAddress();

        {
            AssociateAddressRequest request = new AssociateAddressRequest();
            request.setPublicIp(vip.getData().getIp());
            request.setPrivateIpAddress(privateIpAddress);
            request.setNetworkInterfaceId(networkInterface.getNetworkInterfaceId());
            request.setInstanceId(ec2InstanceId);

            AssociateAddressResult response = ec2.associateAddress(request);
            log.info("Associated public IP with assocation id: {}", response.getAssociationId());
        }
View Full Code Here

TOP

Related Classes of com.amazonaws.services.ec2.model.Image

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.