| 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.rimuhosting.miro.data; |
| 20 | |
| 21 | import java.util.List; |
| 22 | |
| 23 | import com.google.gson.annotations.SerializedName; |
| 24 | |
| 25 | import org.jclouds.rimuhosting.miro.domain.MetaData; |
| 26 | import org.jclouds.rimuhosting.miro.domain.ServerParameters; |
| 27 | import org.jclouds.rimuhosting.miro.domain.PricingPlan; |
| 28 | |
| 29 | /** |
| 30 | * This structure defines the VPS to be setup. |
| 31 | * |
| 32 | * @author Ivan Meredith |
| 33 | */ |
| 34 | public class NewServerData implements PostData { |
| 35 | public NewServerData() { |
| 36 | } |
| 37 | |
| 38 | public NewServerData(CreateOptions createOptions, PricingPlan pricingPlan) { |
| 39 | this.createOptions = createOptions; |
| 40 | if (pricingPlan != null) { |
| 41 | this.planId = pricingPlan.getId(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | public NewServerData(CreateOptions createOptions, String pricingPlanId) { |
| 46 | this.createOptions = createOptions; |
| 47 | this.planId = pricingPlanId; |
| 48 | } |
| 49 | |
| 50 | public NewServerData(CloneOptions cloneOptions) { |
| 51 | this.cloneOptions = cloneOptions; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Set the billing id if you want to control how it is billed. Else we will, for example, |
| 56 | * try to use, say, the credit card you used on your last order that had a credit card. Or |
| 57 | * use a wire transfer method if you are using that on other orders. See the billing |
| 58 | * methods resource for how to find what billing methods/ids you have setup on your identity. |
| 59 | */ |
| 60 | @SerializedName("billing_oid") |
| 61 | private Long billingId; |
| 62 | /** |
| 63 | * The host server on which to setup the server. Typically you will want to leave this |
| 64 | * blank and let the API decide what is best/available. And exception may be if you are a |
| 65 | * customer with a dedicated server that is a VPS host with us. And in that case you may |
| 66 | * want to force a VPS to be setup on a particular server of yours. |
| 67 | */ |
| 68 | @SerializedName("host_server_oid") |
| 69 | private String hostServerId; |
| 70 | /** |
| 71 | * These are the instantiation options. e.g. domain name, password, etc. Only provide |
| 72 | * these if you are not cloning a VPS (the vps_order_oid_to_clone setting). i.e. utually |
| 73 | * exclusive to instantiation_via_clone_options |
| 74 | */ |
| 75 | @SerializedName("instantiation_options") |
| 76 | private CreateOptions createOptions; |
| 77 | /** |
| 78 | * These are the instantiation options if you are creating a new VPS as a clone of an existing |
| 79 | * VPS. Mutually exclusive to instantiation_options. |
| 80 | */ |
| 81 | @SerializedName("instantiation_via_clone_options") |
| 82 | private CloneOptions cloneOptions; |
| 83 | /** |
| 84 | * The number of IPs you need on the VPS and a justification for having more than one. Just |
| 85 | * leave blank for a single IP (which is all most servers need). |
| 86 | */ |
| 87 | @SerializedName("ip_request") |
| 88 | private IpRequestData ipRequest; |
| 89 | /** |
| 90 | * The pricing plan code you want to use. Per the pricing plans resource. |
| 91 | */ |
| 92 | @SerializedName("pricing_plan_code") |
| 93 | private String planId; |
| 94 | /** |
| 95 | * To whom will the order belong? Leave this blank and we will assign it to you. If you set |
| 96 | * it and you do not have permissions on that user's identity you will get an error. |
| 97 | */ |
| 98 | @SerializedName("user_oid") |
| 99 | private Long userId; |
| 100 | /** |
| 101 | * Any particular memory/disk size overrides you want to make. If they are compatible with |
| 102 | * the pricing plan you selected we will use them. We will calculate the cost based on the |
| 103 | * resources we setup you up with. We can provision VPSs in most sizes, provided that the |
| 104 | * host has space for them. The low contention plans are an exception. You will |
| 105 | * likely need to use the provided memory and disk sizes. Since those plans are designed so |
| 106 | * there is a specific (small) number of VPSs per host. And having VPSs with 'odd' sizes |
| 107 | * stops them all fitting in 'neatly' (that's not a problem on the bigger-, non-low |
| 108 | * contention-plans. |
| 109 | */ |
| 110 | @SerializedName("vps_paramters") |
| 111 | private ServerParameters serverParameters; |
| 112 | |
| 113 | @SerializedName("meta_data") |
| 114 | private List<MetaData> metaData; |
| 115 | |
| 116 | public Long getBillingId() { |
| 117 | return billingId; |
| 118 | } |
| 119 | |
| 120 | public void setBillingId(Long billingId) { |
| 121 | this.billingId = billingId; |
| 122 | } |
| 123 | |
| 124 | public String getHostServerId() { |
| 125 | return hostServerId; |
| 126 | } |
| 127 | |
| 128 | public void setHostServerId(String hostServerId) { |
| 129 | this.hostServerId = hostServerId; |
| 130 | } |
| 131 | |
| 132 | public CreateOptions getCreateOptions() { |
| 133 | return createOptions; |
| 134 | } |
| 135 | |
| 136 | public void setCreateOptions(CreateOptions createOptions) { |
| 137 | this.createOptions = createOptions; |
| 138 | } |
| 139 | |
| 140 | public CloneOptions getCloneOptions() { |
| 141 | return cloneOptions; |
| 142 | } |
| 143 | |
| 144 | public void setCloneOptions(CloneOptions cloneOptions) { |
| 145 | this.cloneOptions = cloneOptions; |
| 146 | } |
| 147 | |
| 148 | public IpRequestData getIpRequest() { |
| 149 | return ipRequest; |
| 150 | } |
| 151 | |
| 152 | public void setIpRequest(IpRequestData ipRequest) { |
| 153 | this.ipRequest = ipRequest; |
| 154 | } |
| 155 | |
| 156 | public String getPlanId() { |
| 157 | return planId; |
| 158 | } |
| 159 | |
| 160 | public void setPlanId(String planId) { |
| 161 | this.planId = planId; |
| 162 | } |
| 163 | |
| 164 | public Long getUserId() { |
| 165 | return userId; |
| 166 | } |
| 167 | |
| 168 | public void setUserId(Long userId) { |
| 169 | this.userId = userId; |
| 170 | } |
| 171 | |
| 172 | public ServerParameters getInstanceParameters() { |
| 173 | return serverParameters; |
| 174 | } |
| 175 | |
| 176 | public void setInstanceParameters(ServerParameters serverParameters) { |
| 177 | this.serverParameters = serverParameters; |
| 178 | } |
| 179 | |
| 180 | public void validate() { |
| 181 | // bitwise XOR, works with boolean :) |
| 182 | assert (this.cloneOptions == null ^ this.createOptions == null); |
| 183 | if (this.cloneOptions != null) { |
| 184 | this.cloneOptions.validate(); |
| 185 | } |
| 186 | if (this.createOptions != null) { |
| 187 | this.createOptions.validate(); |
| 188 | assert (this.planId != null && this.planId.length() == 0); |
| 189 | } |
| 190 | |
| 191 | if (this.ipRequest != null) { |
| 192 | this.ipRequest.validate(); |
| 193 | } |
| 194 | |
| 195 | if (this.serverParameters != null) { |
| 196 | this.serverParameters.validate(); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | public void setMetaData(List<MetaData> metaData) { |
| 201 | this.metaData = metaData; |
| 202 | } |
| 203 | |
| 204 | public List<MetaData> getMetaData() { |
| 205 | return metaData; |
| 206 | } |
| 207 | } |