| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 18 | */ |
| 19 | package org.jclouds.ec2.options; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.util.Set; |
| 24 | |
| 25 | import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; |
| 26 | |
| 27 | /** |
| 28 | * Contains options supported in the Form API for the DescribeImages operation. <h2> |
| 29 | * Usage</h2> The recommended way to instantiate a DescribeImagesOptions object is to statically |
| 30 | * import DescribeImagesOptions.Builder.* and invoke a static creation method followed by an |
| 31 | * instance mutator (if needed): |
| 32 | * <p/> |
| 33 | * <code> |
| 34 | * import static org.jclouds.ec2.options.DescribeImagesOptions.Builder.* |
| 35 | * <p/> |
| 36 | * EC2Client connection = // get connection |
| 37 | * Future<Set<ImageMetadata>> images = connection.getAMIServices().describeImages(executableBy("123125").imageIds(1000, 1004)); |
| 38 | * <code> |
| 39 | * |
| 40 | * @author Adrian Cole |
| 41 | * @see <a |
| 42 | * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-DescribeImages.html" |
| 43 | * /> |
| 44 | */ |
| 45 | public class DescribeImagesOptions extends BaseEC2RequestOptions { |
| 46 | public static final DescribeImagesOptions NONE = new DescribeImagesOptions(); |
| 47 | |
| 48 | /** |
| 49 | * AMIs for which the specified user has explicit launch permissions. |
| 50 | * |
| 51 | */ |
| 52 | public DescribeImagesOptions executableBy(String identityId) { |
| 53 | formParameters.put("ExecutableBy", checkNotNull(identityId, "identityId")); |
| 54 | return this; |
| 55 | } |
| 56 | |
| 57 | public String getExecutableBy() { |
| 58 | return getFirstFormOrNull("ExecutableBy"); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * AMI IDs to describe. |
| 63 | */ |
| 64 | public DescribeImagesOptions imageIds(String... imageIds) { |
| 65 | indexFormValuesWithPrefix("ImageId", imageIds); |
| 66 | return this; |
| 67 | } |
| 68 | |
| 69 | public Set<String> getImageIds() { |
| 70 | return getFormValuesWithKeysPrefixedBy("ImageId."); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns AMIs owned by the specified owner. Multiple owners can be specified. |
| 75 | */ |
| 76 | public DescribeImagesOptions ownedBy(String... owners) { |
| 77 | indexFormValuesWithPrefix("Owner", owners); |
| 78 | return this; |
| 79 | } |
| 80 | |
| 81 | public Set<String> getOwners() { |
| 82 | return getFormValuesWithKeysPrefixedBy("Owner."); |
| 83 | } |
| 84 | |
| 85 | public static class Builder { |
| 86 | |
| 87 | /** |
| 88 | * @see DescribeImagesOptions#executableBy(String ) |
| 89 | */ |
| 90 | public static DescribeImagesOptions executableBy(String identityId) { |
| 91 | DescribeImagesOptions options = new DescribeImagesOptions(); |
| 92 | return options.executableBy(identityId); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @see DescribeImagesOptions#imageIds(String[] ) |
| 97 | */ |
| 98 | public static DescribeImagesOptions imageIds(String... imageIds) { |
| 99 | DescribeImagesOptions options = new DescribeImagesOptions(); |
| 100 | return options.imageIds(imageIds); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @see DescribeImagesOptions#ownedBy(String[] ) |
| 105 | */ |
| 106 | public static DescribeImagesOptions ownedBy(String... owners) { |
| 107 | DescribeImagesOptions options = new DescribeImagesOptions(); |
| 108 | return options.ownedBy(owners); |
| 109 | } |
| 110 | |
| 111 | } |
| 112 | } |