Package com.amazonaws.services.ec2.model

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


            throw new GFacProviderException("EC2 Username is empty", jobExecutionContext);

        /* Need to start EC2 instance before running it */
        AWSCredentials credential =
                new BasicAWSCredentials(amazonSecurityContext.getAccessKey(), amazonSecurityContext.getSecretKey());
        AmazonEC2Client ec2client = new AmazonEC2Client(credential);
        GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, ApplicationJobStatus.AUTHENTICATE);
        initEc2Environment(jobExecutionContext, ec2client);
        checkConnection(instance, ec2client);
    }
View Full Code Here


            throw new GFacProviderException("EC2 Username is empty");

        /* Need to start EC2 instance before running it */
        AWSCredentials credential =
                new BasicAWSCredentials(amazonSecurityContext.getAccessKey(), amazonSecurityContext.getSecretKey());
        AmazonEC2Client ec2client = new AmazonEC2Client(credential);
        GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, ApplicationJobStatus.AUTHENTICATE);
        initEc2Environment(jobExecutionContext, ec2client);
        checkConnection(instance, ec2client);
    }
View Full Code Here

                                    "Warning", "The file " + file.getAbsolutePath() + " exists.");

                        } else {
                            AWSCredentials credential =
                                    new BasicAWSCredentials(accessID, secretID);
                            AmazonEC2Client ec2client = new AmazonEC2Client(credential);

                            try {
                                EC2ProviderUtil.buildKeyPair(ec2client, EC2Provider.KEY_PAIR_NAME);
                            } catch (NoSuchAlgorithmException e1) {
                                ChangeCredentialWindow.this.engine.getGUI().getErrorWindow().
View Full Code Here

            throw new GFacProviderException("EC2 Username is empty", jobExecutionContext);

        /* Need to start EC2 instance before running it */
        AWSCredentials credential =
                new BasicAWSCredentials(amazonSecurityContext.getAccessKey(), amazonSecurityContext.getSecretKey());
        AmazonEC2Client ec2client = new AmazonEC2Client(credential);
        GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, ApplicationJobStatus.AUTHENTICATE);
        initEc2Environment(jobExecutionContext, ec2client);
        checkConnection(instance, ec2client);
    }
View Full Code Here

        /*
         * Need to start EC2 instance before running it
         */
        AWSCredentials credential = new BasicAWSCredentials(access_key, secret_key);
        AmazonEC2Client ec2client = new AmazonEC2Client(credential);

        try {
            /*
             * Build key pair before start instance
             */
            buildKeyPair(ec2client);

            // right now, we can run it on one host
            if (ami_id != null)
                this.instance = startInstances(ec2client, ami_id, ins_type, execContext).get(0);
            else {

                // already running instance
                DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
                DescribeInstancesResult describeInstancesResult = ec2client.describeInstances(describeInstancesRequest.withInstanceIds(ins_id));

                if (describeInstancesResult.getReservations().size() == 0 || describeInstancesResult.getReservations().get(0).getInstances().size() == 0) {
                    throw new GfacException("Instance not found:" + ins_id);
                }

                this.instance = describeInstancesResult.getReservations().get(0).getInstances().get(0);

                // check instance keypair
                if (this.instance.getKeyName() == null || !this.instance.getKeyName().equals(KEY_PAIR_NAME))
                    throw new GfacException("Keypair for instance:" + ins_id + " is not valid");
            }

            //TODO send out instance id
            //execContext.getNotificationService().sendResourceMappingNotifications(this.instance.getPublicDnsName(), "EC2 Instance " + this.instance.getInstanceId() + " is running with public name " + this.instance.getPublicDnsName(), this.instance.getInstanceId());


            /*
             * 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) {
                    /*
                     * If exception is from duplicate room, ignore it.
                     */
                    if (!as.getErrorCode().equals("InvalidPermission.Duplicate"))
View Full Code Here

            throw new IllegalStateException("Expected EC2 datacenter manager, found: " + datacenterManager);
        }

        Ec2DatacenterManager manager = (Ec2DatacenterManager) datacenterManager;

        AmazonEC2Client ec2 = manager.getEc2Client(host);

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

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

        return privateIpAddress;
    }
View Full Code Here

        if (secretData.hasUsername()) {
            String accessKey = secretData.getUsername();
            String secretKey = secretData.getPassword();
            AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
            ec2Client = new AmazonEC2Client(awsCredentials);
        }
    }
View Full Code Here

        if (this.ec2Client != null) {
            return this.ec2Client;
        }

        CredentialsProvider credentialsProvider = new CredentialsProvider(host);
        AmazonEC2Client ec2Client = new AmazonEC2Client(credentialsProvider);
        return ec2Client;
    }
View Full Code Here

                    + "Make sure you've configured your credentials in: " + configFile.getAbsolutePath() + "\n"
                    + "For more information on configuring your credentials, see "
                    + "http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html");
        }

        ec2 = new AmazonEC2Client(credentialsProvider);
        s3  = new AmazonS3Client(credentialsProvider);
    }
View Full Code Here

  private AmazonEC2 newClient() {

    final AWSCredentials credentials = new BasicAWSCredentials(
        this.awsAccessKey, this.awsSecretKey);

    final AmazonEC2 amazonClient = new AmazonEC2Client(credentials);

    amazonClient.setEndpoint(endpoint);

    return amazonClient;

  }
View Full Code Here

TOP

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

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.