本文整理汇总了Java中com.amazonaws.services.ec2.model.KeyPair类的典型用法代码示例。如果您正苦于以下问题:Java KeyPair类的具体用法?Java KeyPair怎么用?Java KeyPair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyPair类属于com.amazonaws.services.ec2.model包,在下文中一共展示了KeyPair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: probeSSH
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
protected final void probeSSH(final String host, final KeyPair key) {
final Callable<Boolean> callable = () -> {
final JSch jsch = new JSch();
final Session session = jsch.getSession("ec2-user", host);
jsch.addIdentity(key.getKeyName(), key.getKeyMaterial().getBytes(), null, null);
jsch.setConfig("StrictHostKeyChecking", "no"); // for testing this should be fine. adding the host key seems to be only possible via a file which is not very useful here
session.connect(10000);
session.disconnect();
return true;
};
Assert.assertTrue(this.retry(callable));
}
开发者ID:widdix,项目名称:aws-cf-templates,代码行数:13,代码来源:ATest.java
示例2: invoke
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
@Override
public void invoke(FacadeFactory factory, ProjectAndEnv projectAndEnv, Collection<Parameter> cfnParams,
Collection<Parameter> artifacts, String... argument) throws IOException, InterruptedException,
CfnAssistException, MissingArgumentException {
AwsFacade facade = factory.createFacade();
String filename;
if (argument==null) {
String home = System.getenv("HOME");
String keypairName = format("%s_%s", projectAndEnv.getProject(), projectAndEnv.getEnv());
filename = format("%s/.ssh/%s.pem", home, keypairName);
} else {
filename = argument[0];
}
KeyPair keyPair = facade.createKeyPair(projectAndEnv, factory.getSavesFile(), filename);
System.out.println(format("Created key %s with fingerprint %s", keyPair.getKeyName(),
keyPair.getKeyFingerprint()));
}
开发者ID:cartwrightian,项目名称:cfnassist,代码行数:20,代码来源:CreateKeyPairAction.java
示例3: shouldCreateKeyPairAndTagVPC
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
@Test
public void shouldCreateKeyPairAndTagVPC() throws CfnAssistException {
String filename = "fileForPem.pem";
SavesFile destination = createStrictMock(SavesFile.class);
KeyPair keypair = new KeyPair().withKeyName("CfnAssist_Test");
EasyMock.expect(destination.exists(filename)).andReturn(false);
EasyMock.expect(cloudRepository.createKeyPair("CfnAssist_Test", destination, filename)).
andReturn(keypair);
vpcRepository.setVpcTag(projectAndEnv, "keypairname", "CfnAssist_Test");
EasyMock.expectLastCall();
replayAll();
KeyPair result = aws.createKeyPair(projectAndEnv, destination, filename);
verifyAll();
assertEquals("CfnAssist_Test", result.getKeyName());
}
开发者ID:cartwrightian,项目名称:cfnassist,代码行数:20,代码来源:TestAwsFacade.java
示例4: create
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
@Override
public String create(Instance instance) {
CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest();
createKeyPairRequest.withKeyName(instance.getKeyName());
CreateKeyPairResult createKeyPairResult = ec2UserClient.amazonEC2Async().createKeyPair(createKeyPairRequest);
KeyPair keyPair = createKeyPairResult.getKeyPair();
return keyPair.getKeyMaterial();
}
开发者ID:peavers,项目名称:swordfish-service,代码行数:11,代码来源:EC2KeyPairImpl.java
示例5: test
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
@Test
public void test() {
final String vpcStackName = "vpc-2azs-" + this.random8String();
final String stackName = "ec2-auto-recovery-" + this.random8String();
final String classB = "10";
final String keyName = "key-" + this.random8String();
try {
final KeyPair key = this.createKey(keyName);
try {
this.createStack(vpcStackName,
"vpc/vpc-2azs.yaml",
new Parameter().withParameterKey("ClassB").withParameterValue(classB)
);
try {
this.createStack(stackName,
"ec2/ec2-auto-recovery.yaml",
new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName),
new Parameter().withParameterKey("KeyName").withParameterValue(keyName)
);
final String host = this.getStackOutputValue(stackName, "IPAddress");
this.probeSSH(host, key);
} finally {
this.deleteStack(stackName);
}
} finally {
this.deleteStack(vpcStackName);
}
} finally {
this.deleteKey(keyName);
}
}
开发者ID:widdix,项目名称:aws-cf-templates,代码行数:32,代码来源:TestEC2AutoRecovery.java
示例6: test
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
@Test
public void test() {
final String vpcStackName = "vpc-2azs-" + this.random8String();
final String bastionStackName = "vpc-ssh-bastion-" + this.random8String();
final String classB = "10";
final String keyName = "key-" + this.random8String();
try {
final KeyPair key = this.createKey(keyName);
try {
this.createStack(vpcStackName,
"vpc/vpc-2azs.yaml",
new Parameter().withParameterKey("ClassB").withParameterValue(classB)
);
try {
this.createStack(bastionStackName,
"vpc/vpc-ssh-bastion.yaml",
new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName),
new Parameter().withParameterKey("KeyName").withParameterValue(keyName)
);
final String host = this.getStackOutputValue(bastionStackName, "IPAddress");
this.probeSSH(host, key);
} finally {
this.deleteStack(bastionStackName);
}
} finally {
this.deleteStack(vpcStackName);
}
} finally {
this.deleteKey(keyName);
}
}
开发者ID:widdix,项目名称:aws-cf-templates,代码行数:32,代码来源:TestVPCSshBastion.java
示例7: getKeyPair
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
/**
* Gets the {@link KeyPairInfo} used for the launch.
*/
public synchronized KeyPair getKeyPair() throws AmazonClientException, IOException {
if (usableKeyPair == null) {
usableKeyPair = privateKey.find(connect());
}
return usableKeyPair;
}
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:10,代码来源:EC2Cloud.java
示例8: doGenerateKey
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的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: bootstrap
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
private int bootstrap(Connection bootstrapConn, EC2Computer computer, PrintStream logger) throws IOException, InterruptedException, AmazonClientException {
logger.println("bootstrap()" );
boolean closeBootstrap = true;
try {
int tries = 20;
boolean isAuthenticated = false;
logger.println("Getting keypair..." );
KeyPair key = computer.getCloud().getKeyPair();
logger.println("Using key: " + key.getKeyName() + "\n" + key.getKeyFingerprint() + "\n" + key.getKeyMaterial().substring(0, 160) );
while (tries-- > 0) {
logger.println("Authenticating as " + computer.getRemoteAdmin());
isAuthenticated = bootstrapConn.authenticateWithPublicKey(computer.getRemoteAdmin(), key.getKeyMaterial().toCharArray(), "");
if (isAuthenticated) {
break;
}
logger.println("Authentication failed. Trying again...");
Thread.sleep(10000);
}
if (!isAuthenticated) {
logger.println("Authentication failed");
return FAILED;
}
closeBootstrap = false;
return SAMEUSER;
} finally {
if (closeBootstrap)
bootstrapConn.close();
}
}
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:30,代码来源:EC2UnixLauncher.java
示例10: convertObject
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
@Override
protected KeyPair convertObject(KeyPairInfo from) {
KeyPair to = new KeyPair();
to.setKeyName(from.getKeyName());
to.setKeyMaterial(from.getKeyMaterial());
to.setKeyFingerprint(from.getKeyFingerprint());
return to;
}
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:11,代码来源:KeyPairConverter.java
示例11: createKeyValuePair
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
/***
* Creates a 2048-bit RSA key pair with the specified name
*
* @param keyName Key name to use
* @return Unencrypted PEM encoded PKCS#8 private key
*/
public String createKeyValuePair(String keyName) {
final AmazonEC2 amazonEC2 = getEc2Client();
final CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest().withKeyName(keyName);
final CreateKeyPairResult createKeyPairResult = amazonEC2.createKeyPair(createKeyPairRequest);
final KeyPair keyPair = createKeyPairResult.getKeyPair();
final String material = keyPair.getKeyMaterial();
LOGGER.info("Created key: " + keyName);
LOGGER.debug("Created material: " + material);
return material;
}
开发者ID:apache,项目名称:incubator-gobblin,代码行数:20,代码来源:AWSSdkClient.java
示例12: createKeyPair
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
public KeyPair createKeyPair(ProjectAndEnv projAndEnv, SavesFile destination, String filename) throws CfnAssistException {
if (destination.exists(filename)) {
throw new CfnAssistException(format("File '%s' already exists", filename));
}
String env = projAndEnv.getEnv();
String project = projAndEnv.getProject();
String keypairName = format("%s_%s", project,env);
logger.info("Create key pair with name " + keypairName);
KeyPair result = cloudRepository.createKeyPair(keypairName, destination, filename);
vpcRepository.setVpcTag(projAndEnv,KEYNAME_TAG, result.getKeyName());
return result;
}
开发者ID:cartwrightian,项目名称:cfnassist,代码行数:14,代码来源:AwsFacade.java
示例13: shouldCreateKeypairWithNoFilename
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
@Test
public void shouldCreateKeypairWithNoFilename() throws InterruptedException, MissingArgumentException, CfnAssistException {
String home = System.getenv("HOME");
String filename = format("%s/.ssh/CfnAssist_Test.pem",home);
KeyPair keyPair = new KeyPair().withKeyFingerprint("fingerprint").withKeyName("keyName");
SavesFile savesFile = EasyMock.createMock(SavesFile.class);
setFactoryExpectations();
EasyMock.expect(factory.getSavesFile()).andReturn(savesFile);
EasyMock.expect(facade.createKeyPair(projectAndEnv, savesFile, filename)).andReturn(keyPair);
validate((CLIArgBuilder.createKeyPair("")));
}
开发者ID:cartwrightian,项目名称:cfnassist,代码行数:16,代码来源:TestCommandLineActions.java
示例14: shouldCreateKeypairWithFilename
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
@Test
public void shouldCreateKeypairWithFilename() throws InterruptedException, MissingArgumentException, CfnAssistException {
String filename = "someFilename";
SavesFile savesFile = EasyMock.createMock(SavesFile.class);
KeyPair keyPair = new KeyPair().withKeyFingerprint("fingerprint").withKeyName("keyName");
setFactoryExpectations();
EasyMock.expect(factory.getSavesFile()).andReturn(savesFile);
EasyMock.expect(facade.createKeyPair(projectAndEnv, savesFile, filename)).andReturn(keyPair);
validate(CLIArgBuilder.createKeyPair(filename));
}
开发者ID:cartwrightian,项目名称:cfnassist,代码行数:14,代码来源:TestCommandLineActions.java
示例15: createKeyPair
import com.amazonaws.services.ec2.model.KeyPair; //导入依赖的package包/类
public KeyPair createKeyPair(String keyName) {
logger.info("create key pair, keyName={}", keyName);
CreateKeyPairResult result = ec2.createKeyPair(new CreateKeyPairRequest().withKeyName(keyName));
return result.getKeyPair();
}
开发者ID:neowu,项目名称:cmn-project,代码行数:6,代码来源:EC2.java
注:本文中的com.amazonaws.services.ec2.model.KeyPair类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论