ovfparse 0.0.93 → 0.0.95
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ovfparse/marketplace_repository.rb +53 -0
- data/lib/ovfparse/os_id_table.rb +261 -0
- data/lib/ovfparse/vmpackage.rb +111 -54
- data/lib/ovfparse/vmrepository.rb +7 -3
- data/lib/ovfparse.rb +2 -0
- data/lib/test.rb +3 -3
- metadata +6 -4
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
class MarketplaceRepository < VmRepository
|
5
|
+
|
6
|
+
def parse (raw_html)
|
7
|
+
file_list = Array.new
|
8
|
+
|
9
|
+
xml = Nokogiri::XML(raw_html) do |config|
|
10
|
+
config.noblanks.strict.noent
|
11
|
+
end
|
12
|
+
|
13
|
+
entries = xml.root.children.select { |element| element.name == 'entry' }
|
14
|
+
|
15
|
+
entries.each { |entry|
|
16
|
+
repository = entry.children.detect { |element| element.name == 'repository' }
|
17
|
+
basepath = repository.children.detect { |element| element.name == 'basepath' }
|
18
|
+
filename = repository.children.detect { |element| element.name == 'filename' }
|
19
|
+
|
20
|
+
file_list.push( {'basepath' => basepath.content, 'filename' => filename.content} )
|
21
|
+
}
|
22
|
+
|
23
|
+
return file_list
|
24
|
+
end
|
25
|
+
|
26
|
+
def fetch
|
27
|
+
#retrieve data from http server
|
28
|
+
raw_html = open(uri)
|
29
|
+
if (raw_html)
|
30
|
+
|
31
|
+
#parse out package list from index html
|
32
|
+
package_list = parse(raw_html)
|
33
|
+
|
34
|
+
#construct package objects based on results
|
35
|
+
return listPackages(package_list)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def listPackages(package_list)
|
40
|
+
packages = Array.new
|
41
|
+
package_list.each { |pkg|
|
42
|
+
fullpath = (pkg['basepath'] + pkg['filename']).to_s
|
43
|
+
package = VmPackage.create(fullpath)
|
44
|
+
package.base_path = pkg['basepath']
|
45
|
+
package.name = pkg['filename']
|
46
|
+
|
47
|
+
packages.push(package)
|
48
|
+
}
|
49
|
+
|
50
|
+
return packages
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
#############################################################################################
|
2
|
+
# Reverse lookup table for the OVF spec/CIM spec listing of operating system IDs
|
3
|
+
# For reference:
|
4
|
+
#
|
5
|
+
# Go here
|
6
|
+
# http://dmtf.org/standards/cim
|
7
|
+
#
|
8
|
+
# Then pick the latest schema, in this case 2.28, here
|
9
|
+
# http://dmtf.org/standards/cim/cim_schema_v2280
|
10
|
+
#
|
11
|
+
# Then pick the .Zip archive of all Final MOF files., here
|
12
|
+
# http://dmtf.org/sites/default/files/cim/cim_schema_v2280/cim_schema_2.28.0Final-MOFs.zip
|
13
|
+
#
|
14
|
+
# The OS list is in System\CIM_OperatingSystem.mof, line 29.
|
15
|
+
#
|
16
|
+
# sample usage:
|
17
|
+
# require "os_id_table.rb"
|
18
|
+
#
|
19
|
+
# puts OS_ID_TABLE.value? "HPUX"
|
20
|
+
# => true
|
21
|
+
# puts OS_ID_TABLE.value? "arduino embedded"
|
22
|
+
# => false
|
23
|
+
# puts OS_ID_TABLE[55]
|
24
|
+
# => NextStep
|
25
|
+
#
|
26
|
+
# puts OS_ID_TABLE_REV.value? 1
|
27
|
+
# => true
|
28
|
+
# puts OS_ID_TABLE_REV.value? 250
|
29
|
+
# => false
|
30
|
+
# puts OS_ID_TABLE_REV["LINUX"]
|
31
|
+
# => 36
|
32
|
+
#
|
33
|
+
|
34
|
+
OS_ID_TABLE_REV = Hash[
|
35
|
+
"Unknown" => 0,
|
36
|
+
"Other" => 1,
|
37
|
+
"MACOS" => 2,
|
38
|
+
"ATTUNIX" => 3,
|
39
|
+
"DGUX" => 4,
|
40
|
+
"DECNT" => 5,
|
41
|
+
"Tru64 UNIX" => 6,
|
42
|
+
"OpenVMS" => 7,
|
43
|
+
"HPUX" => 8,
|
44
|
+
"AIX" => 9,
|
45
|
+
"MVS" => 10,
|
46
|
+
"OS400" => 11,
|
47
|
+
"OS/2" => 12,
|
48
|
+
"JavaVM" => 13,
|
49
|
+
"MSDOS" => 14,
|
50
|
+
"WIN3x" => 15,
|
51
|
+
"WIN95" => 16,
|
52
|
+
"WIN98" => 17,
|
53
|
+
"WINNT" => 18,
|
54
|
+
"WINCE" => 19,
|
55
|
+
"NCR3000" => 20,
|
56
|
+
"NetWare" => 21,
|
57
|
+
"OSF" => 22,
|
58
|
+
"DC/OS" => 23,
|
59
|
+
"Reliant UNIX" => 24,
|
60
|
+
"SCO UnixWare" => 25,
|
61
|
+
"SCO OpenServer" => 26,
|
62
|
+
"Sequent" => 27,
|
63
|
+
"IRIX" => 28,
|
64
|
+
"Solaris" => 29,
|
65
|
+
"SunOS" => 30,
|
66
|
+
"U6000" => 31,
|
67
|
+
"ASERIES" => 32,
|
68
|
+
"HP NonStop OS" => 33,
|
69
|
+
"HP NonStop OSS" => 34,
|
70
|
+
"BS2000" => 35,
|
71
|
+
"LINUX" => 36,
|
72
|
+
"Lynx" => 37,
|
73
|
+
"XENIX" => 38,
|
74
|
+
"VM" => 39,
|
75
|
+
"Interactive UNIX" => 40,
|
76
|
+
"BSDUNIX" => 41,
|
77
|
+
"FreeBSD" => 42,
|
78
|
+
"NetBSD" => 43,
|
79
|
+
"GNU Hurd" => 44,
|
80
|
+
"OS9" => 45,
|
81
|
+
"MACH Kernel" => 46,
|
82
|
+
"Inferno" => 47,
|
83
|
+
"QNX" => 48,
|
84
|
+
"EPOC" => 49,
|
85
|
+
"IxWorks" => 50,
|
86
|
+
"VxWorks" => 51,
|
87
|
+
"MiNT" => 52,
|
88
|
+
"BeOS" => 53,
|
89
|
+
"HP MPE" => 54,
|
90
|
+
"NextStep" => 55,
|
91
|
+
"PalmPilot" => 56,
|
92
|
+
"Rhapsody" => 57,
|
93
|
+
"Windows 2000" => 58,
|
94
|
+
"Dedicated" => 59,
|
95
|
+
"OS/390" => 60,
|
96
|
+
"VSE" => 61,
|
97
|
+
"TPF" => 62,
|
98
|
+
"Windows (R) Me" => 63,
|
99
|
+
"Caldera Open UNIX" => 64,
|
100
|
+
"OpenBSD" => 65,
|
101
|
+
"Not Applicable" => 66,
|
102
|
+
"Windows XP" => 67,
|
103
|
+
"z/OS" => 68,
|
104
|
+
"Microsoft Windows Server 2003" => 69,
|
105
|
+
"Microsoft Windows Server 2003 64-Bit" => 70,
|
106
|
+
"Windows XP 64-Bit" => 71,
|
107
|
+
"Windows XP Embedded" => 72,
|
108
|
+
"Windows Vista" => 73,
|
109
|
+
"Windows Vista 64-Bit" => 74,
|
110
|
+
"Windows Embedded for Point of Service" => 75,
|
111
|
+
"Microsoft Windows Server 2008" => 76,
|
112
|
+
"Microsoft Windows Server 2008 64-Bit" => 77,
|
113
|
+
"FreeBSD 64-Bit" => 78,
|
114
|
+
"RedHat Enterprise Linux" => 79,
|
115
|
+
"RedHat Enterprise Linux 64-Bit" => 80,
|
116
|
+
"Solaris 64-Bit" => 81,
|
117
|
+
"SUSE" => 82,
|
118
|
+
"SUSE 64-Bit" => 83,
|
119
|
+
"SLES" => 84,
|
120
|
+
"SLES 64-Bit" => 85,
|
121
|
+
"Novell OES" => 86,
|
122
|
+
"Novell Linux Desktop" => 87,
|
123
|
+
"Sun Java Desktop System" => 88,
|
124
|
+
"Mandriva" => 89,
|
125
|
+
"Mandriva 64-Bit" => 90,
|
126
|
+
"TurboLinux" => 91,
|
127
|
+
"TurboLinux 64-Bit" => 92,
|
128
|
+
"Ubuntu" => 93,
|
129
|
+
"Ubuntu 64-Bit" => 94,
|
130
|
+
"Debian" => 95,
|
131
|
+
"Debian 64-Bit" => 96,
|
132
|
+
"Linux 2.4.x" => 97,
|
133
|
+
"Linux 2.4.x 64-Bit" => 98,
|
134
|
+
"Linux 2.6.x" => 99,
|
135
|
+
"Linux 2.6.x 64-Bit" => 100,
|
136
|
+
"Linux 64-Bit" => 101,
|
137
|
+
"Other 64-Bit" => 102,
|
138
|
+
"Microsoft Windows Server 2008 R2" => 103,
|
139
|
+
"VMware ESXi" => 104,
|
140
|
+
"Microsoft Windows 7" => 105,
|
141
|
+
"CentOS 32-bit" => 106,
|
142
|
+
"CentOS 64-bit" => 107,
|
143
|
+
"Oracle Enterprise Linux 32-bit" => 108,
|
144
|
+
"Oracle Enterprise Linux 64-bit" => 109,
|
145
|
+
"eComStation 32-bitx" => 110
|
146
|
+
]
|
147
|
+
|
148
|
+
OS_ID_TABLE = Hash[
|
149
|
+
0 => "Unknown" ,
|
150
|
+
1 => "Other" ,
|
151
|
+
2 => "MACOS" ,
|
152
|
+
3 => "ATTUNIX" ,
|
153
|
+
4 => "DGUX" ,
|
154
|
+
5 => "DECNT" ,
|
155
|
+
6 => "Tru64 UNIX" ,
|
156
|
+
7 => "OpenVMS" ,
|
157
|
+
8 => "HPUX" ,
|
158
|
+
9 => "AIX" ,
|
159
|
+
10 => "MVS" ,
|
160
|
+
11 => "OS400" ,
|
161
|
+
12 => "OS/2" ,
|
162
|
+
13 => "JavaVM" ,
|
163
|
+
14 => "MSDOS" ,
|
164
|
+
15 => "WIN3x" ,
|
165
|
+
16 => "WIN95" ,
|
166
|
+
17 => "WIN98" ,
|
167
|
+
18 => "WINNT" ,
|
168
|
+
19 => "WINCE" ,
|
169
|
+
20 => "NCR3000" ,
|
170
|
+
21 => "NetWare" ,
|
171
|
+
22 => "OSF" ,
|
172
|
+
23 => "DC/OS" ,
|
173
|
+
24 => "Reliant UNIX" ,
|
174
|
+
25 => "SCO UnixWare" ,
|
175
|
+
26 => "SCO OpenServer" ,
|
176
|
+
27 => "Sequent" ,
|
177
|
+
28 => "IRIX" ,
|
178
|
+
29 => "Solaris" ,
|
179
|
+
30 => "SunOS" ,
|
180
|
+
31 => "U6000" ,
|
181
|
+
32 => "ASERIES" ,
|
182
|
+
33 => "HP NonStop OS" ,
|
183
|
+
34 => "HP NonStop OSS" ,
|
184
|
+
35 => "BS2000" ,
|
185
|
+
36 => "LINUX" ,
|
186
|
+
37 => "Lynx" ,
|
187
|
+
38 => "XENIX" ,
|
188
|
+
39 => "VM" ,
|
189
|
+
40 => "Interactive UNIX" ,
|
190
|
+
41 => "BSDUNIX" ,
|
191
|
+
42 => "FreeBSD" ,
|
192
|
+
43 => "NetBSD" ,
|
193
|
+
44 => "GNU Hurd" ,
|
194
|
+
45 => "OS9" ,
|
195
|
+
46 => "MACH Kernel" ,
|
196
|
+
47 => "Inferno" ,
|
197
|
+
48 => "QNX" ,
|
198
|
+
49 => "EPOC" ,
|
199
|
+
50 => "IxWorks" ,
|
200
|
+
51 => "VxWorks" ,
|
201
|
+
52 => "MiNT" ,
|
202
|
+
53 => "BeOS" ,
|
203
|
+
54 => "HP MPE" ,
|
204
|
+
55 => "NextStep" ,
|
205
|
+
56 => "PalmPilot" ,
|
206
|
+
57 => "Rhapsody" ,
|
207
|
+
58 => "Windows 2000" ,
|
208
|
+
59 => "Dedicated" ,
|
209
|
+
60 => "OS/390" ,
|
210
|
+
61 => "VSE" ,
|
211
|
+
62 => "TPF" ,
|
212
|
+
63 => "Windows (R) Me" ,
|
213
|
+
64 => "Caldera Open UNIX" ,
|
214
|
+
65 => "OpenBSD" ,
|
215
|
+
66 => "Not Applicable" ,
|
216
|
+
67 => "Windows XP" ,
|
217
|
+
68 => "z/OS" ,
|
218
|
+
69 => "Microsoft Windows Server 2003" ,
|
219
|
+
70 => "Microsoft Windows Server 2003 64-Bit" ,
|
220
|
+
71 => "Windows XP 64-Bit" ,
|
221
|
+
72 => "Windows XP Embedded" ,
|
222
|
+
73 => "Windows Vista" ,
|
223
|
+
74 => "Windows Vista 64-Bit" ,
|
224
|
+
75 => "Windows Embedded for Point of Service" ,
|
225
|
+
76 => "Microsoft Windows Server 2008" ,
|
226
|
+
77 => "Microsoft Windows Server 2008 64-Bit" ,
|
227
|
+
78 => "FreeBSD 64-Bit" ,
|
228
|
+
79 => "RedHat Enterprise Linux" ,
|
229
|
+
80 => "RedHat Enterprise Linux 64-Bit" ,
|
230
|
+
81 => "Solaris 64-Bit" ,
|
231
|
+
82 => "SUSE" ,
|
232
|
+
83 => "SUSE 64-Bit" ,
|
233
|
+
84 => "SLES" ,
|
234
|
+
85 => "SLES 64-Bit" ,
|
235
|
+
86 => "Novell OES" ,
|
236
|
+
87 => "Novell Linux Desktop" ,
|
237
|
+
88 => "Sun Java Desktop System" ,
|
238
|
+
89 => "Mandriva" ,
|
239
|
+
90 => "Mandriva 64-Bit" ,
|
240
|
+
91 => "TurboLinux" ,
|
241
|
+
92 => "TurboLinux 64-Bit" ,
|
242
|
+
93 => "Ubuntu" ,
|
243
|
+
94 => "Ubuntu 64-Bit" ,
|
244
|
+
95 => "Debian" ,
|
245
|
+
96 => "Debian 64-Bit" ,
|
246
|
+
97 => "Linux 2.4.x" ,
|
247
|
+
98 => "Linux 2.4.x 64-Bit" ,
|
248
|
+
99 => "Linux 2.6.x" ,
|
249
|
+
100 => "Linux 2.6.x 64-Bit" ,
|
250
|
+
101 => "Linux 64-Bit" ,
|
251
|
+
102 => "Other 64-Bit" ,
|
252
|
+
103 => "Microsoft Windows Server 2008 R2" ,
|
253
|
+
104 => "VMware ESXi" ,
|
254
|
+
105 => "Microsoft Windows 7" ,
|
255
|
+
106 => "CentOS 32-bit" ,
|
256
|
+
107 => "CentOS 64-bit" ,
|
257
|
+
108 => "Oracle Enterprise Linux 32-bit" ,
|
258
|
+
109 => "Oracle Enterprise Linux 64-bit" ,
|
259
|
+
110 => "eComStation 32-bitx"
|
260
|
+
]
|
261
|
+
|
data/lib/ovfparse/vmpackage.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
1
3
|
class VmPackage
|
2
4
|
@url
|
5
|
+
@base_path
|
3
6
|
@name
|
4
7
|
@version
|
5
8
|
@protocol
|
@@ -10,19 +13,25 @@ class VmPackage
|
|
10
13
|
OVA = 0
|
11
14
|
OVF = 1
|
12
15
|
ISO = 2
|
16
|
+
|
17
|
+
@references
|
18
|
+
@diskSection
|
19
|
+
@networkSection
|
20
|
+
@virtualSystem
|
13
21
|
|
14
22
|
@type = nil
|
15
|
-
|
23
|
+
|
24
|
+
DEBUG_MODE = false
|
16
25
|
|
17
26
|
# List of attributes in an OVF product that we will extract / set
|
18
27
|
PRODUCT_ATTRIBUTES = [ {'full_name' => 'ovf:instance', 'node_ref' => 'instance', 'attribute_ref' => 'instance'},
|
19
28
|
{'full_name' => 'ovf:class', 'node_ref' => 'class', 'attribute_ref' => 'product_class'} ]
|
20
29
|
|
21
30
|
# List of elements in an OVF product that we will extract / set
|
22
|
-
PRODUCT_ELEMENTS = [ {'full_name' => '
|
23
|
-
{'full_name' => '
|
24
|
-
{'full_name' => '
|
25
|
-
{'full_name' => '
|
31
|
+
PRODUCT_ELEMENTS = [ {'full_name' => 'Info', 'node_ref' => 'Info', 'element_ref' => 'description', 'required' => false},
|
32
|
+
{'full_name' => 'Product', 'node_ref' => 'Product', 'element_ref' => 'name', 'required' => false},
|
33
|
+
{'full_name' => 'Vendor', 'node_ref' => 'Vendor', 'element_ref' => 'vendor', 'required' => false},
|
34
|
+
{'full_name' => 'Version', 'node_ref' => 'Version', 'element_ref' => 'version', 'required' => false} ]
|
26
35
|
|
27
36
|
# List of attributes in an OVF property that we will extract / set
|
28
37
|
PROPERTY_ATTRIBUTES = [ {'full_name' => 'ovf:value', 'node_ref' => 'value', 'attribute_ref' => 'value'},
|
@@ -35,15 +44,15 @@ class VmPackage
|
|
35
44
|
{'full_name' => 'cops:uuid', 'node_ref' => 'uuid', 'attribute_ref' => 'uuid'} ] # @todo refactor to cops extension module
|
36
45
|
|
37
46
|
# List of elements in an OVF property that we will extract / set
|
38
|
-
PROPERTY_ELEMENTS = [ {'full_name' => '
|
39
|
-
{'full_name' => '
|
40
|
-
{'full_name' => '
|
41
|
-
{'full_name' => '
|
47
|
+
PROPERTY_ELEMENTS = [ {'full_name' => 'Label', 'node_ref' => 'Label', 'element_ref' => 'name', 'required' => false},
|
48
|
+
{'full_name' => 'Description', 'node_ref' => 'Description', 'element_ref' => 'description', 'required' => false},
|
49
|
+
{'full_name' => 'Example', 'node_ref' => 'cops:Example', 'element_ref' => 'example', 'required' => true}, # @todo refactor to cops extension module
|
50
|
+
{'full_name' => 'NoneType', 'node_ref' => 'cops:NoneType', 'element_ref' => 'nonetype', 'required' => true} ] # @todo refactor to cops extension module
|
42
51
|
|
43
52
|
OVF_NAMESPACE = {'ovf' => 'http://schemas.dmtf.org/ovf/envelope/1'}
|
44
53
|
|
45
54
|
|
46
|
-
attr_accessor :url, :name, :version, :state, :protocol, :size, :xml
|
55
|
+
attr_accessor :url, :base_path, :name, :version, :state, :protocol, :size, :xml, :references, :diskSection, :networkSection, :virtualSystem
|
47
56
|
|
48
57
|
|
49
58
|
def initialize
|
@@ -63,6 +72,10 @@ class VmPackage
|
|
63
72
|
end
|
64
73
|
|
65
74
|
def initialize(uri)
|
75
|
+
if (URI::HTTP==uri.class) then
|
76
|
+
uri = uri.to_s
|
77
|
+
end
|
78
|
+
|
66
79
|
(@protocol, @url) = uri.split(":", 2) unless !uri
|
67
80
|
@url.sub!(/^\/{0,2}/, '')
|
68
81
|
@protocol.downcase
|
@@ -75,7 +88,6 @@ class VmPackage
|
|
75
88
|
@url.sub!(/^\/{0,2}/, '')
|
76
89
|
@protocol.downcase
|
77
90
|
@url.downcase
|
78
|
-
|
79
91
|
if @protocol=='ftp'
|
80
92
|
FtpVmPackage.new(uri)
|
81
93
|
elsif @protocol=='http'
|
@@ -105,13 +117,52 @@ class VmPackage
|
|
105
117
|
|
106
118
|
def fetch
|
107
119
|
end
|
120
|
+
|
121
|
+
|
122
|
+
# Caches all of the base elements inside Envelope for fast access
|
123
|
+
def loadElementRefs
|
124
|
+
children = @xml.root.children
|
125
|
+
|
126
|
+
@references = children[0]
|
127
|
+
if(@references.name != 'References')
|
128
|
+
@references = getChildByName(xml.root, 'References')
|
129
|
+
end
|
130
|
+
|
131
|
+
@diskSection = children[1]
|
132
|
+
if(@diskSection.name != 'DiskSection')
|
133
|
+
@diskSection = getChildByName(xml.root, 'DiskSection')
|
134
|
+
end
|
135
|
+
|
136
|
+
@networkSection = children[2]
|
137
|
+
if(@networkSection.name != 'NetworkSection')
|
138
|
+
@networkSection = getChildByName(xml.root, 'NetworkSection')
|
139
|
+
end
|
140
|
+
|
141
|
+
@virtualSystem = children[3]
|
142
|
+
if(@virtualSystem.name != 'VirtualSystem')
|
143
|
+
@virtualSystem = getChildByName(xml.root, 'VirtualSystem')
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
108
147
|
|
148
|
+
# Returns the first child node of the passed node whose name matches the passed name.
|
149
|
+
def getChildByName(node, childName)
|
150
|
+
return node.children.detect{ |element| element.name == childName}
|
151
|
+
end
|
152
|
+
|
153
|
+
# Returns every child node of the passed node whose name matches the passed name.
|
154
|
+
def getChildrenByName(node, childName)
|
155
|
+
return node.children.select{ |element| element.name == childName}
|
156
|
+
end
|
157
|
+
|
109
158
|
def referenced_file(element)
|
110
159
|
@xml.xpath("//ovf:References/ovf:File[@ovf:id='#{element['fileRef']}']", OVF_NAMESPACE).first
|
111
160
|
end
|
112
161
|
|
113
162
|
def method_missing(method)
|
114
|
-
|
163
|
+
if DEBUG_MODE
|
164
|
+
puts "WARNING: NoSuchMethod Error: " + method.to_s + " ...trying XPath query \n"
|
165
|
+
end
|
115
166
|
|
116
167
|
# try with namespace
|
117
168
|
data = @xml.xpath("//ovf:" + method.to_s)
|
@@ -139,7 +190,7 @@ class VmPackage
|
|
139
190
|
end
|
140
191
|
|
141
192
|
def checkschema(schema)
|
142
|
-
xsd = Nokogiri::XML::Schema(
|
193
|
+
xsd = Nokogiri::XML::Schema(schema)
|
143
194
|
response = ""
|
144
195
|
|
145
196
|
isValid = true
|
@@ -152,18 +203,23 @@ class VmPackage
|
|
152
203
|
end
|
153
204
|
|
154
205
|
def getVmName
|
155
|
-
return
|
206
|
+
return virtualSystem['id']
|
156
207
|
end
|
157
208
|
|
158
209
|
def getVmDescription
|
159
|
-
descNode =
|
210
|
+
descNode = getChildByName(virtualSystem, 'Info')
|
160
211
|
return descNode.nil? ? '' : descNode.content
|
161
212
|
end
|
162
213
|
|
163
214
|
def getVmOS_ID
|
164
|
-
return
|
215
|
+
return getChildByName(virtualSystem, 'OperatingSystemSection')['id']
|
165
216
|
end
|
166
217
|
|
218
|
+
def getVmOS
|
219
|
+
return OS_ID_TABLE[getVmOS_ID.to_i]
|
220
|
+
end
|
221
|
+
|
222
|
+
|
167
223
|
# note this is not part of the OVF spec. Specific users could overwrite this method to
|
168
224
|
# store/retrieve patch level in the description field, for example.
|
169
225
|
def getVmPatchLevel
|
@@ -186,11 +242,11 @@ class VmPackage
|
|
186
242
|
def getVmDisks
|
187
243
|
disks = Array.new
|
188
244
|
filenames = Hash.new
|
189
|
-
|
245
|
+
getChildrenByName(references, 'File').each { |node|
|
190
246
|
filenames[node['id']] = node['href']
|
191
247
|
}
|
192
248
|
|
193
|
-
|
249
|
+
getChildrenByName(diskSection, 'Disk').each { |node|
|
194
250
|
disks.push({ 'name' => node['diskId'], 'location' => filenames[node['fileRef']], 'size' => node['capacity'] })
|
195
251
|
}
|
196
252
|
|
@@ -199,8 +255,8 @@ class VmPackage
|
|
199
255
|
|
200
256
|
def getVmNetworks
|
201
257
|
networks = Array.new
|
202
|
-
|
203
|
-
descriptionNode = node
|
258
|
+
getChildrenByName(networkSection, 'Network').each { |node|
|
259
|
+
descriptionNode = getChildByName(node, 'Description')
|
204
260
|
text = descriptionNode.nil? ? '' : descriptionNode.text
|
205
261
|
networks.push({'location' => node['name'], 'notes' => text })
|
206
262
|
}
|
@@ -217,25 +273,25 @@ class VmPackage
|
|
217
273
|
end
|
218
274
|
|
219
275
|
def getVirtualQuantity(resource)
|
220
|
-
|
276
|
+
getChildrenByName(getChildByName(virtualSystem, 'VirtualHardwareSection'), 'Item').each{ |node|
|
221
277
|
resourceType = node.xpath('rasd:ResourceType')[0].text
|
222
278
|
resourceType == resource.to_s ? (return node.xpath('rasd:VirtualQuantity')[0].text) : next
|
223
279
|
}
|
224
280
|
end
|
225
281
|
|
226
282
|
def setVmName(newValue)
|
227
|
-
|
228
|
-
nameNode =
|
229
|
-
|
283
|
+
virtualSystem['ovf:id'] = newValue
|
284
|
+
nameNode = getChildByName(virtualSystem, 'Name') ||
|
285
|
+
getChildByName(virtualSystem, 'Info').add_next_sibling(xml.create_element('Name', {}))
|
230
286
|
nameNode.content = newValue
|
231
287
|
end
|
232
288
|
|
233
289
|
def setVmDescription(newValue)
|
234
|
-
|
290
|
+
getChildByName(virtualSystem, 'Info').content = newValue
|
235
291
|
end
|
236
292
|
|
237
293
|
def setVmOS_ID(newValue)
|
238
|
-
|
294
|
+
getChildByName(virtualSystem, 'OperatingSystemSection')['ovf:id'] = newValue.to_s
|
239
295
|
end
|
240
296
|
|
241
297
|
|
@@ -248,22 +304,21 @@ class VmPackage
|
|
248
304
|
end
|
249
305
|
|
250
306
|
def setVirtualQuantity(resource, newValue)
|
251
|
-
|
307
|
+
getChildrenByName(getChildByName(virtualSystem, 'VirtualHardwareSection'), 'Item').each { |node|
|
252
308
|
resourceType = node.xpath('rasd:ResourceType')[0].text
|
253
309
|
resourceType == resource.to_s ? (node.xpath('rasd:VirtualQuantity')[0].content = newValue) : next
|
254
310
|
}
|
255
311
|
end
|
256
312
|
|
257
313
|
def setVmNetworks(networks)
|
258
|
-
|
259
|
-
|
260
|
-
|
314
|
+
networkNodes = getChildrenByName(networkSection, 'Network')
|
315
|
+
|
261
316
|
networkNodes.each { |node|
|
262
317
|
updated_network = networks.detect { |network| network.location == node['name'] }
|
263
318
|
if(updated_network.nil?)
|
264
319
|
node.unlink
|
265
320
|
else
|
266
|
-
descriptionNode = node
|
321
|
+
descriptionNode = getChildByName(node, 'Description')
|
267
322
|
if((updated_network.notes == '' || updated_network.notes.nil?) && !descriptionNode.nil?)
|
268
323
|
descriptionNode.unlink
|
269
324
|
elsif(updated_network.notes != '' && !updated_network.notes.nil?)
|
@@ -284,14 +339,11 @@ class VmPackage
|
|
284
339
|
end
|
285
340
|
|
286
341
|
def setVmDisks(disks)
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
diskSection = xml.xpath('ovf:Envelope/ovf:DiskSection')[0]
|
291
|
-
diskNodes = diskSection.xpath('ovf:Disk')
|
342
|
+
fileNodes = getChildrenByName(references, 'File')
|
343
|
+
diskNodes = getChildrenByName(diskSection, 'Disk')
|
292
344
|
|
293
345
|
icons = Array.new
|
294
|
-
|
346
|
+
getChildrenByName(getChildByName(virtualSystem, 'ProductSection'), 'Icon').each { |node|
|
295
347
|
icons.push(node['fileRef'])
|
296
348
|
}
|
297
349
|
|
@@ -317,7 +369,7 @@ class VmPackage
|
|
317
369
|
disks.each { |disk|
|
318
370
|
if( (fileNodes.detect { |node| disk.location == node['href'] }).nil?)
|
319
371
|
diskSection.add_child(xml.create_element('Disk', {'ovf:capacity' => disk.size.to_s, 'ovf:capacityAllocationUnits' => "byte * 2^30", 'ovf:diskId' => disk.name, 'ovf:fileRef' => disk.name + '_disk', 'ovf:format' => "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized" }))
|
320
|
-
|
372
|
+
references.add_child(xml.create_element('File', {'ovf:href' => disk.location, 'ovf:id' => disk.name + '_disk'}))
|
321
373
|
end
|
322
374
|
}
|
323
375
|
end
|
@@ -344,17 +396,17 @@ class VmPackage
|
|
344
396
|
end
|
345
397
|
|
346
398
|
def setProductIcon(new_icon, productNode)
|
347
|
-
iconNode = productNode
|
399
|
+
iconNode = getChildByName(productNode, 'Icon')
|
348
400
|
if((new_icon == '' || new_icon.nil?) && !iconNode.nil?)
|
349
|
-
(
|
401
|
+
getChildrenByName(references, 'File').detect { |fileNode| fileNode['id'] == iconNode['fileRef']}.unlink
|
350
402
|
iconNode.unlink
|
351
403
|
elsif(new_icon != '' && !new_icon.nil?)
|
352
404
|
if(iconNode.nil?)
|
353
405
|
productNode.add_child(xml.create_element('Icon', {'ovf:fileRef' => productNode['class'] + '_icon'}))
|
354
|
-
|
406
|
+
references.add_child(xml.create_element('File', {'ovf:id' => productNode['class'] + '_icon', 'ovf:href' => new_icon}))
|
355
407
|
else
|
356
408
|
productNode.add_child(iconNode)
|
357
|
-
(
|
409
|
+
getChildrenByName(references, 'File').detect { |fileNode| fileNode['id'] == iconNode['fileRef']}['ovf:href'] = new_icon
|
358
410
|
end
|
359
411
|
end
|
360
412
|
end
|
@@ -430,7 +482,11 @@ class VmPackage
|
|
430
482
|
node = Nokogiri::XML::Comment.new(xml.doc, ' skeleton framework constructed by OVFparse ')
|
431
483
|
xml.doc.children[0].add_previous_sibling(node)
|
432
484
|
end
|
433
|
-
|
485
|
+
|
486
|
+
newPackage = NewVmPackage.new
|
487
|
+
newPackage.xml = builder.doc
|
488
|
+
newPackage.loadElementRefs
|
489
|
+
return newPackage
|
434
490
|
end
|
435
491
|
|
436
492
|
def write_xml(file)
|
@@ -452,19 +508,12 @@ end
|
|
452
508
|
class HttpVmPackage < VmPackage
|
453
509
|
def fetch
|
454
510
|
url = URI.parse(URI.escape(self.uri))
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
file.write(resp.body)
|
459
|
-
}
|
460
|
-
}
|
461
|
-
|
462
|
-
@xml = Nokogiri::XML(File.open(@name)) do |config|
|
463
|
-
config.strict.noent
|
464
|
-
config.strict
|
511
|
+
|
512
|
+
@xml = Nokogiri::XML(open(url)) do |config|
|
513
|
+
config.noblanks.strict.noent
|
465
514
|
end
|
466
515
|
|
467
|
-
|
516
|
+
loadElementRefs
|
468
517
|
end
|
469
518
|
end
|
470
519
|
|
@@ -486,6 +535,7 @@ class HttpsVmPackage < VmPackage
|
|
486
535
|
end
|
487
536
|
|
488
537
|
File.unlink(@name)
|
538
|
+
loadElementRefs
|
489
539
|
end
|
490
540
|
|
491
541
|
|
@@ -505,6 +555,7 @@ class FtpVmPackage < VmPackage
|
|
505
555
|
end
|
506
556
|
|
507
557
|
File.unlink(@name)
|
558
|
+
loadElementRefs
|
508
559
|
end
|
509
560
|
end
|
510
561
|
|
@@ -513,6 +564,12 @@ class FileVmPackage < VmPackage
|
|
513
564
|
@xml = Nokogiri::XML(File.open(self.url)) do |config|
|
514
565
|
config.noblanks.strict.noent
|
515
566
|
end
|
567
|
+
loadElementRefs
|
568
|
+
end
|
569
|
+
end
|
570
|
+
|
571
|
+
class NewVmPackage < VmPackage
|
572
|
+
def initialize
|
516
573
|
end
|
517
574
|
end
|
518
575
|
|
@@ -19,13 +19,15 @@ def initialize(uri)
|
|
19
19
|
@url.downcase
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.create
|
22
|
+
def self.create(uri, managed)
|
23
23
|
(@protocol, @url) = uri.split(":", 2) unless !uri
|
24
24
|
@url.sub!(/^\/{0,2}/, '')
|
25
25
|
@protocol.downcase
|
26
26
|
@url.downcase
|
27
27
|
|
28
|
-
if
|
28
|
+
if(managed)
|
29
|
+
MarketplaceRepository.new(uri)
|
30
|
+
elsif @protocol=='ftp'
|
29
31
|
FtpVmRepository.new(uri)
|
30
32
|
elsif @protocol=='http'
|
31
33
|
HttpVmRepository.new(uri)
|
@@ -69,8 +71,10 @@ end
|
|
69
71
|
packages = Array.new
|
70
72
|
package_list.each { |p|
|
71
73
|
package = VmPackage.create(self.uri + "/" + p)
|
74
|
+
package.base_path = self.uri + "/"
|
72
75
|
package.name = p
|
73
|
-
|
76
|
+
# @todo remove this, or fix it. Supposed to be handled with a COPS mix-in
|
77
|
+
# package.state = VmPackage::UNKNOWN
|
74
78
|
packages.push(package)
|
75
79
|
}
|
76
80
|
|
data/lib/ovfparse.rb
CHANGED
@@ -8,9 +8,11 @@ path = File.expand_path(File.dirname(__FILE__))
|
|
8
8
|
|
9
9
|
require path + '/ovfparse/vmrepository'
|
10
10
|
require path + '/ovfparse/vmpackage'
|
11
|
+
require path + '/ovfparse/os_id_table'
|
11
12
|
require path + '/ovfparse/esx4_vmrepository'
|
12
13
|
require path + '/ovfparse/file_vmrepository'
|
13
14
|
require path + '/ovfparse/ftp_vmrepository'
|
14
15
|
require path + '/ovfparse/http_vmrepository'
|
15
16
|
require path + '/ovfparse/https_vmrepository'
|
16
17
|
require path + '/ovfparse/vc4_vmrepository'
|
18
|
+
require path + '/ovfparse/marketplace_repository'
|
data/lib/test.rb
CHANGED
@@ -40,7 +40,7 @@ puts "\n\n****************************\n"
|
|
40
40
|
#
|
41
41
|
# package = VmPackage.create("file://ambrosia/public/vmlib/someOVF.ovf")
|
42
42
|
# package = VmPackage.create("http://cops-af-lib.mitre.org//Base OS Package (jeos)-Ubuntu-20090917.ovf")
|
43
|
-
# package.
|
43
|
+
# package.fetch
|
44
44
|
# puts package.xml
|
45
45
|
# puts package.ProductSection
|
46
46
|
#
|
@@ -52,7 +52,7 @@ puts "\n\n****************************\n"
|
|
52
52
|
# puts "uri: " + vmRepo.uri + "\n"
|
53
53
|
# packages = vmRepo.fetch
|
54
54
|
# ovfTest = packages[1]
|
55
|
-
# ovfTest.
|
55
|
+
# ovfTest.fetch
|
56
56
|
# puts ovfTest.xml
|
57
57
|
#
|
58
58
|
# uri = "ftp://localhost/repo"
|
@@ -63,7 +63,7 @@ puts "\n\n****************************\n"
|
|
63
63
|
# puts "uri: " + vmRepo.uri + "\n"
|
64
64
|
# packages = vmRepo.fetch
|
65
65
|
# ovfTest = packages[1]
|
66
|
-
# ovfTest.
|
66
|
+
# ovfTest.fetch
|
67
67
|
|
68
68
|
|
69
69
|
#
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ovfparse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 161
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 95
|
10
|
+
version: 0.0.95
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jim Barkley
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-18 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -49,6 +49,8 @@ files:
|
|
49
49
|
- lib/ovfparse/ftp_vmrepository.rb
|
50
50
|
- lib/ovfparse/http_vmrepository.rb
|
51
51
|
- lib/ovfparse/https_vmrepository.rb
|
52
|
+
- lib/ovfparse/marketplace_repository.rb
|
53
|
+
- lib/ovfparse/os_id_table.rb
|
52
54
|
- lib/ovfparse/vc4_vmrepository.rb
|
53
55
|
- lib/ovfparse/vc_repository.rb
|
54
56
|
- lib/ovfparse/vmpackage.rb
|