public static void main(String[] args) { final String USAGE = "To run this example, supply a key pair name\n" + "Ex: DeleteKeyPair <key-pair-name>\n"; if (args.length != 1) { System.out.println(USAGE); System.exit(1); } String key_name = args[0]; final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DeleteKeyPairRequest request = new DeleteKeyPairRequest() .withKeyName(key_name); DeleteKeyPairResult response = ec2.deleteKeyPair(request); System.out.printf( "Successfully deleted key pair named %s", key_name); }
@Override public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) { String keyName = KeyPairs.formatNameFromBusinessKey(execution.getProcessBusinessKey()); LOG.info(">> Importing admin access key pair as {}", keyName); final String publicKey = pool.getAdminAccess().getPublicKey(); try { importPoolPublicKeyPair(client, keyName, publicKey); } catch (AmazonServiceException e) { if (e.getErrorCode().equals(ErrorCodes.DUPLICATE_KEYPAIR)) { LOG.info("<< Duplicate key pair found. Re-importing from pool description"); client.deleteKeyPair(new DeleteKeyPairRequest().withKeyName(keyName)); importPoolPublicKeyPair(client, keyName, publicKey); } } }
private List<KeyPairInfo> deleteKeyPair(String keypairName) { List<KeyPairInfo> keys; try { DescribeKeyPairsRequest query = new DescribeKeyPairsRequest().withKeyNames(keypairName); DescribeKeyPairsResult keysFound = ec2Client.describeKeyPairs(query); keys = keysFound.getKeyPairs(); } catch (AmazonServiceException exception) { keys = new LinkedList<>(); } if (keys.size() > 0) { DeleteKeyPairRequest deleteRequest = new DeleteKeyPairRequest().withKeyName(keypairName); ec2Client.deleteKeyPair(deleteRequest); } return keys; }
@Override public void delete(Instance instance) { DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(); deleteKeyPairRequest.withKeyName(instance.getKeyName()); ec2UserClient.amazonEC2Async().deleteKeyPair(deleteKeyPairRequest); }
public void execute() { checkParams(); AmazonEC2Client ec2Client = getOrCreateClient(AmazonEC2Client.class); ec2Client .deleteKeyPair(new DeleteKeyPairRequest().withKeyName(keyName)); AmazonCloudFormationClient cloudFormationClient = getOrCreateClient(AmazonCloudFormationClient.class); cloudFormationClient.deleteStack(new DeleteStackRequest() .withStackName(stackName)); }
private void deleteKeyPair(AuthenticatedContext ac, CloudStack stack) { AwsCredentialView awsCredential = new AwsCredentialView(ac.getCloudCredential()); String region = ac.getCloudContext().getLocation().getRegion().value(); if (!awsClient.existingKeyPairNameSpecified(stack.getInstanceAuthentication())) { try { AmazonEC2Client client = awsClient.createAccess(awsCredential, region); DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(awsClient.getKeyPairName(ac)); client.deleteKeyPair(deleteKeyPairRequest); } catch (Exception e) { String errorMessage = String.format("Failed to delete public key [roleArn:'%s', region: '%s'], detailed message: %s", awsCredential.getRoleArn(), region, e.getMessage()); LOGGER.error(errorMessage, e); } } }
@Override public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) { String keyName = KeyPairs.formatNameFromBusinessKey(execution.getProcessBusinessKey()); LOG.info(">> Deleting key pair {}", keyName); client.deleteKeyPair(new DeleteKeyPairRequest().withKeyName(keyName)); }
@Override public void deleteKeyPair(DeleteKeyPairRequest deleteKeyPairRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
public void deleteKeyPair(String keyPairName) { logger.info("delete keyPair, keyName={}", keyPairName); ec2.deleteKeyPair(new DeleteKeyPairRequest(keyPairName)); }
@Override public void delete(DeleteKeyPairRequest request) { delete(request, null); }
@Override public void delete(DeleteKeyPairRequest request, ResultCapture<Void> extractor) { resource.performAction("Delete", request, extractor); }
@Override public void delete(ResultCapture<Void> extractor) { DeleteKeyPairRequest request = new DeleteKeyPairRequest(); delete(request, extractor); }
@Override public void tearDown() throws Exception { client.deleteKeyPair(new DeleteKeyPairRequest().withKeyName(KEYPAIR_NAME)); super.tearDown(); }
/** * Performs the <code>Delete</code> action. * * <p> * The following request parameters will be populated from the data of this * <code>KeyPair</code> resource, and any conflicting parameter value set in * the request will be overridden: * <ul> * <li> * <b><code>KeyName</code></b> * - mapped from the <code>Name</code> identifier. * </li> * </ul> * * <p> * * @see DeleteKeyPairRequest */ void delete(DeleteKeyPairRequest request);
/** * Performs the <code>Delete</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * The following request parameters will be populated from the data of this * <code>KeyPair</code> resource, and any conflicting parameter value set in * the request will be overridden: * <ul> * <li> * <b><code>KeyName</code></b> * - mapped from the <code>Name</code> identifier. * </li> * </ul> * * <p> * * @see DeleteKeyPairRequest */ void delete(DeleteKeyPairRequest request, ResultCapture<Void> extractor);