mkuzmin-rbvmomi 1.8.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +6 -0
  3. data/LICENSE +19 -0
  4. data/README.rdoc +78 -0
  5. data/Rakefile +45 -0
  6. data/VERSION +1 -0
  7. data/bin/rbvmomish +138 -0
  8. data/devel/analyze-vim-declarations.rb +213 -0
  9. data/devel/analyze-xml.rb +46 -0
  10. data/devel/benchmark.rb +117 -0
  11. data/devel/collisions.rb +18 -0
  12. data/devel/merge-internal-vmodl.rb +59 -0
  13. data/devel/merge-manual-vmodl.rb +32 -0
  14. data/examples/annotate.rb +54 -0
  15. data/examples/cached_ovf_deploy.rb +120 -0
  16. data/examples/clone_vm.rb +84 -0
  17. data/examples/create_vm-1.9.rb +93 -0
  18. data/examples/create_vm.rb +93 -0
  19. data/examples/extraConfig.rb +54 -0
  20. data/examples/lease_tool.rb +102 -0
  21. data/examples/logbundle.rb +63 -0
  22. data/examples/logtail.rb +60 -0
  23. data/examples/nfs_datastore.rb +95 -0
  24. data/examples/power.rb +59 -0
  25. data/examples/readme-1.rb +35 -0
  26. data/examples/readme-2.rb +51 -0
  27. data/examples/run.sh +41 -0
  28. data/examples/screenshot.rb +48 -0
  29. data/examples/vdf.rb +81 -0
  30. data/examples/vm_drs_behavior.rb +76 -0
  31. data/lib/rbvmomi.rb +12 -0
  32. data/lib/rbvmomi/basic_types.rb +375 -0
  33. data/lib/rbvmomi/connection.rb +270 -0
  34. data/lib/rbvmomi/deserialization.rb +248 -0
  35. data/lib/rbvmomi/fault.rb +17 -0
  36. data/lib/rbvmomi/pbm.rb +66 -0
  37. data/lib/rbvmomi/sms.rb +61 -0
  38. data/lib/rbvmomi/sms/SmsStorageManager.rb +7 -0
  39. data/lib/rbvmomi/trivial_soap.rb +114 -0
  40. data/lib/rbvmomi/trollop.rb +70 -0
  41. data/lib/rbvmomi/type_loader.rb +136 -0
  42. data/lib/rbvmomi/utils/admission_control.rb +398 -0
  43. data/lib/rbvmomi/utils/deploy.rb +314 -0
  44. data/lib/rbvmomi/utils/leases.rb +142 -0
  45. data/lib/rbvmomi/utils/perfdump.rb +628 -0
  46. data/lib/rbvmomi/vim.rb +128 -0
  47. data/lib/rbvmomi/vim/ComputeResource.rb +51 -0
  48. data/lib/rbvmomi/vim/Datacenter.rb +17 -0
  49. data/lib/rbvmomi/vim/Datastore.rb +68 -0
  50. data/lib/rbvmomi/vim/DynamicTypeMgrAllTypeInfo.rb +75 -0
  51. data/lib/rbvmomi/vim/DynamicTypeMgrDataTypeInfo.rb +20 -0
  52. data/lib/rbvmomi/vim/DynamicTypeMgrManagedTypeInfo.rb +46 -0
  53. data/lib/rbvmomi/vim/Folder.rb +207 -0
  54. data/lib/rbvmomi/vim/HostSystem.rb +174 -0
  55. data/lib/rbvmomi/vim/ManagedEntity.rb +57 -0
  56. data/lib/rbvmomi/vim/ManagedObject.rb +60 -0
  57. data/lib/rbvmomi/vim/ObjectContent.rb +23 -0
  58. data/lib/rbvmomi/vim/ObjectUpdate.rb +23 -0
  59. data/lib/rbvmomi/vim/OvfManager.rb +200 -0
  60. data/lib/rbvmomi/vim/PerfCounterInfo.rb +26 -0
  61. data/lib/rbvmomi/vim/PerformanceManager.rb +110 -0
  62. data/lib/rbvmomi/vim/PropertyCollector.rb +25 -0
  63. data/lib/rbvmomi/vim/ReflectManagedMethodExecuter.rb +30 -0
  64. data/lib/rbvmomi/vim/ResourcePool.rb +55 -0
  65. data/lib/rbvmomi/vim/ServiceInstance.rb +55 -0
  66. data/lib/rbvmomi/vim/Task.rb +65 -0
  67. data/lib/rbvmomi/vim/VirtualMachine.rb +74 -0
  68. data/test/test_deserialization.rb +383 -0
  69. data/test/test_emit_request.rb +128 -0
  70. data/test/test_exceptions.rb +14 -0
  71. data/test/test_helper.rb +14 -0
  72. data/test/test_misc.rb +24 -0
  73. data/test/test_parse_response.rb +69 -0
  74. data/test/test_serialization.rb +311 -0
  75. data/vmodl.db +0 -0
  76. metadata +163 -0
