本文整理汇总了Java中com.amazonaws.services.ec2.model.DescribeKeyPairsRequest类的典型用法代码示例。如果您正苦于以下问题:Java DescribeKeyPairsRequest类的具体用法?Java DescribeKeyPairsRequest怎么用?Java DescribeKeyPairsRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DescribeKeyPairsRequest类属于com.amazonaws.services.ec2.model包,在下文中一共展示了DescribeKeyPairsRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testIsKeyPairPresentTrue
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的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: testIsKeyPairPresentException
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
@Test
public void testIsKeyPairPresentException() {
String keyName = "key-name";
String fakeExceptionMessage = "fake-exception";
when(ec2Client.describeKeyPairs(new DescribeKeyPairsRequest().withKeyNames(keyName)))
.thenThrow(new AmazonServiceException(fakeExceptionMessage));
try {
// invoke method under test
ec2Service.isKeyPairPresent(keyName);
fail("expected exception not passed up");
} catch (AmazonServiceException ex) {
// pass
assertEquals(fakeExceptionMessage, ex.getErrorMessage());
}
}
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:19,代码来源:Ec2ServiceTest.java
示例3: getKeyPair
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的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
示例4: importKeyPair
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的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
示例5: validateExistingKeyPair
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
private void validateExistingKeyPair(InstanceAuthentication instanceAuthentication, AwsCredentialView credentialView, String region) {
String keyPairName = awsClient.getExistingKeyPairName(instanceAuthentication);
if (StringUtils.isNoneEmpty(keyPairName)) {
boolean keyPairIsPresentOnEC2 = false;
try {
AmazonEC2Client client = awsClient.createAccess(credentialView, region);
DescribeKeyPairsResult describeKeyPairsResult = client.describeKeyPairs(new DescribeKeyPairsRequest().withKeyNames(keyPairName));
keyPairIsPresentOnEC2 = describeKeyPairsResult.getKeyPairs().stream().findFirst().isPresent();
} catch (RuntimeException e) {
String errorMessage = String.format("Failed to get the key pair [name: '%s'] from EC2 [roleArn:'%s'], detailed message: %s.",
keyPairName, credentialView.getRoleArn(), e.getMessage());
LOGGER.error(errorMessage, e);
}
if (!keyPairIsPresentOnEC2) {
throw new CloudConnectorException(String.format("The key pair '%s' could not be found in the '%s' region of EC2.", keyPairName, region));
}
}
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:19,代码来源:AwsSetup.java
示例6: deleteKeyPair
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的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
示例7: isKeyPairPresent
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
/**
* Checks if a key pair is present in AWS EC2.
*
* @param keyName Friendly name for the key
* @return If present
*/
public boolean isKeyPairPresent(final String keyName) {
final DescribeKeyPairsRequest request = new DescribeKeyPairsRequest().withKeyNames(keyName);
try {
final DescribeKeyPairsResult result = ec2Client.describeKeyPairs(request);
return result.getKeyPairs().size() > 0;
} catch (final AmazonServiceException ase) {
if (ase.getErrorCode() == "InvalidKeyPair.NotFound") {
return false;
}
throw ase;
}
}
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:21,代码来源:Ec2Service.java
示例8: testIsKeyPairPresentFalse
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
@Test
public void testIsKeyPairPresentFalse() {
String keyName = "key-name";
when(ec2Client.describeKeyPairs(new DescribeKeyPairsRequest().withKeyNames(keyName)))
.thenReturn(new DescribeKeyPairsResult());
// invoke method under test
assertFalse(ec2Service.isKeyPairPresent(keyName));
}
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:12,代码来源:Ec2ServiceTest.java
示例9: testIsKeyPairPresentFalseNotFound
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
@Test
public void testIsKeyPairPresentFalseNotFound() {
String keyName = "key-name";
AmazonServiceException ex = new AmazonServiceException("fake-exception");
ex.setErrorCode("InvalidKeyPair.NotFound");
when(ec2Client.describeKeyPairs(new DescribeKeyPairsRequest().withKeyNames(keyName)))
.thenThrow(ex);
// invoke method under test
assertFalse(ec2Service.isKeyPairPresent(keyName));
}
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:15,代码来源:Ec2ServiceTest.java
示例10: checkKeyName
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
/**
* Validates the EC2 key name.
*
* @param client the EC2 client
* @param accumulator the exception condition accumulator
* @param localizationContext the localization context
*/
@VisibleForTesting
void checkKeyName(AmazonEC2Client client,
Configured configuration,
PluginExceptionConditionAccumulator accumulator,
LocalizationContext localizationContext) {
String keyName = configuration.getConfigurationValue(KEY_NAME, localizationContext);
if (keyName != null) {
LOG.info(">> Describing key pair");
try {
DescribeKeyPairsResult result = client.describeKeyPairs(
new DescribeKeyPairsRequest().withKeyNames(keyName));
// TODO Should this be REDACTED instead of NotDisplayed?
checkCount(accumulator, KEY_NAME, localizationContext, "NotDisplayed",
result.getKeyPairs());
} catch (AmazonServiceException e) {
if (e.getErrorCode().startsWith(INVALID_KEY_PAIR)) {
addError(accumulator, KEY_NAME, localizationContext,
null, INVALID_KEY_NAME_MSG, keyName);
} else {
throw Throwables.propagate(e);
}
}
}
}
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:35,代码来源:EC2InstanceTemplateConfigurationValidator.java
示例11: keyPairExists
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
public boolean keyPairExists(String name) {
try {
return !ec2.describeKeyPairs(new DescribeKeyPairsRequest().withKeyNames(name)).getKeyPairs().isEmpty();
} catch (AmazonServiceException e) {
if ("InvalidKeyPair.NotFound".equals(e.getErrorCode())) {
return false;
}
throw e;
}
}
开发者ID:neowu,项目名称:cmn-project,代码行数:11,代码来源:EC2.java
示例12: load
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的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
示例13: getKeyPairs
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的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
示例14: getKeyPairs
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
@Override
public KeyPairCollection getKeyPairs(DescribeKeyPairsRequest request) {
ResourceCollectionImpl result = service.getCollection("KeyPairs",
request);
if (result == null) return null;
return new KeyPairCollectionImpl(result);
}
开发者ID:awslabs,项目名称:aws-sdk-java-resources,代码行数:9,代码来源:EC2Impl.java
示例15: sshKeys
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
@Override
public CloudSshKeys sshKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Map<String, Set<CloudSshKey>> result = new HashMap<>();
for (Region actualRegion : awsPlatformParameters.regions().types()) {
// If region is provided then should filter for those region
if (regionMatch(actualRegion, region)) {
Set<CloudSshKey> cloudSshKeys = new HashSet<>();
AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(cloudCredential), actualRegion.value());
//create sshkey filter view
PlatformResourceSshKeyFilterView filter = new PlatformResourceSshKeyFilterView(filters);
DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest();
// If the filtervalue is provided then we should filter only for those securitygroups
if (!Strings.isNullOrEmpty(filter.getKeyName())) {
describeKeyPairsRequest.withKeyNames(filter.getKeyName());
}
for (KeyPairInfo keyPairInfo : ec2Client.describeKeyPairs(describeKeyPairsRequest).getKeyPairs()) {
Map<String, Object> properties = new HashMap<>();
properties.put("fingerPrint", keyPairInfo.getKeyFingerprint());
cloudSshKeys.add(new CloudSshKey(keyPairInfo.getKeyName(), properties));
}
result.put(actualRegion.value(), cloudSshKeys);
}
}
return new CloudSshKeys(result);
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:30,代码来源:AwsPlatformResources.java
示例16: describeKeyPairs
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的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
示例17: assertKeyNotFound
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
public void assertKeyNotFound(String keyName) {
final DescribeKeyPairsRequest request = new DescribeKeyPairsRequest().withKeyNames(keyName);
try {
DescribeKeyPairsResult result = client.describeKeyPairs(request);
fail("Found key " + result.getKeyPairs().get(0));
} catch (AmazonServiceException e) {
assertThat(e.getErrorCode()).isEqualTo(ErrorCodes.KEYPAIR_NOT_FOUND);
}
}
开发者ID:apache,项目名称:incubator-provisionr,代码行数:11,代码来源:DeleteKeyPairLiveTest.java
示例18: assertKeyPairWasImportedAsExpected
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
private void assertKeyPairWasImportedAsExpected() {
final DescribeKeyPairsRequest request = new DescribeKeyPairsRequest().withKeyNames(KEYPAIR_NAME);
DescribeKeyPairsResult result = client.describeKeyPairs(request);
assertThat(result.getKeyPairs()).hasSize(1);
assertThat(result.getKeyPairs().get(0).getKeyFingerprint()).isEqualTo(TEST_KEY_FINGERPRINT);
}
开发者ID:apache,项目名称:incubator-provisionr,代码行数:8,代码来源:EnsureKeyPairExistsLiveTest.java
示例19: describeKeyPairs
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
@Override
public DescribeKeyPairsResult describeKeyPairs(DescribeKeyPairsRequest describeKeyPairsRequest) throws AmazonServiceException, AmazonClientException {
throw new UnsupportedOperationException("Not supported in mock");
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:AmazonEC2Mock.java
示例20: load
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; //导入依赖的package包/类
@Override
public boolean load(DescribeKeyPairsRequest request) {
return load(request, null);
}
开发者ID:awslabs,项目名称:aws-sdk-java-resources,代码行数:5,代码来源:KeyPairImpl.java
注:本文中的com.amazonaws.services.ec2.model.DescribeKeyPairsRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论