| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. 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, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.ec2.options; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import org.jclouds.ec2.domain.Image.Architecture; |
| 24 | import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; |
| 25 | |
| 26 | /** |
| 27 | * Contains options supported in the Form API for the RegisterImage operation. <h2> |
| 28 | * Usage</h2> The recommended way to instantiate a RegisterImageOptions object is to statically |
| 29 | * import RegisterImageOptions.Builder.* and invoke a static creation method followed by an instance |
| 30 | * mutator (if needed): |
| 31 | * <p/> |
| 32 | * <code> |
| 33 | * import static org.jclouds.ec2.options.RegisterImageOptions.Builder.* |
| 34 | * <p/> |
| 35 | * EC2Client connection = // get connection |
| 36 | * String imageId = connection.getImageServices().registerImageFromManifest(...withArchitecture(Architecture.I386).withDescription("description")); |
| 37 | * <code> |
| 38 | * |
| 39 | * @author Adrian Cole |
| 40 | * @see <a |
| 41 | * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-RegisterImage.html" |
| 42 | * /> |
| 43 | */ |
| 44 | public class RegisterImageOptions extends BaseEC2RequestOptions { |
| 45 | |
| 46 | /** |
| 47 | * The architecture of the image. |
| 48 | */ |
| 49 | public RegisterImageOptions asArchitecture(Architecture architecture) { |
| 50 | formParameters.put("Architecture", checkNotNull(architecture, "architecture").value()); |
| 51 | return this; |
| 52 | } |
| 53 | |
| 54 | String getArchitecture() { |
| 55 | return getFirstFormOrNull("Architecture"); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | *The description of the AMI. "Up to 255 characters." |
| 60 | */ |
| 61 | public RegisterImageOptions withDescription(String info) { |
| 62 | formParameters.put("Description", checkNotNull(info, "info")); |
| 63 | return this; |
| 64 | } |
| 65 | |
| 66 | String getDescription() { |
| 67 | return getFirstFormOrNull("Description"); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * The ID of the kernel to select. |
| 72 | */ |
| 73 | public RegisterImageOptions withKernelId(String kernelId) { |
| 74 | formParameters.put("KernelId", checkNotNull(kernelId, "kernelId")); |
| 75 | return this; |
| 76 | } |
| 77 | |
| 78 | String getKernelId() { |
| 79 | return getFirstFormOrNull("KernelId"); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * The ID of the RAM disk to select. Some kernels require additional drivers at launch. Check the |
| 84 | * kernel requirements for information on whether you need to specify a RAM disk. To find kernel |
| 85 | * requirements, refer to the Resource Center and search for the kernel ID. |
| 86 | */ |
| 87 | public RegisterImageOptions withRamdisk(String ramDiskId) { |
| 88 | formParameters.put("RamdiskId", checkNotNull(ramDiskId, "ramDiskId")); |
| 89 | return this; |
| 90 | } |
| 91 | |
| 92 | String getRamdiskId() { |
| 93 | return getFirstFormOrNull("RamdiskId"); |
| 94 | } |
| 95 | |
| 96 | public static class Builder { |
| 97 | /** |
| 98 | * @see RegisterImageOptions#asArchitecture(Architecture) |
| 99 | */ |
| 100 | public static RegisterImageOptions asArchitecture(Architecture architecture) { |
| 101 | RegisterImageOptions options = new RegisterImageOptions(); |
| 102 | return options.asArchitecture(architecture); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @see RegisterImageOptions#withDescription(String) |
| 107 | */ |
| 108 | public static RegisterImageOptions withDescription(String additionalInfo) { |
| 109 | RegisterImageOptions options = new RegisterImageOptions(); |
| 110 | return options.withDescription(additionalInfo); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @see RegisterImageOptions#withKernelId(String) |
| 115 | */ |
| 116 | public static RegisterImageOptions withKernelId(String kernelId) { |
| 117 | RegisterImageOptions options = new RegisterImageOptions(); |
| 118 | return options.withKernelId(kernelId); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @see RegisterImageOptions#withRamdisk(String) |
| 123 | */ |
| 124 | public static RegisterImageOptions withRamdisk(String ramdiskId) { |
| 125 | RegisterImageOptions options = new RegisterImageOptions(); |
| 126 | return options.withRamdisk(ramdiskId); |
| 127 | } |
| 128 | |
| 129 | } |
| 130 | } |