@@ -0,0 +1,383 @@
1
+ require 'test_helper'
2
+
3
+ class DeserializationTest < Test::Unit::TestCase
4
+ def setup
5
+ conn = VIM.new(:ns => 'urn:vim25', :rev => '4.0')
6
+ @deserializer = RbVmomi::Deserializer.new conn
7
+ end
8
+
9
+ def check str, expected, type
10
+ got = @deserializer.deserialize Nokogiri(str).root, type
11
+ assert_equal expected, got
12
+ end
13
+
14
+ def test_moref
15
+ check <<-EOS, VIM.Folder(nil, 'ha-folder-root'), 'Folder'
16
+ <root type="Folder">ha-folder-root</root>
17
+ EOS
18
+
19
+ check <<-EOS, VIM.Datacenter(nil, 'ha-datacenter'), 'ManagedObjectReference'
20
+ <ManagedObjectReference type="Datacenter" xsi:type="ManagedObjectReference">ha-datacenter</ManagedObjectReference>
21
+ EOS
22
+ end
23
+
24
+ def test_dataobject
25
+ obj = VIM.DatastoreSummary(
26
+ :capacity => 1000,
27
+ :accessible => true,
28
+ :datastore => VIM.Datastore(nil, "foo"),
29
+ :freeSpace => 31,
30
+ :multipleHostAccess => false,
31
+ :name => "baz",
32
+ :type => "VMFS",
33
+ :url => "http://foo/",
34
+ :dynamicProperty => []
35
+ )
36
+
37
+ check <<-EOS, obj, 'DatastoreSummary'
38
+ <root>
39
+ <datastore type="Datastore">foo</datastore>
40
+ <name>baz</name>
41
+ <url>http://foo/</url>
42
+ <capacity>1000</capacity>
43
+ <freeSpace>31</freeSpace>
44
+ <accessible>1</accessible>
45
+ <multipleHostAccess>false</multipleHostAccess>
46
+ <type>VMFS</type>
47
+ </root>
48
+ EOS
49
+ end
50
+
51
+ def test_enum
52
+ check <<-EOS, 'add', 'ConfigSpecOperation'
53
+ <root>add</root>
54
+ EOS
55
+ end
56
+
57
+ def test_array
58
+ obj = VIM.ObjectContent(
59
+ :obj => VIM.Folder(nil, 'ha-folder-root'),
60
+ :dynamicProperty => [],
61
+ :missingSet => [],
62
+ :propSet => [
63
+ VIM.DynamicProperty(
64
+ :name => 'childEntity',
65
+ :val => [
66
+ VIM.Datacenter(nil, 'ha-datacenter')
67
+ ]
68
+ )
69
+ ]
70
+ )
71
+
72
+ check <<-EOS, obj, 'ObjectContent'
73
+ <root xmlns:xsi="#{VIM::NS_XSI}">
74
+ <obj type="Folder">ha-folder-root</obj>
75
+ <propSet>
76
+ <name>childEntity</name>
77
+ <val xsi:type="ArrayOfManagedObjectReference">
78
+ <ManagedObjectReference type="Datacenter" xsi:type="ManagedObjectReference">ha-datacenter</ManagedObjectReference>
79
+ </val>
80
+ </propSet>
81
+ </root>
82
+ EOS
83
+ end
84
+
85
+ def test_array2
86
+ obj = VIM.DVPortStatus(
87
+ :dynamicProperty => [],
88
+ :linkUp => true,
89
+ :blocked => false,
90
+ :vlanIds => [
91
+ VIM::NumericRange(:dynamicProperty => [], :start => 5, :end => 7),
92
+ VIM::NumericRange(:dynamicProperty => [], :start => 10, :end => 20),
93
+ ],
94
+ :vmDirectPathGen2InactiveReasonNetwork => [],
95
+ :vmDirectPathGen2InactiveReasonOther => []
96
+ )
97
+
98
+ check <<-EOS, obj, 'DVPortStatus'
99
+ <root>
100
+ <linkUp>1</linkUp>
101
+ <blocked>false</blocked>
102
+ <vlanIds>
103
+ <start>5</start>
104
+ <end>7</end>
105
+ </vlanIds>
106
+ <vlanIds>
107
+ <start>10</start>
108
+ <end>20</end>
109
+ </vlanIds>
110
+ </root>
111
+ EOS
112
+ end
113
+
114
+ def test_empty_array
115
+ obj = VIM.DVPortStatus(
116
+ :dynamicProperty => [],
117
+ :linkUp => true,
118
+ :blocked => false,
119
+ :vlanIds => [],
120
+ :vmDirectPathGen2InactiveReasonNetwork => [],
121
+ :vmDirectPathGen2InactiveReasonOther => []
122
+ )
123
+
124
+ check <<-EOS, obj, 'DVPortStatus'
125
+ <root>
126
+ <linkUp>1</linkUp>
127
+ <blocked>false</blocked>
128
+ </root>
129
+ EOS
130
+ end
131
+
132
+ def test_fault
133
+ obj = VIM.LocalizedMethodFault(
134
+ :localizedMessage => "The attempted operation cannot be performed in the current state (Powered off).",
135
+ :fault => VIM.InvalidPowerState(
136
+ :requestedState => 'poweredOn',
137
+ :existingState => 'poweredOff',
138
+ :faultMessage => []
139
+ )
140
+ )
141
+
142
+ check <<-EOS, obj, "LocalizedMethodFault"
143
+ <error xmlns:xsi="#{VIM::NS_XSI}">
144
+ <fault xsi:type="InvalidPowerState">
145
+ <requestedState>poweredOn</requestedState>
146
+ <existingState>poweredOff</existingState>
147
+ </fault>
148
+ <localizedMessage>The attempted operation cannot be performed in the current state (Powered off).</localizedMessage>
149
+ </error>
150
+ EOS
151
+ end
152
+
153
+ def test_wait_for_updates
154
+ obj = VIM.UpdateSet(
155
+ :version => '7',
156
+ :dynamicProperty => [],
157
+ :filterSet => [
158
+ VIM.PropertyFilterUpdate(
159
+ :dynamicProperty => [],
160
+ :filter => VIM.PropertyFilter(nil, "session[528BA5EB-335B-4AF6-B49C-6160CF5E8D5B]71E3AC7E-7927-4D9E-8BC3-522769F22DAF"),
161
+ :missingSet => [],
162
+ :objectSet => [
163
+ VIM.ObjectUpdate(
164
+ :dynamicProperty => [],
165
+ :kind => 'enter',
166
+ :obj => VIM.VirtualMachine(nil, 'vm-1106'),
167
+ :missingSet => [],
168
+ :changeSet => [
169
+ VIM.PropertyChange(
170
+ :dynamicProperty => [],
171
+ :name => 'runtime.powerState',
172
+ :op => 'assign',
173
+ :val => 'poweredOn'
174
+ )
175
+ ]
176
+ )
177
+ ]
178
+ )
179
+ ]
180
+ )
181
+
182
+ check <<-EOS, obj, "UpdateSet"
183
+ <returnval xmlns:xsi="#{VIM::NS_XSI}">
184
+ <version>7</version>
185
+ <filterSet>
186
+ <filter type="PropertyFilter">session[528BA5EB-335B-4AF6-B49C-6160CF5E8D5B]71E3AC7E-7927-4D9E-8BC3-522769F22DAF</filter>
187
+ <objectSet>
188
+ <kind>enter</kind>
189
+ <obj type="VirtualMachine">vm-1106</obj>
190
+ <changeSet>
191
+ <name>runtime.powerState</name>
192
+ <op>assign</op>
193
+ <val xsi:type="VirtualMachinePowerState">poweredOn</val>
194
+ </changeSet>
195
+ </objectSet>
196
+ </filterSet>
197
+ </returnval>
198
+ EOS
199
+ end
200
+
201
+ def test_binary
202
+ obj = "\x00foo\x01bar\x02baz"
203
+ check <<-EOS, obj, 'xsd:base64Binary'
204
+ <root>AGZvbwFiYXICYmF6</root>
205
+ EOS
206
+ end
207
+
208
+ def test_hba
209
+ obj = VIM::HostBlockHba(
210
+ :dynamicProperty => [],
211
+ :key => 'key-vim.host.BlockHba-vmhba0',
212
+ :device => 'vmhba0',
213
+ :bus => 0,
214
+ :status => 'unknown',
215
+ :model => 'Virtual Machine Chipset',
216
+ :driver => 'ata_piix',
217
+ :pci => '00:07.1')
218
+
219
+ check <<-EOS, obj, "HostBlockHba"
220
+ <hostBusAdapter xsi:type="HostBlockHba">
221
+ <key>key-vim.host.BlockHba-vmhba0</key>
222
+ <device>vmhba0</device>
223
+ <bus>0</bus>
224
+ <status>unknown</status>
225
+ <model>Virtual Machine Chipset</model>
226
+ <driver>ata_piix</driver>
227
+ <pci>00:07.1</pci>
228
+ </hostBusAdapter>
229
+ EOS
230
+ end
231
+
232
+ =begin
233
+ def test_runtime_state
234
+ obj = VIM::VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState(
235
+ :dynamicProperty => [],
236
+ vmDirectPathGen2:Active => false,
237
+ vmDirectPathGen2:InactiveReasonOther => ["vmNptIncompatibleHost"],
238
+ vmDirectPathGen2:InactiveReasonVm => []
239
+ )
240
+ check <<-EOS, obj, 'VirtualMachineDeviceRuntimeInfoDeviceRuntimeState'
241
+ <runtimeState xsi:type="VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState" xmlns:xsi="#{VIM::NS_XSI}">
242
+ <vmDirectPathGen2Active>false</vmDirectPathGen2Active>
243
+ <vmDirectPathGen2InactiveReasonOther>vmNptIncompatibleHost</vmDirectPathGen2InactiveReasonOther>
244
+ </runtimeState>
245
+ EOS
246
+ end
247
+ =end
248
+
249
+ def test_runtime_info
250
+ obj = VIM::VirtualMachineRuntimeInfo(
251
+ :bootTime => Time.parse('2010-08-20 05:44:35 UTC'),
252
+ :connectionState => "connected",
253
+ :dynamicProperty => [],
254
+ :faultToleranceState => "notConfigured",
255
+ :featureMask => [],
256
+ :featureRequirement => [],
257
+ :host => VIM::HostSystem(nil, "host-32"),
258
+ :maxCpuUsage => 5612,
259
+ :maxMemoryUsage => 3072,
260
+ :memoryOverhead => 128671744,
261
+ :numMksConnections => 1,
262
+ :offlineFeatureRequirement => [],
263
+ :powerState => "poweredOn",
264
+ :recordReplayState => "inactive",
265
+ :suspendInterval => 0,
266
+ :toolsInstallerMounted => false,
267
+ :device => []
268
+ )
269
+
270
+ check <<-EOS, obj, 'VirtualMachineRuntimeInfo'
271
+ <val xsi:type="VirtualMachineRuntimeInfo" xmlns:xsi="#{VIM::NS_XSI}">
272
+ <host type="HostSystem">host-32</host>
273
+ <connectionState>connected</connectionState>
274
+ <powerState>poweredOn</powerState>
275
+ <faultToleranceState>notConfigured</faultToleranceState>
276
+ <toolsInstallerMounted>false</toolsInstallerMounted>
277
+ <bootTime>2010-08-20T05:44:35.0Z</bootTime>
278
+ <suspendInterval>0</suspendInterval>
279
+ <memoryOverhead>128671744</memoryOverhead>
280
+ <maxCpuUsage>5612</maxCpuUsage>
281
+ <maxMemoryUsage>3072</maxMemoryUsage>
282
+ <numMksConnections>1</numMksConnections>
283
+ <recordReplayState>inactive</recordReplayState>
284
+ </val>
285
+ EOS
286
+ end
287
+
288
+ def test_keyvalue
289
+ obj = ['a', 'b']
290
+ check <<-EOS, obj, 'KeyValue'
291
+ <root>
292
+ <key>a</key>
293
+ <value>b</value>
294
+ </root>
295
+ EOS
296
+ end
297
+
298
+ def test_boolean
299
+ check "<root>1</root>", true, 'xsd:boolean'
300
+ check "<root>true</root>", true, 'xsd:boolean'
301
+ check "<root>0</root>", false, 'xsd:boolean'
302
+ check "<root>false</root>", false, 'xsd:boolean'
303
+ end
304
+
305
+ def test_int
306
+ check "<root>5</root>", 5, 'xsd:byte'
307
+ check "<root>5</root>", 5, 'xsd:short'
308
+ check "<root>5</root>", 5, 'xsd:int'
309
+ check "<root>5</root>", 5, 'xsd:long'
310
+ end
311
+
312
+ def test_float
313
+ obj = 1.2
314
+ check <<-EOS, obj, 'xsd:float'
315
+ <root>1.2</root>
316
+ EOS
317
+ end
318
+
319
+ def test_date
320
+ time_str = '2010-08-20T05:44:35.0Z'
321
+ obj = Time.parse(time_str)
322
+ check <<-EOS, obj, 'xsd:dateTime'
323
+ <root>#{time_str}</root>
324
+ EOS
325
+ end
326
+
327
+ def test_array_mangling
328
+ obj = ["foo"]
329
+ check <<-EOS, obj, 'ArrayOfString'
330
+ <root><e>foo</e></root>
331
+ EOS
332
+
333
+ time_str = '2010-08-20T05:44:35.0Z'
334
+ obj = [Time.parse(time_str)]
335
+ check <<-EOS, obj, 'ArrayOfDateTime'
336
+ <root><e>#{time_str}</e></root>
337
+ EOS
338
+
339
+ obj = [1]
340
+ check <<-EOS, obj, 'ArrayOfAnyType'
341
+ <root xmlns:xsi="#{VIM::NS_XSI}">
342
+ <e xsi:type="xsd:int">1</e>
343
+ </root>
344
+ EOS
345
+ end
346
+
347
+ def test_propertypath
348
+ check "<root>foo</root>", "foo", 'PropertyPath'
349
+ end
350
+
351
+ def test_methodname
352
+ check "<root>foo</root>", "foo", 'MethodName'
353
+ end
354
+
355
+ def test_typename
356
+ check "<root>foo</root>", "foo", 'TypeName'
357
+ end
358
+
359
+ def test_new_fields
360
+ obj = VIM::HostBlockHba(
361
+ :dynamicProperty => [],
362
+ :key => 'key-vim.host.BlockHba-vmhba0',
363
+ :device => 'vmhba0',
364
+ :bus => 0,
365
+ :status => 'unknown',
366
+ :model => 'Virtual Machine Chipset',
367
+ :driver => 'ata_piix',
368
+ :pci => '00:07.1')
369
+
370
+ check <<-EOS, obj, "HostBlockHba"
371
+ <hostBusAdapter xsi:type="HostBlockHba">
372
+ <key>key-vim.host.BlockHba-vmhba0</key>
373
+ <device>vmhba0</device>
374
+ <bus>0</bus>
375
+ <status>unknown</status>
376
+ <foo>bar</foo>
377
+ <model>Virtual Machine Chipset</model>
378
+ <driver>ata_piix</driver>
379
+ <pci>00:07.1</pci>
380
+ </hostBusAdapter>
381
+ EOS
382
+ end
383
+ end
@@ -0,0 +1,128 @@
1
+ require 'test_helper'
2
+
3
+ class EmitRequestTest < Test::Unit::TestCase
4
+ MO = VIM::VirtualMachine(nil, "foo")
5
+
6
+ def check desc, str, this, params
7
+ soap = VIM.new(:ns => 'urn:vim25', :rev => '4.0')
8
+ xml = Builder::XmlMarkup.new :indent => 2
9
+ soap.emit_request xml, 'root', desc, this, params
10
+
11
+ begin
12
+ assert_equal str, xml.target!
13
+ rescue MiniTest::Assertion
14
+ puts "expected:"
15
+ puts str
16
+ puts
17
+ puts "got:"
18
+ puts xml.target!
19
+ puts
20
+ raise
21
+ end
22
+ end
23
+
24
+ def test_string_array
25
+ desc = [
26
+ {
27
+ 'name' => 'blah',
28
+ 'is-array' => true,
29
+ 'is-optional' => true,
30
+ 'wsdl_type' => 'xsd:string',
31
+ }
32
+ ]
33
+
34
+ check desc, <<-EOS, MO, :blah => ['a', 'b', 'c']
35
+ <root xmlns="urn:vim25">
36
+ <_this type="VirtualMachine">foo</_this>
37
+ <blah>a</blah>
38
+ <blah>b</blah>
39
+ <blah>c</blah>
40
+ </root>
41
+ EOS
42
+ end
43
+
44
+ def test_required_param
45
+ desc = [
46
+ {
47
+ 'name' => 'blah',
48
+ 'is-array' => false,
49
+ 'is-optional' => false,
50
+ 'wsdl_type' => 'xsd:string',
51
+ }
52
+ ]
53
+
54
+ check desc, <<-EOS, MO, :blah => 'a'
55
+ <root xmlns="urn:vim25">
56
+ <_this type="VirtualMachine">foo</_this>
57
+ <blah>a</blah>
58
+ </root>
59
+ EOS
60
+
61
+ assert_raise RuntimeError do
62
+ check desc, <<-EOS, MO, {}
63
+ <root xmlns="urn:vim25">
64
+ <_this type="VirtualMachine">foo</_this>
65
+ </root>
66
+ EOS
67
+ end
68
+ end
69
+
70
+ def test_optional_param
71
+ desc = [
72
+ {
73
+ 'name' => 'blah',
74
+ 'is-array' => false,
75
+ 'is-optional' => true,
76
+ 'wsdl_type' => 'xsd:string',
77
+ }
78
+ ]
79
+
80
+ check desc, <<-EOS, MO, {}
81
+ <root xmlns="urn:vim25">
82
+ <_this type="VirtualMachine">foo</_this>
83
+ </root>
84
+ EOS
85
+ end
86
+
87
+ def test_nil_optional_param
88
+ desc = [
89
+ {
90
+ 'name' => 'blah',
91
+ 'is-array' => false,
92
+ 'is-optional' => true,
93
+ 'wsdl_type' => 'xsd:string',
94
+ }
95
+ ]
96
+
97
+ check desc, <<-EOS, MO, :blah => nil
98
+ <root xmlns="urn:vim25">
99
+ <_this type="VirtualMachine">foo</_this>
100
+ </root>
101
+ EOS
102
+ end
103
+
104
+ def test_string_key
105
+ desc = [
106
+ {
107
+ 'name' => 'blah',
108
+ 'is-array' => false,
109
+ 'is-optional' => false,
110
+ 'wsdl_type' => 'xsd:string',
111
+ }
112
+ ]
113
+
114
+ check desc, <<-EOS, MO, 'blah' => 'a'
115
+ <root xmlns="urn:vim25">
116
+ <_this type="VirtualMachine">foo</_this>
117
+ <blah>a</blah>
118
+ </root>
119
+ EOS
120
+ end
121
+
122
+ def disabled_test_required_property
123
+ assert_raise RuntimeError do
124
+ VIM::AboutInfo()
125
+ end
126
+ end
127
+ end
128
+