1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.vcloud.options;
20
21 import static com.google.common.base.Preconditions.checkArgument;
22 import static com.google.common.base.Preconditions.checkNotNull;
23
24 import java.util.Set;
25
26 import org.jclouds.vcloud.domain.network.NetworkConfig;
27
28 import com.google.common.collect.Sets;
29
30
31
32
33
34
35 public class InstantiateVAppTemplateOptions {
36 private Set<NetworkConfig> networkConfig = Sets.newLinkedHashSet();
37
38 private Boolean customizeOnInstantiate;
39 private String cpuCount;
40 private String memorySizeMegabytes;
41 private String diskSizeKilobytes;
42
43 private boolean block = true;
44 private boolean deploy = true;
45 private boolean powerOn = true;
46
47 public boolean shouldBlock() {
48 return block;
49 }
50
51 public boolean shouldDeploy() {
52 return deploy;
53 }
54
55 public boolean shouldPowerOn() {
56 return powerOn;
57 }
58
59
60
61
62 public InstantiateVAppTemplateOptions deploy(boolean deploy) {
63 this.deploy = deploy;
64 return this;
65 }
66
67
68
69
70 public InstantiateVAppTemplateOptions powerOn(boolean powerOn) {
71 this.powerOn = powerOn;
72 return this;
73 }
74
75
76
77
78 public InstantiateVAppTemplateOptions block(boolean block) {
79 this.block = block;
80 return this;
81 }
82
83
84
85
86
87 public InstantiateVAppTemplateOptions customizeOnInstantiate(boolean customizeOnInstantiate) {
88 this.customizeOnInstantiate = customizeOnInstantiate;
89 return this;
90 }
91
92 public InstantiateVAppTemplateOptions processorCount(int cpuCount) {
93 checkArgument(cpuCount >= 1, "cpuCount must be positive");
94 this.cpuCount = cpuCount + "";
95 return this;
96 }
97
98 public InstantiateVAppTemplateOptions memory(long megabytes) {
99 checkArgument(megabytes >= 1, "megabytes must be positive");
100 this.memorySizeMegabytes = megabytes + "";
101 return this;
102 }
103
104 public InstantiateVAppTemplateOptions disk(long kilobytes) {
105 checkArgument(kilobytes >= 1, "diskSizeKilobytes must be positive");
106 this.diskSizeKilobytes = kilobytes + "";
107 return this;
108 }
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 public InstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) {
124 this.networkConfig.add(checkNotNull(networkConfig, "networkConfig"));
125 return this;
126 }
127
128 public Set<NetworkConfig> getNetworkConfig() {
129 return networkConfig;
130 }
131
132 public String getCpuCount() {
133 return cpuCount;
134 }
135
136 public Boolean shouldCustomizeOnInstantiate() {
137 return customizeOnInstantiate;
138 }
139
140 public String getMemorySizeMegabytes() {
141 return memorySizeMegabytes;
142 }
143
144 public String getDiskSizeKilobytes() {
145 return diskSizeKilobytes;
146 }
147
148 public static class Builder {
149
150
151
152
153 public static InstantiateVAppTemplateOptions block(boolean block) {
154 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
155 return options.block(block);
156 }
157
158
159
160
161 public static InstantiateVAppTemplateOptions deploy(boolean deploy) {
162 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
163 return options.deploy(deploy);
164 }
165
166
167
168
169 public static InstantiateVAppTemplateOptions powerOn(boolean powerOn) {
170 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
171 return options.powerOn(powerOn);
172 }
173
174
175
176
177 public static InstantiateVAppTemplateOptions processorCount(int cpuCount) {
178 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
179 return options.processorCount(cpuCount);
180 }
181
182
183
184
185 public static InstantiateVAppTemplateOptions customizeOnInstantiate(Boolean customizeOnInstantiate) {
186 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
187 return options.customizeOnInstantiate(customizeOnInstantiate);
188 }
189
190
191
192
193 public static InstantiateVAppTemplateOptions memory(int megabytes) {
194 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
195 return options.memory(megabytes);
196 }
197
198
199
200
201 public static InstantiateVAppTemplateOptions disk(long kilobytes) {
202 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
203 return options.disk(kilobytes);
204 }
205
206
207
208
209 public static InstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) {
210 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
211 return options.addNetworkConfig(networkConfig);
212 }
213
214 }
215
216 @Override
217 public String toString() {
218 return "InstantiateVAppTemplateOptions [cpuCount=" + cpuCount + ", memorySizeMegabytes=" + memorySizeMegabytes
219 + ", diskSizeKilobytes=" + diskSizeKilobytes + ", networkConfig=" + networkConfig
220 + ", customizeOnInstantiate=" + customizeOnInstantiate + ", deploy=" + (deploy) + ", powerOn="
221 + (powerOn) + "]";
222 }
223
224 @Override
225 public int hashCode() {
226 final int prime = 31;
227 int result = 1;
228 result = prime * result + (block ? 1231 : 1237);
229 result = prime * result + ((cpuCount == null) ? 0 : cpuCount.hashCode());
230 result = prime * result + ((customizeOnInstantiate == null) ? 0 : customizeOnInstantiate.hashCode());
231 result = prime * result + (deploy ? 1231 : 1237);
232 result = prime * result + ((diskSizeKilobytes == null) ? 0 : diskSizeKilobytes.hashCode());
233 result = prime * result + ((memorySizeMegabytes == null) ? 0 : memorySizeMegabytes.hashCode());
234 result = prime * result + ((networkConfig == null) ? 0 : networkConfig.hashCode());
235 result = prime * result + (powerOn ? 1231 : 1237);
236 return result;
237 }
238
239 @Override
240 public boolean equals(Object obj) {
241 if (this == obj)
242 return true;
243 if (obj == null)
244 return false;
245 if (getClass() != obj.getClass())
246 return false;
247 InstantiateVAppTemplateOptions other = (InstantiateVAppTemplateOptions) obj;
248 if (block != other.block)
249 return false;
250 if (cpuCount == null) {
251 if (other.cpuCount != null)
252 return false;
253 } else if (!cpuCount.equals(other.cpuCount))
254 return false;
255 if (customizeOnInstantiate == null) {
256 if (other.customizeOnInstantiate != null)
257 return false;
258 } else if (!customizeOnInstantiate.equals(other.customizeOnInstantiate))
259 return false;
260 if (deploy != other.deploy)
261 return false;
262 if (diskSizeKilobytes == null) {
263 if (other.diskSizeKilobytes != null)
264 return false;
265 } else if (!diskSizeKilobytes.equals(other.diskSizeKilobytes))
266 return false;
267 if (memorySizeMegabytes == null) {
268 if (other.memorySizeMegabytes != null)
269 return false;
270 } else if (!memorySizeMegabytes.equals(other.memorySizeMegabytes))
271 return false;
272 if (networkConfig == null) {
273 if (other.networkConfig != null)
274 return false;
275 } else if (!networkConfig.equals(other.networkConfig))
276 return false;
277 if (powerOn != other.powerOn)
278 return false;
279 return true;
280 }
281
282 }