本文整理汇总了Java中com.amazonaws.services.ec2.AmazonEC2.describeKeyPairs方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonEC2.describeKeyPairs方法的具体用法?Java AmazonEC2.describeKeyPairs怎么用?Java AmazonEC2.describeKeyPairs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.AmazonEC2
的用法示例。
在下文中一共展示了AmazonEC2.describeKeyPairs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
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());
}
}
示例2: validateSaveAWSCred
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
/**
* Validates fields for credential submit
*/
public void validateSaveAWSCred() {
if (awsCred.getAccessKey() == null ||
awsCred.getAccessKey().trim().equals("")) {
addFieldError("awsCred.accessKey", "Required");
}
if (awsCred.getSecretKey() == null ||
awsCred.getSecretKey().trim().equals("")) {
addFieldError("awsCred.secretKey", "Required");
}
if (!this.hasErrors()) {
try {
//check if credential are valid
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsCred.getAccessKey(), awsCred.getSecretKey());
AmazonEC2 service = AmazonEC2ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.withClientConfiguration(AWSClientConfig.getClientConfig()).build();
service.describeKeyPairs();
} catch (Exception ex) {
ex.printStackTrace();
addActionError("Invalid Credentials");
}
}
if(this.hasActionErrors() || this.hasErrors()){
sortedSet = AWSCredDB.getAWSCredSet(sortedSet);
}
}
示例3: getKeyPairJSON
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
/**
* returns keypairs as a json string
*/
@Action(value = "/manage/getKeyPairJSON"
)
public String getKeyPairJSON() {
AWSCred awsCred = AWSCredDB.getAWSCred(ec2Key.getAwsCredId());
//set AWS credentials for service
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsCred.getAccessKey(), awsCred.getSecretKey());
AmazonEC2 service = AmazonEC2ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.withClientConfiguration(AWSClientConfig.getClientConfig())
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(ec2Key.getEc2Region(), ec2RegionMap.get(ec2Key.getEc2Region()))).build();
DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest();
DescribeKeyPairsResult describeKeyPairsResult = service.describeKeyPairs(describeKeyPairsRequest);
List<KeyPairInfo> keyPairInfoList = describeKeyPairsResult.getKeyPairs();
String json = new Gson().toJson(keyPairInfoList);
try {
servletResponse.getOutputStream().write(json.getBytes());
} catch (Exception ex) {
log.error(ex.toString(), ex);
}
return null;
}
示例4: describeKeyPairs
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
@Override
public List<AbstractResource<?>> describeKeyPairs(Account account, Region region, DateTime dt, Ec2Filter... filters) {
AmazonEC2 ec2 = findClient(account, region);
DescribeKeyPairsRequest req = new DescribeKeyPairsRequest();
for (Ec2Filter filter : filters) {
Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues());
req.withFilters(f);
}
log.debug("start describing key pairs for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region);
DescribeKeyPairsResult res = ec2.describeKeyPairs(req);
return converter.toEc2KeyPairs(res.getKeyPairs(), account.getId(), region, dt);
}
示例5: importEC2Key
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
@Action(value = "/manage/importEC2Key",
results = {
@Result(name = "input", location = "/manage/view_ec2_keys.jsp"),
@Result(name = "success", location = "/manage/viewEC2Keys.action", type = "redirect")
}
)
public String importEC2Key() {
String retVal = SUCCESS;
try {
//get AWS credentials from DB
AWSCred awsCred = AWSCredDB.getAWSCred(ec2Key.getAwsCredId());
//set AWS credentials for service
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsCred.getAccessKey(), awsCred.getSecretKey());
//create service
AmazonEC2 service = AmazonEC2ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.withClientConfiguration(AWSClientConfig.getClientConfig())
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(ec2Key.getEc2Region(), ec2RegionMap.get(ec2Key.getEc2Region()))).build();
//describe key pair request
DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest();
describeKeyPairsRequest.setKeyNames(Arrays.asList(ec2Key.getKeyNm()));
//call service
DescribeKeyPairsResult describeKeyPairsResult = service.describeKeyPairs(describeKeyPairsRequest);
if (describeKeyPairsResult != null && describeKeyPairsResult.getKeyPairs().size() > 0) {
//add to db
EC2KeyDB.saveEC2Key(ec2Key);
} else {
addActionError("Imported key does not exist on AWS");
retVal = INPUT;
}
} catch (AmazonServiceException ex) {
addActionError(ex.getMessage());
retVal = INPUT;
}
return retVal;
}