Package com.amazonaws.services.ec2.model

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


        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

        }
        return null;
    }

    private InstanceNetworkInterface findNetworkInterface(Instance ec2Instance, int deviceIndex) {
        InstanceNetworkInterface networkInterface = null;
        for (InstanceNetworkInterface i : ec2Instance.getNetworkInterfaces()) {
            InstanceNetworkInterfaceAttachment attachment = i.getAttachment();
            if (attachment == null) {
                log.error("EC2 network attachment on instance was null");
                continue;
View Full Code Here

        log.info("Added tag: {}={} to {}", key, value, id);
    }

    private InstancePrivateIpAddress findUnusedIp(InstanceNetworkInterface networkInterface) {
        InstanceNetworkInterfaceAssociation unused = null;
        for (InstancePrivateIpAddress privateIpAddress : networkInterface.getPrivateIpAddresses()) {
            InstanceNetworkInterfaceAssociation association = privateIpAddress.getAssociation();
            if (association == null) {
                return privateIpAddress;
            }
        }
        return null;
View Full Code Here

    }

    private InstanceNetworkInterface findNetworkInterface(Instance ec2Instance, int deviceIndex) {
        InstanceNetworkInterface networkInterface = null;
        for (InstanceNetworkInterface i : ec2Instance.getNetworkInterfaces()) {
            InstanceNetworkInterfaceAttachment attachment = i.getAttachment();
            if (attachment == null) {
                log.error("EC2 network attachment on instance was null");
                continue;
            }

            Integer attachmentDeviceIndex = attachment.getDeviceIndex();
            if (attachmentDeviceIndex == null) {
                log.error("EC2 device index was null");
                continue;
            }
View Full Code Here

             * "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);
View Full Code Here

                if (filterByTag) {
                    logger.trace("filtering out instance {} based tags {}, not part of {}", instance.getInstanceId(), tags, instance.getTags());
                    continue;
                }

                InstanceState state = instance.getState();
                if (state.getName().equalsIgnoreCase("pending") || state.getName().equalsIgnoreCase("running")) {
                    String address = null;
                    switch (hostType) {
                        case PRIVATE_DNS:
                            address = instance.getPrivateDnsName();
                            break;
View Full Code Here

      /*
       * Make sure port 22 is connectable
       */
      for (GroupIdentifier g : this.instance.getSecurityGroups()) {
        IpPermission ip = new IpPermission();
        ip.setIpProtocol("tcp");
        ip.setFromPort(22);
        ip.setToPort(22);
        AuthorizeSecurityGroupIngressRequest r = new AuthorizeSecurityGroupIngressRequest();
        r = r.withIpPermissions(ip.withIpRanges("0.0.0.0/0"));
        r.setGroupId(g.getGroupId());
        try {
          ec2client.authorizeSecurityGroupIngress(r);
        } catch (AmazonServiceException as) {
          /*
 
View Full Code Here

     * of security group info.
     */
      if (response instanceof DescribeSpotInstanceRequestsResult) {
        DescribeSpotInstanceRequestsResult result = (DescribeSpotInstanceRequestsResult)response;
        for (SpotInstanceRequest spotInstanceRequest : result.getSpotInstanceRequests()) {
          LaunchSpecification launchSpecification = spotInstanceRequest.getLaunchSpecification();
          populateLaunchSpecificationSecurityGroupNames(launchSpecification);
        }
      } else if (response instanceof RequestSpotInstancesResult) {
        RequestSpotInstancesResult result = (RequestSpotInstancesResult)response;
        for (SpotInstanceRequest spotInstanceRequest : result.getSpotInstanceRequests()) {
          LaunchSpecification launchSpecification = spotInstanceRequest.getLaunchSpecification();
          populateLaunchSpecificationSecurityGroupNames(launchSpecification);
        }
      } else if (response instanceof DescribeInstancesResult) {
        DescribeInstancesResult result = (DescribeInstancesResult)response;
        for (Reservation reservation : result.getReservations()) {
View Full Code Here

TOP

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

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.