當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。