当前位置: 首页>>代码示例>>Java>>正文


Java AmazonEC2.describeKeyPairs方法代码示例

本文整理汇总了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());
    }
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:15,代码来源:DescribeKeyPairs.java

示例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);
    }
}
 
开发者ID:skavanagh,项目名称:EC2Box,代码行数:31,代码来源:AWSCredAction.java

示例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;
}
 
开发者ID:skavanagh,项目名称:EC2Box,代码行数:31,代码来源:EC2KeyAction.java

示例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);
}
 
开发者ID:veyronfei,项目名称:clouck,代码行数:16,代码来源:Ec2WrapperImpl.java

示例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;


}
 
开发者ID:skavanagh,项目名称:EC2Box,代码行数:52,代码来源:EC2KeyAction.java


注:本文中的com.amazonaws.services.ec2.AmazonEC2.describeKeyPairs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。