Java 类com.amazonaws.services.ec2.model.CreateKeyPairRequest 实例源码

项目:aws-doc-sdk-examples    文件:CreateKeyPair.java   
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);
}
项目:aws-cluster-toolkit    文件:AwsClusterManager.java   
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");
    }
}
项目:swordfish-service    文件:EC2KeyPairImpl.java   
@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();
}
项目:ec2-plugin    文件:EC2Cloud.java   
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());
    }
}
项目:incubator-gobblin    文件:AWSSdkClient.java   
/***
 * 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;
}
项目:aws-sdk-java-resources    文件:EC2Impl.java   
@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());
}
项目:aws-sdk-java-resources    文件:EC2Impl.java   
@Override
public KeyPair createKeyPair(String keyName,
        ResultCapture<CreateKeyPairResult> extractor) {

    CreateKeyPairRequest request = new CreateKeyPairRequest()
        .withKeyName(keyName);
    return createKeyPair(request, extractor);
}
项目:aws-ant-tasks    文件:SetUpCloudFormationTestsTask.java   
/**
 * 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);
    }
}
项目:elasticsearch_my    文件:AmazonEC2Mock.java   
@Override
public CreateKeyPairResult createKeyPair(CreateKeyPairRequest createKeyPairRequest) throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Not supported in mock");
}
项目:cmn-project    文件:EC2.java   
public KeyPair createKeyPair(String keyName) {
    logger.info("create key pair, keyName={}", keyName);
    CreateKeyPairResult result = ec2.createKeyPair(new CreateKeyPairRequest().withKeyName(keyName));
    return result.getKeyPair();
}
项目:sequenceiq-samples    文件:SimpleKeyPairService.java   
public CreateKeyPairResult createKeyPair(AmazonEC2Client client, String keyName) {
    CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest().withKeyName(keyName);
    CreateKeyPairResult createKeyPairResult = client.createKeyPair(createKeyPairRequest);
    return createKeyPairResult;
}
项目:aws-sdk-java-resources    文件:EC2Impl.java   
@Override
public KeyPair createKeyPair(CreateKeyPairRequest request) {
    return createKeyPair(request, null);
}
项目:aws-sdk-java-resources    文件:EC2.java   
/**
 * 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);
项目:aws-sdk-java-resources    文件:EC2.java   
/**
 * Performs the <code>CreateKeyPair</code> action and use a ResultCapture to
 * retrieve the low-level client response.
 *
 * <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, ResultCapture<CreateKeyPairResult> extractor);