1 | /** |
2 | * |
3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
4 | * |
5 | * ==================================================================== |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * you may not use this file except in compliance with the License. |
8 | * 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, software |
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * See the License for the specific language governing permissions and |
16 | * limitations under the License. |
17 | * ==================================================================== |
18 | */ |
19 | package org.jclouds.compute.domain.os; |
20 | |
21 | import org.jclouds.compute.domain.OperatingSystem; |
22 | import org.jclouds.compute.domain.OsFamily; |
23 | |
24 | import com.google.common.annotations.Beta; |
25 | |
26 | /** |
27 | * Operating system based on DMTF CIM model. |
28 | * |
29 | * @author Adrian Cole |
30 | * @see <a href="http://dmtf.org/standards/cim/cim_schema_v2260">DMTF CIM model</a> |
31 | */ |
32 | @Beta |
33 | public class CIMOperatingSystem extends OperatingSystem { |
34 | |
35 | public enum OSType { |
36 | /** |
37 | * Other |
38 | */ |
39 | OTHER(1, "Other", OsFamily.UNRECOGNIZED, false), |
40 | /** |
41 | * MACOS |
42 | */ |
43 | MACOS(2, "MACOS", OsFamily.DARWIN, false), |
44 | /** |
45 | * Solaris |
46 | */ |
47 | SOLARIS(29, "Solaris", OsFamily.SOLARIS, false), |
48 | /** |
49 | * LINUX |
50 | */ |
51 | LINUX(36, "LINUX", OsFamily.LINUX, false), |
52 | /** |
53 | * FreeBSD |
54 | */ |
55 | FREEBSD(42, "FreeBSD", OsFamily.FREEBSD, false), |
56 | /** |
57 | * NetBSD |
58 | */ |
59 | NETBSD(43, "NetBSD", OsFamily.NETBSD, false), |
60 | /** |
61 | * OpenBSD |
62 | */ |
63 | OPENBSD(65, "OpenBSD", OsFamily.OPENBSD, false), |
64 | /** |
65 | * Not Applicable |
66 | */ |
67 | NOT_APPLICABLE(66, "Not Applicable", OsFamily.UNRECOGNIZED, false), |
68 | /** |
69 | * Microsoft Windows Server 2003 |
70 | */ |
71 | WINDOWS_SERVER_2003(69, "Microsoft Windows Server 2003", OsFamily.WINDOWS, false), |
72 | /** |
73 | * Microsoft Windows Server 2003 64-Bit |
74 | */ |
75 | WINDOWS_SERVER_2003_64(70, "Microsoft Windows Server 2003 64-Bit", OsFamily.WINDOWS, true), |
76 | /** |
77 | * Microsoft Windows Server 2008 |
78 | */ |
79 | WINDOWS_SERVER_2008(76, "Microsoft Windows Server 2008", OsFamily.WINDOWS, false), |
80 | /** |
81 | * Microsoft Windows Server 2008 64-Bit |
82 | */ |
83 | WINDOWS_SERVER_2008_64(77, "Microsoft Windows Server 2008 64-Bit", OsFamily.WINDOWS, true), |
84 | /** |
85 | * FreeBSD 64-Bit |
86 | */ |
87 | FREEBSD_64(78, "FreeBSD 64-Bit", OsFamily.FREEBSD, true), |
88 | /** |
89 | * RedHat Enterprise Linux |
90 | */ |
91 | RHEL(79, "RedHat Enterprise Linux", OsFamily.RHEL, false), |
92 | /** |
93 | * RedHat Enterprise Linux 64-Bit |
94 | */ |
95 | RHEL_64(80, "RedHat Enterprise Linux 64-Bit", OsFamily.RHEL, true), |
96 | /** |
97 | * Solaris 64-Bit |
98 | */ |
99 | SOLARIS_64(81, "Solaris 64-Bit", OsFamily.SOLARIS, true), |
100 | /** |
101 | * SUSE |
102 | */ |
103 | SUSE(82, "SUSE", OsFamily.SUSE, false), |
104 | /** |
105 | * SUSE 64-Bit |
106 | */ |
107 | SUSE_64(83, "SUSE 64-Bit", OsFamily.SUSE, true), |
108 | /** |
109 | * SLES |
110 | */ |
111 | SLES(84, "SLES", OsFamily.SUSE, false), |
112 | /** |
113 | * SLES 64-Bit |
114 | */ |
115 | SLES_64(85, "SLES 64-Bit", OsFamily.SUSE, true), |
116 | /** |
117 | * Novell OES |
118 | */ |
119 | NOVELL_OES(86, "Novell OES", OsFamily.SUSE, true), |
120 | /** |
121 | * Mandriva |
122 | */ |
123 | MANDRIVA(89, "Mandriva", OsFamily.MANDRIVA, false), |
124 | /** |
125 | * Mandriva 64-Bit |
126 | */ |
127 | MANDRIVA_64(90, "Mandriva 64-Bit", OsFamily.MANDRIVA, true), |
128 | /** |
129 | * TurboLinux |
130 | */ |
131 | TURBOLINUX(91, "TurboLinux", OsFamily.TURBOLINUX, false), |
132 | /** |
133 | * TurboLinux 64-Bit |
134 | */ |
135 | TURBOLINUX_64(92, "TurboLinux 64-Bit", OsFamily.TURBOLINUX, true), |
136 | /** |
137 | * Ubuntu |
138 | */ |
139 | UBUNTU(93, "Ubuntu", OsFamily.UBUNTU, false), |
140 | /** |
141 | * Ubuntu 64-Bit |
142 | */ |
143 | UBUNTU_64(94, "Ubuntu 64-Bit", OsFamily.UBUNTU, true), |
144 | /** |
145 | * Debian |
146 | */ |
147 | DEBIAN(95, "Debian", OsFamily.DEBIAN, false), |
148 | /** |
149 | * Debian 64-Bit |
150 | */ |
151 | DEBIAN_64(96, "Debian 64-Bit", OsFamily.DEBIAN, false), |
152 | /** |
153 | * Linux 2.4.x |
154 | */ |
155 | LINUX_2_4(97, "Linux 2.4.x", OsFamily.LINUX, false), |
156 | /** |
157 | * Linux 2.4.x 64-Bi |
158 | */ |
159 | LINUX_2_4_64(98, "Linux 2.4.x 64-Bit", OsFamily.LINUX, true), |
160 | /** |
161 | * Linux 2.6.x |
162 | */ |
163 | LINUX_2_6(99, "Linux 2.6.x", OsFamily.LINUX, false), |
164 | /** |
165 | * Linux 2.6.x 64-Bit |
166 | */ |
167 | LINUX_2_6_64(100, "Linux 2.6.x 64-Bit", OsFamily.LINUX, true), |
168 | /** |
169 | * Linux 64-Bit |
170 | */ |
171 | LINUX_64(101, "Linux 64-Bit", OsFamily.LINUX, true), |
172 | /** |
173 | * Other 64-Bit |
174 | */ |
175 | OTHER_64(102, "Other 64-Bit", OsFamily.UNRECOGNIZED, true), |
176 | /** |
177 | * Microsoft Windows Server 2008 R2 |
178 | */ |
179 | WINDOWS_SERVER_2008_R2(103, "Microsoft Windows Server 2008 R2", OsFamily.WINDOWS, true), |
180 | /** |
181 | * VMware ESXi |
182 | */ |
183 | ESXI(104, "VMware ESXi", OsFamily.ESX, true), |
184 | /** |
185 | * Microsoft Windows 7 |
186 | */ |
187 | WINDOWS_7(105, "Microsoft Windows 7", OsFamily.WINDOWS, false), |
188 | /** |
189 | * CentOS 32-bit |
190 | */ |
191 | CENTOS(106, "CentOS 32-bit", OsFamily.CENTOS, false), |
192 | /** |
193 | * CentOS 64-bit |
194 | */ |
195 | CENTOS_64(107, "CentOS 64-bit", OsFamily.CENTOS, true), |
196 | /** |
197 | * Oracle Enterprise Linux 32-bit |
198 | */ |
199 | ORACLE_ENTERPRISE_LINUX(108, "Oracle Enterprise Linux 32-bit", OsFamily.OEL, false), |
200 | /** |
201 | * Oracle Enterprise Linux 64-bit |
202 | */ |
203 | ORACLE_ENTERPRISE_LINUX_64(109, "Oracle Enterprise Linux 64-bit", OsFamily.OEL, true), UNRECOGNIZED( |
204 | Integer.MAX_VALUE, "UNRECOGNIZED", null, true); |
205 | |
206 | private final int code; |
207 | |
208 | public int getCode() { |
209 | return code; |
210 | } |
211 | |
212 | public String getValue() { |
213 | return value; |
214 | } |
215 | |
216 | public OsFamily getFamily() { |
217 | return family; |
218 | } |
219 | |
220 | public boolean is64Bit() { |
221 | return is64Bit; |
222 | } |
223 | |
224 | private final String value; |
225 | private final OsFamily family; |
226 | private final boolean is64Bit; |
227 | |
228 | OSType(int code, String value, OsFamily family, boolean is64Bit) { |
229 | this.code = code; |
230 | this.value = value; |
231 | this.family = family; |
232 | this.is64Bit = is64Bit; |
233 | } |
234 | |
235 | public static OSType fromValue(int code) { |
236 | for (OSType type : values()) { |
237 | if (type.code == code) |
238 | return type; |
239 | } |
240 | return UNRECOGNIZED; |
241 | } |
242 | |
243 | } |
244 | |
245 | private OSType osType; |
246 | |
247 | protected CIMOperatingSystem() { |
248 | super(); |
249 | } |
250 | |
251 | public CIMOperatingSystem(OSType osType, String version, String arch, String description) { |
252 | super(osType.getFamily(), osType.getValue(), version, arch, description, osType.is64Bit()); |
253 | this.osType = osType; |
254 | } |
255 | |
256 | /** |
257 | * CIM OSType of the image |
258 | */ |
259 | public OSType getOsType() { |
260 | return osType; |
261 | } |
262 | |
263 | @Override |
264 | public int hashCode() { |
265 | final int prime = 31; |
266 | int result = super.hashCode(); |
267 | result = prime * result + ((osType == null) ? 0 : osType.hashCode()); |
268 | return result; |
269 | } |
270 | |
271 | @Override |
272 | public boolean equals(Object obj) { |
273 | if (this == obj) |
274 | return true; |
275 | if (!super.equals(obj)) |
276 | return false; |
277 | if (getClass() != obj.getClass()) |
278 | return false; |
279 | CIMOperatingSystem other = (CIMOperatingSystem) obj; |
280 | if (osType == null) { |
281 | if (other.osType != null) |
282 | return false; |
283 | } else if (!osType.equals(other.osType)) |
284 | return false; |
285 | return true; |
286 | } |
287 | |
288 | @Override |
289 | public String toString() { |
290 | return "[osType=" + osType + ", version=" + getVersion() + ", arch=" + getArch() + ", description=" |
291 | + getDescription() + "]"; |
292 | } |
293 | } |