コード例 #1
0
ファイル: AWSClient.java プロジェクト: jnayegandhi/SimianArmy
  /**
   * Describe a set of specific images.
   *
   * @param imageIds the image ids
   * @return the images
   */
  public List<Image> describeImages(String... imageIds) {
    if (imageIds == null || imageIds.length == 0) {
      LOGGER.info("Getting all AMIs.");
    } else {
      LOGGER.info(String.format("Getting AMIs for %d ids.", imageIds.length));
    }

    AmazonEC2 ec2Client = ec2Client();
    DescribeImagesRequest request = new DescribeImagesRequest();
    if (imageIds != null) {
      request.setImageIds(Arrays.asList(imageIds));
    }
    DescribeImagesResult result = ec2Client.describeImages(request);
    List<Image> images = result.getImages();

    LOGGER.info(String.format("Got %d AMIs.", images.size()));
    return images;
  }
コード例 #2
0
 /** * Check that the AMI requested is available in the cloud and can be used. */
 public FormValidation doValidateAmi(
     @QueryParameter boolean useInstanceProfileForCredentials,
     @QueryParameter String credentialsId,
     @QueryParameter String ec2endpoint,
     @QueryParameter String region,
     final @QueryParameter String ami)
     throws IOException {
   AWSCredentialsProvider credentialsProvider =
       EC2Cloud.createCredentialsProvider(useInstanceProfileForCredentials, credentialsId);
   AmazonEC2 ec2;
   if (region != null) {
     ec2 = EC2Cloud.connect(credentialsProvider, AmazonEC2Cloud.getEc2EndpointUrl(region));
   } else {
     ec2 = EC2Cloud.connect(credentialsProvider, new URL(ec2endpoint));
   }
   if (ec2 != null) {
     try {
       List<String> images = new LinkedList<String>();
       images.add(ami);
       List<String> owners = new LinkedList<String>();
       List<String> users = new LinkedList<String>();
       DescribeImagesRequest request = new DescribeImagesRequest();
       request.setImageIds(images);
       request.setOwners(owners);
       request.setExecutableUsers(users);
       List<Image> img = ec2.describeImages(request).getImages();
       if (img == null || img.isEmpty()) {
         // de-registered AMI causes an empty list to be
         // returned. so be defensive
         // against other possibilities
         return FormValidation.error("No such AMI, or not usable with this accessId: " + ami);
       }
       String ownerAlias = img.get(0).getImageOwnerAlias();
       return FormValidation.ok(
           img.get(0).getImageLocation() + (ownerAlias != null ? " by " + ownerAlias : ""));
     } catch (AmazonClientException e) {
       return FormValidation.error(e.getMessage());
     }
   } else return FormValidation.ok(); // can't test
 }