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