| 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.deltacloud.options; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import org.jclouds.http.options.BaseHttpRequestOptions; |
| 24 | |
| 25 | /** |
| 26 | * Contains options supported in the Deltacloud API for the Create Instance operation. <h2> |
| 27 | * Usage</h2> The recommended way to instantiate a CreateInstanceOptions object is to statically |
| 28 | * import CreateInstanceOptions.Builder.* and invoke a static creation method followed by an |
| 29 | * instance mutator (if needed): |
| 30 | * <p/> |
| 31 | * <code> |
| 32 | * import static org.jclouds.deltacloud.options.CreateInstanceOptions.Builder.* |
| 33 | * <p/> |
| 34 | * DeltacloudClient connection = // get connection |
| 35 | * ListenableFuture<Instance> instance = client.createInstance(collection, "imageId", named("robot")); |
| 36 | * <code> |
| 37 | * |
| 38 | * @author Adrian Cole |
| 39 | * @see <a href="http://deltacloud.org/api.html#h1" /> |
| 40 | */ |
| 41 | public class CreateInstanceOptions extends BaseHttpRequestOptions { |
| 42 | public static final CreateInstanceOptions NONE = new CreateInstanceOptions(); |
| 43 | |
| 44 | /** |
| 45 | * A short label to identify the instance. |
| 46 | * |
| 47 | */ |
| 48 | public CreateInstanceOptions named(String name) { |
| 49 | formParameters.put("name", checkNotNull(name, "name")); |
| 50 | return this; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * The realm in which to launch the instance |
| 55 | * |
| 56 | */ |
| 57 | public CreateInstanceOptions realm(String realmId) { |
| 58 | formParameters.put("realm_id", checkNotNull(realmId, "realmId")); |
| 59 | return this; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * The hardware profile upon which to launch the instance |
| 64 | */ |
| 65 | public CreateInstanceOptions hardwareProfile(String hwpName) { |
| 66 | formParameters.put("hwp_name", checkNotNull(hwpName, "hwpName")); |
| 67 | return this; |
| 68 | } |
| 69 | |
| 70 | public String getName() { |
| 71 | return this.getFirstFormOrNull("name"); |
| 72 | } |
| 73 | |
| 74 | public static class Builder { |
| 75 | |
| 76 | /** |
| 77 | * @see CreateInstanceOptions#named |
| 78 | */ |
| 79 | public static CreateInstanceOptions named(String name) { |
| 80 | CreateInstanceOptions options = new CreateInstanceOptions(); |
| 81 | return options.named(name); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @see CreateInstanceOptions#realm |
| 86 | */ |
| 87 | public static CreateInstanceOptions realm(String realmId) { |
| 88 | CreateInstanceOptions options = new CreateInstanceOptions(); |
| 89 | return options.realm(realmId); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @see CreateInstanceOptions#hardwareProfile |
| 94 | */ |
| 95 | public static CreateInstanceOptions hardwareProfile(String hwpName) { |
| 96 | CreateInstanceOptions options = new CreateInstanceOptions(); |
| 97 | return options.hardwareProfile(hwpName); |
| 98 | } |
| 99 | |
| 100 | } |
| 101 | } |