Пример #1
0
    protected FormValidation doTestConnection(
        URL ec2endpoint,
        boolean useInstanceProfileForCredentials,
        String accessId,
        String secretKey,
        String privateKey)
        throws IOException, ServletException {
      try {
        AWSCredentialsProvider credentialsProvider =
            createCredentialsProvider(useInstanceProfileForCredentials, accessId, secretKey);
        AmazonEC2 ec2 = connect(credentialsProvider, ec2endpoint);
        ec2.describeInstances();

        if (privateKey == null)
          return FormValidation.error(
              "Private key is not specified. Click 'Generate Key' to generate one.");

        if (privateKey.trim().length() > 0) {
          // check if this key exists
          EC2PrivateKey pk = new EC2PrivateKey(privateKey);
          if (pk.find(ec2) == null)
            return FormValidation.error(
                "The EC2 key pair private key isn't registered to this EC2 region (fingerprint is "
                    + pk.getFingerprint()
                    + ")");
        }

        return FormValidation.ok(Messages.EC2Cloud_Success());
      } catch (AmazonClientException e) {
        LOGGER.log(Level.WARNING, "Failed to check EC2 credential", e);
        return FormValidation.error(e.getMessage());
      }
    }
Пример #2
0
 /** Gets the {@link KeyPairInfo} used for the launch. */
 public synchronized KeyPair getKeyPair() throws AmazonClientException, IOException {
   if (usableKeyPair == null) usableKeyPair = privateKey.find(connect());
   return usableKeyPair;
 }