1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.trmk.vcloud_0_8.options;
20
21 import static com.google.common.base.Preconditions.checkArgument;
22 import static com.google.common.base.Preconditions.checkNotNull;
23
24 import java.net.URI;
25 import java.util.Map;
26 import java.util.Set;
27
28 import org.jclouds.javax.annotation.Nullable;
29
30 import org.jclouds.ovf.NetworkSection;
31 import org.jclouds.trmk.vcloud_0_8.domain.FenceMode;
32
33 import com.google.common.collect.Maps;
34 import com.google.common.collect.Sets;
35
36
37
38
39
40
41 public class InstantiateVAppTemplateOptions {
42 public static class NetworkConfig {
43 @Nullable
44 private final String networkName;
45 private final URI parentNetwork;
46 @Nullable
47 private final FenceMode fenceMode;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 public NetworkConfig(String networkName, URI parentNetwork, FenceMode fenceMode) {
65 this.networkName = networkName;
66 this.parentNetwork = checkNotNull(parentNetwork, "parentNetwork");
67 this.fenceMode = fenceMode;
68 }
69
70 public NetworkConfig(URI parentNetwork) {
71 this(null, parentNetwork, null);
72 }
73
74
75
76
77
78
79
80
81
82
83 public String getNetworkName() {
84 return networkName;
85 }
86
87
88
89
90
91
92 public URI getParentNetwork() {
93 return parentNetwork;
94 }
95
96
97
98
99
100 public FenceMode getFenceMode() {
101 return fenceMode;
102 }
103
104 @Override
105 public int hashCode() {
106 final int prime = 31;
107 int result = 1;
108 result = prime * result + ((fenceMode == null) ? 0 : fenceMode.hashCode());
109 result = prime * result + ((parentNetwork == null) ? 0 : parentNetwork.hashCode());
110 result = prime * result + ((networkName == null) ? 0 : networkName.hashCode());
111 return result;
112 }
113
114 @Override
115 public boolean equals(Object obj) {
116 if (this == obj)
117 return true;
118 if (obj == null)
119 return false;
120 if (getClass() != obj.getClass())
121 return false;
122 NetworkConfig other = (NetworkConfig) obj;
123 if (fenceMode == null) {
124 if (other.fenceMode != null)
125 return false;
126 } else if (!fenceMode.equals(other.fenceMode))
127 return false;
128 if (parentNetwork == null) {
129 if (other.parentNetwork != null)
130 return false;
131 } else if (!parentNetwork.equals(other.parentNetwork))
132 return false;
133 if (networkName == null) {
134 if (other.networkName != null)
135 return false;
136 } else if (!networkName.equals(other.networkName))
137 return false;
138 return true;
139 }
140
141 @Override
142 public String toString() {
143 return "[networkName=" + networkName + ", parentNetwork=" + parentNetwork + ", fenceMode=" + fenceMode + "]";
144 }
145 }
146
147 private Set<NetworkConfig> networkConfig = Sets.newLinkedHashSet();
148
149 private Boolean customizeOnInstantiate;
150 private String cpuCount;
151 private String memorySizeMegabytes;
152
153 private boolean block = true;
154 private boolean deploy = true;
155 private boolean powerOn = true;
156
157 private final Map<String, String> properties = Maps.newLinkedHashMap();
158
159 public InstantiateVAppTemplateOptions sshKeyFingerprint(String sshKeyFingerprint) {
160 productProperty("sshKeyFingerprint", sshKeyFingerprint);
161 return this;
162 }
163
164 public InstantiateVAppTemplateOptions primaryDNS(String primaryDNS) {
165 productProperty("primaryDNS", primaryDNS);
166 return this;
167 }
168
169 public InstantiateVAppTemplateOptions secondaryDNS(String secondaryDNS) {
170 productProperty("secondaryDNS", secondaryDNS);
171 return this;
172 }
173
174 public InstantiateVAppTemplateOptions withPassword(String password) {
175 productProperty("password", password);
176 return this;
177 }
178
179 public InstantiateVAppTemplateOptions inGroup(String group) {
180 productProperty("group", group);
181 return this;
182 }
183
184 public InstantiateVAppTemplateOptions inRow(String row) {
185 productProperty("row", row);
186 return this;
187 }
188
189 public InstantiateVAppTemplateOptions productProperties(Map<String, String> properties) {
190 this.properties.putAll(properties);
191 return this;
192 }
193
194 public InstantiateVAppTemplateOptions productProperty(String key, String value) {
195 this.properties.put(key, value);
196 return this;
197 }
198
199 public Map<String, String> getProperties() {
200 return properties;
201 }
202
203 public boolean shouldBlock() {
204 return block;
205 }
206
207 public boolean shouldDeploy() {
208 return deploy;
209 }
210
211 public boolean shouldPowerOn() {
212 return powerOn;
213 }
214
215
216
217
218 public InstantiateVAppTemplateOptions deploy(boolean deploy) {
219 this.deploy = deploy;
220 return this;
221 }
222
223
224
225
226 public InstantiateVAppTemplateOptions powerOn(boolean powerOn) {
227 this.powerOn = powerOn;
228 return this;
229 }
230
231
232
233
234 public InstantiateVAppTemplateOptions block(boolean block) {
235 this.block = block;
236 return this;
237 }
238
239
240
241
242
243 public InstantiateVAppTemplateOptions customizeOnInstantiate(boolean customizeOnInstantiate) {
244 this.customizeOnInstantiate = customizeOnInstantiate;
245 return this;
246 }
247
248 public InstantiateVAppTemplateOptions processorCount(int cpuCount) {
249 checkArgument(cpuCount >= 1, "cpuCount must be positive");
250 this.cpuCount = cpuCount + "";
251 return this;
252 }
253
254 public InstantiateVAppTemplateOptions memory(long megabytes) {
255 checkArgument(megabytes >= 1, "megabytes must be positive");
256 this.memorySizeMegabytes = megabytes + "";
257 return this;
258 }
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276 public InstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) {
277 this.networkConfig.add(checkNotNull(networkConfig, "networkConfig"));
278 return this;
279 }
280
281 public Set<NetworkConfig> getNetworkConfig() {
282 return networkConfig;
283 }
284
285 public String getCpuCount() {
286 return cpuCount;
287 }
288
289 public Boolean shouldCustomizeOnInstantiate() {
290 return customizeOnInstantiate;
291 }
292
293 public String getMemorySizeMegabytes() {
294 return memorySizeMegabytes;
295 }
296
297 public static class Builder {
298
299
300
301
302 public static InstantiateVAppTemplateOptions block(boolean block) {
303 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
304 return options.block(block);
305 }
306
307
308
309
310 public static InstantiateVAppTemplateOptions deploy(boolean deploy) {
311 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
312 return options.deploy(deploy);
313 }
314
315
316
317
318 public static InstantiateVAppTemplateOptions powerOn(boolean powerOn) {
319 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
320 return options.powerOn(powerOn);
321 }
322
323
324
325
326 public static InstantiateVAppTemplateOptions processorCount(int cpuCount) {
327 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
328 return options.processorCount(cpuCount);
329 }
330
331
332
333
334 public static InstantiateVAppTemplateOptions customizeOnInstantiate(Boolean customizeOnInstantiate) {
335 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
336 return options.customizeOnInstantiate(customizeOnInstantiate);
337 }
338
339
340
341
342 public static InstantiateVAppTemplateOptions memory(int megabytes) {
343 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
344 return options.memory(megabytes);
345 }
346
347
348
349
350 public static InstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) {
351 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
352 return options.addNetworkConfig(networkConfig);
353 }
354
355
356
357
358 public static InstantiateVAppTemplateOptions withPassword(String password) {
359 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
360 return options.withPassword(password);
361 }
362
363
364
365
366 public static InstantiateVAppTemplateOptions inGroup(String group) {
367 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
368 return options.inGroup(group);
369 }
370
371
372
373
374 public static InstantiateVAppTemplateOptions inRow(String row) {
375 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
376 return options.inRow(row);
377 }
378
379
380
381
382 public static InstantiateVAppTemplateOptions sshKeyFingerprint(String sshKeyFingerprint) {
383 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
384 return options.sshKeyFingerprint(sshKeyFingerprint);
385 }
386
387
388
389
390 public static InstantiateVAppTemplateOptions primaryDNS(String primaryDNS) {
391 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
392 return options.primaryDNS(primaryDNS);
393 }
394
395
396
397
398 public static InstantiateVAppTemplateOptions secondaryDNS(String secondaryDNS) {
399 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
400 return options.secondaryDNS(secondaryDNS);
401 }
402
403
404
405
406 public static InstantiateVAppTemplateOptions productProperty(String key, String value) {
407 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
408 return (InstantiateVAppTemplateOptions) options.productProperty(key, value);
409 }
410
411
412
413
414
415 public static InstantiateVAppTemplateOptions productProperties(Map<String, String> properties) {
416 InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
417 return (InstantiateVAppTemplateOptions) options.productProperties(properties);
418 }
419
420 }
421
422 @Override
423 public String toString() {
424 return "[cpuCount=" + cpuCount + ", memorySizeMegabytes=" + memorySizeMegabytes + ", networkConfig="
425 + networkConfig + ", customizeOnInstantiate=" + customizeOnInstantiate + ", deploy=" + (deploy)
426 + ", powerOn=" + (powerOn) + "]";
427 }
428
429 @Override
430 public int hashCode() {
431 final int prime = 31;
432 int result = 1;
433 result = prime * result + (block ? 1231 : 1237);
434 result = prime * result + ((cpuCount == null) ? 0 : cpuCount.hashCode());
435 result = prime * result + ((customizeOnInstantiate == null) ? 0 : customizeOnInstantiate.hashCode());
436 result = prime * result + (deploy ? 1231 : 1237);
437 result = prime * result + ((memorySizeMegabytes == null) ? 0 : memorySizeMegabytes.hashCode());
438 result = prime * result + ((networkConfig == null) ? 0 : networkConfig.hashCode());
439 result = prime * result + (powerOn ? 1231 : 1237);
440 return result;
441 }
442
443 @Override
444 public boolean equals(Object obj) {
445 if (this == obj)
446 return true;
447 if (obj == null)
448 return false;
449 if (getClass() != obj.getClass())
450 return false;
451 InstantiateVAppTemplateOptions other = (InstantiateVAppTemplateOptions) obj;
452 if (block != other.block)
453 return false;
454 if (cpuCount == null) {
455 if (other.cpuCount != null)
456 return false;
457 } else if (!cpuCount.equals(other.cpuCount))
458 return false;
459 if (customizeOnInstantiate == null) {
460 if (other.customizeOnInstantiate != null)
461 return false;
462 } else if (!customizeOnInstantiate.equals(other.customizeOnInstantiate))
463 return false;
464 if (deploy != other.deploy)
465 return false;
466 if (memorySizeMegabytes == null) {
467 if (other.memorySizeMegabytes != null)
468 return false;
469 } else if (!memorySizeMegabytes.equals(other.memorySizeMegabytes))
470 return false;
471 if (networkConfig == null) {
472 if (other.networkConfig != null)
473 return false;
474 } else if (!networkConfig.equals(other.networkConfig))
475 return false;
476 if (powerOn != other.powerOn)
477 return false;
478 return true;
479 }
480
481 }