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


Java KeyPairInfo类代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.model.KeyPairInfo的典型用法代码示例。如果您正苦于以下问题:Java KeyPairInfo类的具体用法?Java KeyPairInfo怎么用?Java KeyPairInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KeyPairInfo类属于com.amazonaws.services.ec2.model包,在下文中一共展示了KeyPairInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testIsKeyPairPresentTrue

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
@Test
public void testIsKeyPairPresentTrue() {

    String keyName = "key-name";

    when(ec2Client.describeKeyPairs(
            new DescribeKeyPairsRequest()
                    .withKeyNames(keyName)
            )
    ).thenReturn(
            new DescribeKeyPairsResult()
                    .withKeyPairs(
                            new KeyPairInfo()
                    )
    );

    // invoke method under test
    assertTrue(ec2Service.isKeyPairPresent(keyName));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:20,代码来源:Ec2ServiceTest.java

示例2: getKeyPair

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
public KeyPair getKeyPair(String keyName)
{
    KeyPair keyPair = null;

    if (!isNullOrEmpty(keyName))
    {
        try
        {
            DescribeKeyPairsResult describeKeyPairs = ec2_.describeKeyPairs(new DescribeKeyPairsRequest().withKeyNames(keyName));
            List<KeyPairInfo> keyPairs = describeKeyPairs.getKeyPairs();

            if (keyPairs != null && !keyPairs.isEmpty())
            {
                KeyPairInfo keyPairInfo = keyPairs.get(0);
                keyPair = new KeyPair(keyPairInfo.getKeyName()).withKeyFingerprint(keyPairInfo.getKeyFingerprint());
            }
        }
        catch (AmazonClientException exception)
        {
            LOG.debug("Error on describing keyPairs [{}] on [{}]. Error message: [{}]",  keyName,  credentials_.getProvider().getName(),
                       exception.getMessage());
        }
    }

    return keyPair;
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:27,代码来源:EC2.java

示例3: importKeyPair

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
@Override
public void importKeyPair(String keyName, String publicKey) throws AutoException {
    // キーペアがすでに登録されていたら何もしない
    DescribeKeyPairsRequest request = new DescribeKeyPairsRequest();
    DescribeKeyPairsResult result = ec2Client.describeKeyPairs(request);
    List<KeyPairInfo> keyPairs = result.getKeyPairs();

    for (KeyPairInfo keyPair : keyPairs) {
        if (keyPair.getKeyName().equals(keyName)) {
            log.info(platform.getPlatformName() + " の " + keyName + " はすでに登録されている為、キーのインポートをスキップします");
            System.out.println("IMPORT_SKIPPED");
            return;
        }
    }

    // インポート
    ImportKeyPairRequest request2 = new ImportKeyPairRequest();
    request2.withKeyName(keyName);
    request2.withPublicKeyMaterial(publicKey);
    ec2Client.importKeyPair(request2);

    log.info(keyName + "のキーをインポートしました。");
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:24,代码来源:AwsIaasGatewayScriptService.java

示例4: deleteKeyPair

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
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;
}
 
开发者ID:cartwrightian,项目名称:cfnassist,代码行数:17,代码来源:TestKeyPairCreationAndSave.java

示例5: createKeyPair

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
private void createKeyPair() throws IOException, FileNotFoundException {
	DescribeKeyPairsResult response = ec2.describeKeyPairs();
	boolean check_key=false;
	for(KeyPairInfo key_pair : response.getKeyPairs()) {
		if(key_pair.getKeyName().equalsIgnoreCase(MY_KEY))
		{
			check_key=true;
			break;
		}
	}
	if(!check_key)
	{
		File file=new File(System.getProperty("user.home")+"/.aws/"+MY_KEY+".pem");
		if(!file.exists()) file.createNewFile();
		else{
			System.err.println("Connot create the key pair to access to the cluster!");
			System.exit(1);
		}
		System.out.println("Create new key pair ~/.aws/"+MY_KEY+".pem");
		CreateKeyPairRequest request = new CreateKeyPairRequest()
		.withKeyName(MY_KEY);

		CreateKeyPairResult responsetocreate = ec2.createKeyPair(request);


		PrintWriter print = new PrintWriter(file);
		print.print(responsetocreate.getKeyPair().getKeyMaterial());
		print.close();
		Runtime.getRuntime().exec("chmod 0400 "+System.getProperty("user.home")+"/.aws/"+MY_KEY+".pem");
	}
}
 
开发者ID:spagnuolocarmine,项目名称:aws-cluster-toolkit,代码行数:32,代码来源:AwsClusterManager.java

示例6: main

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的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

示例7: lookupKeyName

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
/**
 * Returns the key name corresponding to the specified fingerprints, or {@code null} if it
 * cannot be determined.
 *
 * @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;
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:24,代码来源:EC2Provider.java

示例8: doGenerateKey

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
public FormValidation doGenerateKey(StaplerResponse rsp, URL ec2EndpointUrl, boolean useInstanceProfileForCredentials, String accessId, String secretKey)
        throws IOException, ServletException {
    try {
        AWSCredentialsProvider credentialsProvider = createCredentialsProvider(useInstanceProfileForCredentials, accessId, secretKey);
        AmazonEC2 ec2 = connect(credentialsProvider, ec2EndpointUrl);
        List<KeyPairInfo> existingKeys = ec2.describeKeyPairs().getKeyPairs();

        int n = 0;
        while (true) {
            boolean found = false;
            for (KeyPairInfo k : existingKeys) {
                if (k.getKeyName().equals("hudson-" + n)) {
                    found = true;
                }
            }
            if (!found) {
                break;
            }
            n++;
        }

        CreateKeyPairRequest request = new CreateKeyPairRequest("hudson-" + n);
        KeyPair key = ec2.createKeyPair(request).getKeyPair();

        rsp.addHeader("script", "findPreviousFormItem(button,'privateKey').value='" + key.getKeyMaterial().replace("\n", "\\n") + "'");

        return FormValidation.ok(Messages.EC2Cloud_Success());
    } catch (AmazonClientException e) {
        LOGGER.log(Level.WARNING, "Failed to check EC2 credential", e);
        return FormValidation.error(e.getMessage());
    }
}
 
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:33,代码来源:EC2Cloud.java

示例9: load

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
public void load() {
    List<KeyPairInfo> remoteKeyPairs = AWS.ec2.ec2.describeKeyPairs(new DescribeKeyPairsRequest()
        .withFilters(new Filter("key-name").withValues(env.name + ":*"))).getKeyPairs();

    for (KeyPairInfo remoteKeyPair : remoteKeyPairs) {
        String keyPairId = keyPairId(env.name, remoteKeyPair.getKeyName());
        if (keyPairId != null) {
            KeyPair keyPair = resources.find(KeyPair.class, keyPairId)
                                       .orElseGet(() -> resources.add(new KeyPair(keyPairId, remoteKeyPair.getKeyName())));
            keyPair.remoteKeyPair = remoteKeyPair;
            keyPair.foundInRemote();
        }
    }
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:15,代码来源:KeyPairLoader.java

示例10: createKeyPair

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
public void createKeyPair(KeyPair keyPair) throws IOException {
    com.amazonaws.services.ec2.model.KeyPair remoteKeyPair = AWS.ec2.createKeyPair(keyPair.name);
    writeKeyFile(keyPair.name, remoteKeyPair.getKeyMaterial());
    keyPair.remoteKeyPair = new KeyPairInfo()
        .withKeyName(remoteKeyPair.getKeyName())
        .withKeyFingerprint(remoteKeyPair.getKeyFingerprint());
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:8,代码来源:KeyPairHelper.java

示例11: getKeyPairs

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
public List<KeyPair> getKeyPairs()
{
    List<KeyPair> keyPairs = new ArrayList<KeyPair>();

    DescribeKeyPairsResult availableKeyPairs = ec2_.describeKeyPairs();

    for (KeyPairInfo keyInfo : availableKeyPairs.getKeyPairs())
    {
        keyPairs.add(new KeyPair(keyInfo.getKeyName()).withKeyFingerprint(keyInfo.getKeyFingerprint()));
    }

    return Collections.unmodifiableList(keyPairs);
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:14,代码来源:EC2.java

示例12: getKeyPairs

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
@Override
public List<KeyPairInfo> getKeyPairs(Long userNo, Long platformNo) {
    List<KeyPairInfo> infos = new ArrayList<KeyPairInfo>();

    infos.add(new KeyPairInfo().withKeyName("key01"));
    infos.add(new KeyPairInfo().withKeyName("key02"));
    infos.add(new KeyPairInfo().withKeyName("key03"));

    return infos;
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:11,代码来源:MockAwsDescribeService.java

示例13: convertObject

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
@Override
protected KeyPairInfo convertObject(com.xerox.amazonws.ec2.KeyPairInfo from) {
    KeyPairInfo to = new KeyPairInfo();

    to.setKeyName(from.getKeyName());
    to.setKeyFingerprint(from.getKeyFingerprint());

    return to;
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:10,代码来源:KeyPairInfoConverter.java

示例14: getKeyPairs

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public List<KeyPairInfo> getKeyPairs(Long userNo, Long platformNo) {
    // キーペアを取得
    AwsProcessClient awsProcessClient = awsProcessClientFactory.createAwsProcessClient(userNo, platformNo);
    DescribeKeyPairsRequest request = new DescribeKeyPairsRequest();
    DescribeKeyPairsResult result = awsProcessClient.getEc2Client().describeKeyPairs(request);
    List<KeyPairInfo> keyPairs = result.getKeyPairs();

    // ソート
    Collections.sort(keyPairs, Comparators.COMPARATOR_KEY_PAIR_INFO);

    return keyPairs;
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:17,代码来源:AwsDescribeServiceImpl.java

示例15: checkKeyName

import com.amazonaws.services.ec2.model.KeyPairInfo; //导入依赖的package包/类
private boolean checkKeyName(Long userNo, Long platformNo, String keyName) {
    List<KeyPairInfo> keyPairs = awsDescribeService.getKeyPairs(userNo, platformNo);
    for (KeyPairInfo keyPair : keyPairs) {
        if (StringUtils.equals(keyName, keyPair.getKeyName())) {
            return true;
        }
    }

    return false;
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:11,代码来源:EditInstanceAws.java


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