本文整理汇总了Java中com.amazonaws.services.ec2.model.CreateKeyPairRequest类的典型用法代码示例。如果您正苦于以下问题:Java CreateKeyPairRequest类的具体用法?Java CreateKeyPairRequest怎么用?Java CreateKeyPairRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CreateKeyPairRequest类属于com.amazonaws.services.ec2.model包,在下文中一共展示了CreateKeyPairRequest类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.amazonaws.services.ec2.model.CreateKeyPairRequest; //导入依赖的package包/类
public static void main(String[] args)
{
final String USAGE =
"To run this example, supply a key pair name\n" +
"Ex: CreateKeyPair <key-pair-name>\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String key_name = args[0];
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
CreateKeyPairRequest request = new CreateKeyPairRequest()
.withKeyName(key_name);
CreateKeyPairResult response = ec2.createKeyPair(request);
System.out.printf(
"Successfulyl created key pair named %s",
key_name);
}
示例2: createKeyPair
import com.amazonaws.services.ec2.model.CreateKeyPairRequest; //导入依赖的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");
}
}
示例3: create
import com.amazonaws.services.ec2.model.CreateKeyPairRequest; //导入依赖的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();
}
示例4: doGenerateKey
import com.amazonaws.services.ec2.model.CreateKeyPairRequest; //导入依赖的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());
}
}
示例5: createKeyValuePair
import com.amazonaws.services.ec2.model.CreateKeyPairRequest; //导入依赖的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;
}
示例6: createKeyPair
import com.amazonaws.services.ec2.model.CreateKeyPairRequest; //导入依赖的package包/类
@Override
public KeyPair createKeyPair(CreateKeyPairRequest request,
ResultCapture<CreateKeyPairResult> extractor) {
ActionResult result = service.performAction("CreateKeyPair", request,
extractor);
if (result == null) return null;
return new KeyPairImpl(result.getResource());
}
示例7: execute
import com.amazonaws.services.ec2.model.CreateKeyPairRequest; //导入依赖的package包/类
/**
* Creates a key-pair with a randomly generated name, and sets the generated
* name to the specified property.
*/
public void execute() {
checkParams();
AmazonEC2Client client = getOrCreateClient(AmazonEC2Client.class);
try {
String keyName = Long.toString(System.currentTimeMillis());
client.createKeyPair(new CreateKeyPairRequest()
.withKeyName(keyName));
getProject().setProperty(propertyNameForKeyName, keyName);
} catch (Exception e) {
throw new BuildException(e.getMessage(), e);
}
}
示例8: createKeyPair
import com.amazonaws.services.ec2.model.CreateKeyPairRequest; //导入依赖的package包/类
@Override
public CreateKeyPairResult createKeyPair(CreateKeyPairRequest createKeyPairRequest) throws AmazonServiceException, AmazonClientException {
throw new UnsupportedOperationException("Not supported in mock");
}
示例9: createKeyPair
import com.amazonaws.services.ec2.model.CreateKeyPairRequest; //导入依赖的package包/类
public KeyPair createKeyPair(String keyName) {
logger.info("create key pair, keyName={}", keyName);
CreateKeyPairResult result = ec2.createKeyPair(new CreateKeyPairRequest().withKeyName(keyName));
return result.getKeyPair();
}
示例10: createKeyPair
import com.amazonaws.services.ec2.model.CreateKeyPairRequest; //导入依赖的package包/类
public CreateKeyPairResult createKeyPair(AmazonEC2Client client, String keyName) {
CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest().withKeyName(keyName);
CreateKeyPairResult createKeyPairResult = client.createKeyPair(createKeyPairRequest);
return createKeyPairResult;
}
示例11: createKeyPair
import com.amazonaws.services.ec2.model.CreateKeyPairRequest; //导入依赖的package包/类
/**
* Performs the <code>CreateKeyPair</code> action.
*
* <p>
*
* @return The <code>KeyPair</code> resource object associated with the
* result of this action.
* @see CreateKeyPairRequest
*/
com.amazonaws.resources.ec2.KeyPair createKeyPair(CreateKeyPairRequest
request);