Search in sources :

Example 6 with DescribeKeyPairsResult

use of com.amazonaws.services.ec2.model.DescribeKeyPairsResult in project airavata by apache.

the class AmazonUtil method loadKeypairs.

/**
 * Load keypairs
 *
 * @return list of keypairs
 */
public static List<String> loadKeypairs() {
    List<String> resultList = new ArrayList<String>();
    DescribeKeyPairsResult results = getEC2Client().describeKeyPairs();
    for (KeyPairInfo key : results.getKeyPairs()) {
        resultList.add(key.getKeyName());
    }
    return resultList;
}
Also used : KeyPairInfo(com.amazonaws.services.ec2.model.KeyPairInfo) DescribeKeyPairsResult(com.amazonaws.services.ec2.model.DescribeKeyPairsResult) ArrayList(java.util.ArrayList)

Example 7 with DescribeKeyPairsResult

use of com.amazonaws.services.ec2.model.DescribeKeyPairsResult in project cloudbreak by hortonworks.

the class AwsSetup method validateExistingKeyPair.

private void validateExistingKeyPair(InstanceAuthentication instanceAuthentication, AwsCredentialView credentialView, String region) {
    String keyPairName = awsClient.getExistingKeyPairName(instanceAuthentication);
    if (StringUtils.isNoneEmpty(keyPairName)) {
        boolean keyPairIsPresentOnEC2 = false;
        try {
            AmazonEC2Client client = awsClient.createAccess(credentialView, region);
            DescribeKeyPairsResult describeKeyPairsResult = client.describeKeyPairs(new DescribeKeyPairsRequest().withKeyNames(keyPairName));
            keyPairIsPresentOnEC2 = describeKeyPairsResult.getKeyPairs().stream().findFirst().isPresent();
        } catch (RuntimeException e) {
            String errorMessage = String.format("Failed to get the key pair [name: '%s'] from EC2 [roleArn:'%s'], detailed message: %s.", keyPairName, credentialView.getRoleArn(), e.getMessage());
            LOGGER.error(errorMessage, e);
        }
        if (!keyPairIsPresentOnEC2) {
            throw new CloudConnectorException(String.format("The key pair '%s' could not be found in the '%s' region of EC2.", keyPairName, region));
        }
    }
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) DescribeKeyPairsRequest(com.amazonaws.services.ec2.model.DescribeKeyPairsRequest) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) DescribeKeyPairsResult(com.amazonaws.services.ec2.model.DescribeKeyPairsResult)

Aggregations

DescribeKeyPairsResult (com.amazonaws.services.ec2.model.DescribeKeyPairsResult)7 KeyPairInfo (com.amazonaws.services.ec2.model.KeyPairInfo)5 DescribeKeyPairsRequest (com.amazonaws.services.ec2.model.DescribeKeyPairsRequest)3 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 AuthorizeSecurityGroupIngressRequest (com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest)2 CreateSecurityGroupRequest (com.amazonaws.services.ec2.model.CreateSecurityGroupRequest)2 IpPermission (com.amazonaws.services.ec2.model.IpPermission)2 ArrayList (java.util.ArrayList)2 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 CreateKeyPairRequest (com.amazonaws.services.ec2.model.CreateKeyPairRequest)1 CreateKeyPairResult (com.amazonaws.services.ec2.model.CreateKeyPairResult)1 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)1 DescribeSecurityGroupsRequest (com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest)1 DescribeSecurityGroupsResult (com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)1 IpRange (com.amazonaws.services.ec2.model.IpRange)1 MonitorInstancesRequest (com.amazonaws.services.ec2.model.MonitorInstancesRequest)1 RebootInstancesRequest (com.amazonaws.services.ec2.model.RebootInstancesRequest)1 RunInstancesRequest (com.amazonaws.services.ec2.model.RunInstancesRequest)1