List of usage examples for com.amazonaws.services.ec2.model KeyPairInfo getKeyName
public String getKeyName()
The name of the key pair.
From source file:aws.example.ec2.DescribeKeyPairs.java
License:Open Source License
public static void main(String[] args) { final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DescribeKeyPairsResult response = ec2.describeKeyPairs(); for (KeyPairInfo key_pair : response.getKeyPairs()) { System.out.printf("Found key pair with name %s " + "and fingerprint %s", key_pair.getKeyName(), key_pair.getKeyFingerprint()); }/*from ww w . ja va 2 s .co m*/ }
From source file:com.boxupp.dao.AwsProjectDAOManager.java
License:Apache License
private StatusBean validateKeyPair(AmazonEC2Client ec2Client, String keyPair) throws AmazonServiceException { StatusBean statusBean = new StatusBean(); List<com.amazonaws.services.ec2.model.Region> regions = ec2Client.describeRegions().getRegions(); for (com.amazonaws.services.ec2.model.Region region : regions) { ec2Client.setRegion(com.amazonaws.regions.Region .getRegion(com.amazonaws.regions.Regions.fromName(region.getRegionName()))); List<KeyPairInfo> keyPairs = ec2Client.describeKeyPairs().getKeyPairs(); for (KeyPairInfo keyPairInfo : keyPairs) { if (keyPairInfo.getKeyName().equals(keyPair)) { statusBean.setStatusCode(0); statusBean.setStatusMessage("Key Pair validated with region " + region.getRegionName()); return statusBean; }/* w w w . j a v a 2s . c o m*/ } } statusBean.setStatusCode(1); statusBean.setStatusMessage("Key Pair not found Please enter a valid key pair"); return statusBean; }
From source file:com.cloudera.director.aws.ec2.EC2Provider.java
License:Apache License
/** * Returns the key name corresponding to the specified fingerprints, or {@code null} if it * cannot be determined.//from ww w . j a v a2 s .c om * * @param privateKeyFingerprint the private key fingerprint * @param publicKeyFingerprint the public key fingerprint * @return the key name corresponding to the specified fingerprints, or {@code null} if it * cannot be determined */ private String lookupKeyName(String privateKeyFingerprint, String publicKeyFingerprint) { DescribeKeyPairsResult keyPairsResult = client.describeKeyPairs(); for (KeyPairInfo keyPairInfo : keyPairsResult.getKeyPairs()) { String knownFingerprint = keyPairInfo.getKeyFingerprint().replace(":", ""); LOG.debug("Found fingerprint {} for keyName {}", knownFingerprint, keyPairInfo.getKeyName()); if (privateKeyFingerprint.equals(knownFingerprint)) { return keyPairInfo.getKeyName(); } if (publicKeyFingerprint.equals(knownFingerprint)) { return keyPairInfo.getKeyName(); } } return null; }
From source file:com.eucalyptus.tests.awssdk.CloudCleaner.java
License:Open Source License
@Test public void clean() throws Exception { testInfo(this.getClass().getSimpleName()); getCloudInfo();/*w w w . j av a 2 s . c o m*/ //Terminate All instances List<String> instancesToTerminate = new ArrayList<String>(); DescribeInstancesResult result = ec2.describeInstances(); List<Reservation> reservations = result.getReservations(); if (reservations.size() > 0) { print("Found instances to terminate"); for (Reservation reservation : reservations) { List<Instance> instances = reservation.getInstances(); for (Instance instance : instances) { print("Terminating: " + instance.getInstanceId()); instancesToTerminate.add(instance.getInstanceId()); } } TerminateInstancesRequest term = new TerminateInstancesRequest(); term.setInstanceIds(instancesToTerminate); ec2.terminateInstances(term); } else { print("No instances found"); } // delete all keypairs if (getKeyPairCount() > 0) { print("Found Keypairs to delete"); DescribeKeyPairsResult describeKeyPairsResult = ec2.describeKeyPairs(); for (KeyPairInfo keypair : describeKeyPairsResult.getKeyPairs()) { deleteKeyPair(keypair.getKeyName()); } } else { print("No keypairs found"); } // delete all groups except default group List<SecurityGroup> groups = describeSecurityGroups(); if (groups.size() > 1) { print("Found security groups to delete"); for (SecurityGroup group : groups) { if (!group.getGroupName().equals("default")) { deleteSecurityGroup(group.getGroupName()); } } } else { print("No Security Groups found (other than default)"); } // delete all policies List<ScalingPolicy> policies = describePolicies(); if (policies.size() > 0) { print("Found Policies to delete"); for (ScalingPolicy policy : policies) { deletePolicy(policy.getPolicyName()); } } else { print("No auto scaling policies found"); } // delete launch configs List<LaunchConfiguration> lcs = describeLaunchConfigs(); if (lcs.size() > 0) { print("Found Launch Configs to delete"); for (LaunchConfiguration lc : lcs) { deleteLaunchConfig(lc.getLaunchConfigurationName()); } } else { print("No launch configs found"); } // delete autoscaling groups List<AutoScalingGroup> asGroups = describeAutoScalingGroups(); if (asGroups.size() > 0) { print("Found Auto Scaling Groups to delete"); for (AutoScalingGroup asg : asGroups) { deleteAutoScalingGroup(asg.getAutoScalingGroupName(), true); } } else { print("No auto scaling groups found"); } // delete volumes List<Volume> volumes = ec2.describeVolumes().getVolumes(); if (volumes.size() > 0) { print("Found volumes to delete"); for (Volume vol : volumes) { deleteVolume(vol.getVolumeId()); } } else { print("No volumes found"); } //delete snapshots List<Snapshot> snapshots = ec2.describeSnapshots().getSnapshots(); if (snapshots.size() > 0) { print("Found snapshots to delete"); for (Snapshot snap : snapshots) { deleteSnapshot(snap.getSnapshotId()); } } else { print("No volumes found"); } }
From source file:com.norbl.cbp.ppe.Ec2Wrangler.java
License:Open Source License
public List<String> getKeypairNames() { List<String> names = new ArrayList<String>(); DescribeKeyPairsResult r = ec2Client.describeKeyPairs(); for (KeyPairInfo kpi : r.getKeyPairs()) { String nm = kpi.getKeyName(); if (nm != null) names.add(nm);//from w w w . ja v a 2 s . co m } return (names); }
From source file:com.yosanai.java.aws.console.DefaultAWSConnectionProvider.java
License:Open Source License
@Override public Collection<String> getKeyPairNames() throws Exception { ArrayList<String> ret = new ArrayList<String>(); DescribeKeyPairsResult result = getConnection().describeKeyPairs(); if (null != result && null != result.getKeyPairs()) { for (KeyPairInfo keyPairInfo : result.getKeyPairs()) { ret.add(keyPairInfo.getKeyName()); }/*from w w w .j ava 2 s .c om*/ } return ret; }
From source file:de.fischer.thotti.ec2.clients.EC2Validator.java
License:Apache License
private boolean isKeyPairKnownInRegion(ServerRequestType server) throws AWSRemoteServiceException { if (getRegionContext().awsKeyPairs == null) retrieveAWSKeyPairInformation(); for (KeyPairInfo key : getRegionContext().awsKeyPairs) { if (server.getKeyPair().equals(key.getKeyName())) return true; }// w w w. j a v a 2s . c om return false; }
From source file:de.fischer.thotti.ec2.clients.EC2Validator.java
License:Apache License
private void retrieveAWSKeyPairInformation() throws AWSRemoteServiceException { try {/*from ww w.ja va 2 s. c om*/ DescribeKeyPairsResult result = getClient().describeKeyPairs(); getRegionContext().awsKeyPairs = result.getKeyPairs(); } catch (AmazonServiceException ase) { handleAmazonServiceException(ase); } if (logger.isDebugEnabled()) for (KeyPairInfo key : getRegionContext().awsKeyPairs) { logger.debug("Found in region '{}' key '{}'.", new Object[] { getRegionContext().regionName, key.getKeyName() }); } }
From source file:ec2.DescribeKeyPairs.java
License:Open Source License
public static void main(String[] args) { final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DescribeKeyPairsResult response = ec2.describeKeyPairs(); for (KeyPairInfo keyPair : response.getKeyPairs()) { System.out.printf("Found key pair with name %s and fingerprint %s", keyPair.getKeyName(), keyPair.getKeyFingerprint()); }/* www . j a va 2 s .c om*/ }
From source file:edu.umass.cs.aws.support.AWSEC2.java
License:Apache License
/** * Describe Key Pairs/* w ww. ja v a 2s. com*/ * * @param ec2 */ public static void describeKeyPairs(AmazonEC2 ec2) { StringBuilder output = new StringBuilder(); String prefix = currentTab + "Key Pairs: "; DescribeKeyPairsResult dkr = ec2.describeKeyPairs(); for (KeyPairInfo keyPairInfo : dkr.getKeyPairs()) { output.append(prefix); prefix = ", "; output.append(keyPairInfo.getKeyName()); } System.out.println(output); }