1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.savvis.vpdc.domain;
20
21 import static com.google.common.base.Preconditions.checkNotNull;
22
23 import java.net.URI;
24 import java.util.Set;
25
26 import org.jclouds.ovf.NetworkSection;
27 import org.jclouds.ovf.OperatingSystemSection;
28 import org.jclouds.ovf.ProductSection;
29 import org.jclouds.ovf.Section;
30 import org.jclouds.ovf.VirtualHardwareSection;
31 import org.jclouds.ovf.internal.BaseVirtualSystem;
32
33 import com.google.common.collect.ImmutableSet;
34 import com.google.common.collect.Multimap;
35 import com.google.common.collect.Sets;
36
37
38
39
40
41
42
43
44 public class VM extends BaseVirtualSystem<VM> implements Resource {
45
46
47
48
49
50
51
52
53
54
55
56
57
58 public enum Status {
59
60
61
62
63
64
65 UNRESOLVED,
66
67
68
69
70 RESOLVED,
71
72
73
74 OFF,
75
76
77
78 SUSPENDED,
79
80
81
82 ON,
83
84
85
86
87
88
89 UNKNOWN, UNRECOGNIZED;
90
91 public String value() {
92 switch (this) {
93 case UNRESOLVED:
94 return "0";
95 case RESOLVED:
96 return "1";
97 case OFF:
98 return "2";
99 case SUSPENDED:
100 return "3";
101 case ON:
102 return "4";
103 case UNKNOWN:
104 return "5";
105 default:
106 return "UNRECOGNIZED";
107 }
108 }
109
110 public static Status fromValue(String status) {
111 try {
112 return fromValue(Integer.parseInt(checkNotNull(status, "status")));
113 } catch (IllegalArgumentException e) {
114 return UNRECOGNIZED;
115 }
116 }
117
118 public static Status fromValue(int v) {
119 switch (v) {
120 case 0:
121 return UNRESOLVED;
122 case 1:
123 return RESOLVED;
124 case 2:
125 return OFF;
126 case 3:
127 return SUSPENDED;
128 case 4:
129 return ON;
130 case 5:
131 return UNKNOWN;
132 default:
133 return UNRECOGNIZED;
134 }
135 }
136
137 }
138
139 public static Builder builder() {
140 return new Builder();
141 }
142
143 public static class Builder extends BaseVirtualSystem.Builder<VM> {
144 protected String type;
145 protected URI href;
146 protected Status status;
147 protected NetworkSection networkSection;
148 protected Set<NetworkConfigSection> networkConfigSections = Sets.newLinkedHashSet();
149 protected Set<NetworkConnectionSection> networkConnectionSections = Sets.newLinkedHashSet();
150
151 public Builder id(String id) {
152 this.id = id;
153 return this;
154 }
155
156 public Builder name(String name) {
157 this.name = name;
158 return this;
159 }
160
161 public Builder type(String type) {
162 this.type = type;
163 return this;
164 }
165
166 public Builder href(URI href) {
167 this.href = href;
168 return this;
169 }
170
171 public Builder status(Status status) {
172 this.status = status;
173 return this;
174 }
175
176 public Builder networkSection(NetworkSection networkSection) {
177 this.networkSection = networkSection;
178 return this;
179 }
180
181
182
183
184 public Builder networkConfigSection(NetworkConfigSection networkConfigSection) {
185 this.networkConfigSections.add(checkNotNull(networkConfigSection, "networkConfigSection"));
186 return this;
187 }
188
189
190
191
192 public Builder networkConfigSections(Iterable<NetworkConfigSection> networkConfigSections) {
193 this.networkConfigSections = ImmutableSet.<NetworkConfigSection> copyOf(checkNotNull(networkConfigSections,
194 "networkConfigSections"));
195 return this;
196 }
197
198
199
200
201 public Builder networkConnectionSection(NetworkConnectionSection networkConnectionSection) {
202 this.networkConnectionSections.add(checkNotNull(networkConnectionSection, "networkConnectionSection"));
203 return this;
204 }
205
206
207
208
209 public Builder networkConnectionSections(Iterable<NetworkConnectionSection> networkConnectionSections) {
210 this.networkConnectionSections = ImmutableSet.<NetworkConnectionSection> copyOf(checkNotNull(
211 networkConnectionSections, "networkConnectionSections"));
212 return this;
213 }
214
215 @Override
216 public VM build() {
217 return new VM(id, info, name, operatingSystem, virtualHardwareSections, productSections, additionalSections, type,
218 href, status, networkSection, networkConfigSections, networkConnectionSections);
219 }
220
221 public Builder fromVM(VM in) {
222 return fromVirtualSystem(in).type(in.getType()).href(in.getHref()).status(in.getStatus()).networkSection(
223 in.getNetworkSection()).networkConfigSections(in.getNetworkConfigSections())
224 .networkConnectionSections(in.getNetworkConnectionSections());
225 }
226
227
228
229
230 @SuppressWarnings("unchecked")
231 @Override
232 public Builder additionalSection(String name, Section additionalSection) {
233 return Builder.class.cast(super.additionalSection(name, additionalSection));
234 }
235
236
237
238
239 @SuppressWarnings("unchecked")
240 @Override
241 public Builder additionalSections(Multimap<String, Section> additionalSections) {
242 return Builder.class.cast(super.additionalSections(additionalSections));
243 }
244
245
246
247
248 @Override
249 public Builder fromSection(Section<VM> in) {
250 return Builder.class.cast(super.fromSection(in));
251 }
252
253
254
255
256 @Override
257 public Builder fromVirtualSystem(BaseVirtualSystem<VM> in) {
258 return Builder.class.cast(super.fromVirtualSystem(in));
259 }
260
261
262
263
264 @Override
265 public Builder virtualHardwareSection(VirtualHardwareSection virtualHardwareSection) {
266 return Builder.class.cast(super.virtualHardwareSection(virtualHardwareSection));
267 }
268
269
270
271
272 @Override
273 public Builder virtualHardwareSections(Iterable<? extends VirtualHardwareSection> virtualHardwareSections) {
274 return Builder.class.cast(super.virtualHardwareSections(virtualHardwareSections));
275 }
276
277
278
279
280 @Override
281 public Builder info(String info) {
282 return Builder.class.cast(super.info(info));
283 }
284
285
286
287
288 @Override
289 public Builder operatingSystemSection(OperatingSystemSection operatingSystem) {
290 return Builder.class.cast(super.operatingSystemSection(operatingSystem));
291 }
292
293
294
295
296 @Override
297 public Builder productSection(ProductSection productSection) {
298 return Builder.class.cast(super.productSection(productSection));
299 }
300
301
302
303
304 @Override
305 public Builder productSections(Iterable<? extends ProductSection> productSections) {
306 return Builder.class.cast(super.productSections(productSections));
307 }
308 }
309
310 protected final String type;
311 protected final URI href;
312 protected final Status status;
313 protected final NetworkSection networkSection;
314 protected final Set<NetworkConfigSection> networkConfigSections;
315 protected final Set<NetworkConnectionSection> networkConnectionSections;
316
317 @SuppressWarnings("unchecked")
318 public VM(String id, String info, String name, OperatingSystemSection operatingSystem,
319 Iterable<? extends VirtualHardwareSection> virtualHardwareSections,
320 Iterable<? extends ProductSection> productSections, Multimap<String, Section> additionalSections,
321 String type, URI href, Status status, NetworkSection networkSection,
322 Iterable<NetworkConfigSection> networkConfigSections,
323 Iterable<NetworkConnectionSection> networkConnectionSections) {
324 super(id, info, name, operatingSystem, virtualHardwareSections, productSections, additionalSections);
325 this.type = type;
326 this.href = href;
327 this.status = status;
328 this.networkSection = networkSection;
329 this.networkConfigSections = ImmutableSet.copyOf(checkNotNull(networkConfigSections, "networkConfigSections"));
330 this.networkConnectionSections = ImmutableSet.copyOf(checkNotNull(networkConnectionSections,
331 "networkConnectionSections"));
332 }
333
334 public Status getStatus() {
335 return status;
336 }
337
338 public NetworkSection getNetworkSection() {
339 return networkSection;
340 }
341
342 public Set<NetworkConfigSection> getNetworkConfigSections() {
343 return networkConfigSections;
344 }
345
346 public Set<NetworkConnectionSection> getNetworkConnectionSections() {
347 return networkConnectionSections;
348 }
349
350 public String getType() {
351 return type;
352 }
353
354 public URI getHref() {
355 return href;
356 }
357
358 @Override
359 public String toString() {
360 return String
361 .format(
362 "[id=%s, name=%s, info=%s, href=%s,status=%s, type=%s, virtualHardwareSections=%s, operatingSystem=%s, productSections=%s, networkSection=%s, networkConfigSections=%s, networkConnectionSections=%s, additionalSections=%s]",
363 id, name, info, href, status, type, virtualHardwareSections, operatingSystem, productSections,
364 networkSection, networkConfigSections, networkConnectionSections, additionalSections);
365 }
366
367 @Override
368 public int compareTo(Resource that) {
369 return (this == that) ? 0 : getHref().compareTo(that.getHref());
370 }
371
372 public Builder toBuilder() {
373 return builder().fromVM(this);
374 }
375
376 }