rbvmomi 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.yardopts +5 -0
  2. data/README.rdoc +71 -0
  3. data/Rakefile +11 -0
  4. data/VERSION +1 -1
  5. data/devel/analyze-xml.rb +29 -29
  6. data/{test/test.rb → examples/create_vm.rb} +40 -15
  7. data/examples/extraConfig.rb +54 -0
  8. data/examples/power.rb +57 -0
  9. data/examples/readme-1.rb +35 -0
  10. data/examples/readme-2.rb +51 -0
  11. data/lib/rbvmomi.rb +3 -282
  12. data/lib/rbvmomi/{types.rb → basic_types.rb} +37 -97
  13. data/lib/rbvmomi/connection.rb +239 -0
  14. data/lib/rbvmomi/fault.rb +17 -0
  15. data/lib/{trivial_soap.rb → rbvmomi/trivial_soap.rb} +31 -13
  16. data/lib/rbvmomi/trollop.rb +6 -2
  17. data/lib/rbvmomi/type_loader.rb +72 -0
  18. data/lib/rbvmomi/vim.rb +76 -0
  19. data/lib/rbvmomi/vim/ComputeResource.rb +51 -0
  20. data/lib/rbvmomi/vim/Datacenter.rb +17 -0
  21. data/lib/rbvmomi/vim/Datastore.rb +68 -0
  22. data/lib/rbvmomi/vim/Folder.rb +112 -0
  23. data/lib/rbvmomi/vim/ManagedEntity.rb +46 -0
  24. data/lib/rbvmomi/vim/ManagedObject.rb +55 -0
  25. data/lib/rbvmomi/vim/ObjectContent.rb +23 -0
  26. data/lib/rbvmomi/vim/ObjectUpdate.rb +23 -0
  27. data/lib/rbvmomi/vim/OvfManager.rb +93 -0
  28. data/lib/rbvmomi/vim/ResourcePool.rb +18 -0
  29. data/lib/rbvmomi/vim/ServiceInstance.rb +53 -0
  30. data/lib/rbvmomi/vim/Task.rb +31 -0
  31. data/lib/rbvmomi/vim/VirtualMachine.rb +7 -0
  32. data/test/test_deserialization.rb +11 -55
  33. data/test/test_emit_request.rb +13 -10
  34. data/test/test_exceptions.rb +16 -0
  35. data/test/test_parse_response.rb +2 -10
  36. data/test/test_serialization.rb +14 -11
  37. metadata +41 -25
  38. data/.gitignore +0 -4
  39. data/README.md +0 -12
  40. data/lib/rbvmomi/extensions.rb +0 -491
  41. data/lib/rbvmomi/profile.rb +0 -22
  42. data/test/runner.rb +0 -3
@@ -0,0 +1,18 @@
1
+ class RbVmomi::VIM::ResourcePool
2
+ # Retrieve a child ResourcePool.
3
+ # @param name [String] Name of the child.
4
+ # @return [VIM::ResourcePool]
5
+ def find name
6
+ @soap.searchIndex.FindChild(entity: self, name: name)
7
+ end
8
+
9
+ # Retrieve a descendant of this ResourcePool.
10
+ # @param path [String] Path delimited by '/'.
11
+ # @return [VIM::ResourcePool]
12
+ def traverse path
13
+ es = path.split('/').reject(&:empty?)
14
+ es.inject(self) do |f,e|
15
+ f.find(e) || return
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,53 @@
1
+ class RbVmomi::VIM::ServiceInstance
2
+ # Retrieve a Datacenter.
3
+ # If no path is given the first datacenter will be returned.
4
+ # @param path (see Folder#traverse)
5
+ # @return [Datacenter]
6
+ def find_datacenter path=nil
7
+ if path
8
+ content.rootFolder.traverse path, RbVmomi::VIM::Datacenter
9
+ else
10
+ content.rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).first
11
+ end
12
+ end
13
+
14
+ # Wait for several tasks to complete.
15
+ # @param interested [Array] Property paths to watch for updates.
16
+ # @param tasks [Array] Tasks to wait on.
17
+ # @yield [Hash] Called when a property is updated on a task.
18
+ # The parameter is a hash from tasks to hashes from
19
+ # property path to value.
20
+ # @return [void]
21
+ def wait_for_multiple_tasks interested, tasks
22
+ version = ''
23
+ interested = (interested + ['info.state']).uniq
24
+ task_props = Hash.new { |h,k| h[k] = {} }
25
+
26
+ filter = @soap.propertyCollector.CreateFilter :spec => {
27
+ :propSet => [{ :type => 'Task', :all => false, :pathSet => interested }],
28
+ :objectSet => tasks.map { |x| { :obj => x } },
29
+ }, :partialUpdates => false
30
+
31
+ begin
32
+ until task_props.size == tasks.size and task_props.all? { |k,h| %w(success error).member? h['info.state'] }
33
+ result = @soap.propertyCollector.WaitForUpdates(version: version)
34
+ version = result.version
35
+ os = result.filterSet[0].objectSet
36
+
37
+ os.each do |o|
38
+ changes = Hash[o.changeSet.map { |x| [x.name, x.val] }]
39
+
40
+ interested.each do |k|
41
+ task = tasks.find { |x| x._ref == o.obj._ref }
42
+ task_props[task][k] = changes[k] if changes.member? k
43
+ end
44
+ end
45
+
46
+ yield task_props
47
+ end
48
+ ensure
49
+ @soap.propertyCollector.CancelWaitForUpdates
50
+ filter.DestroyPropertyFilter
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,31 @@
1
+ class RbVmomi::VIM::Task
2
+ # Wait for a task to finish.
3
+ # @return +info.result+ on success.
4
+ # @raise +info.error+ on error.
5
+ def wait_for_completion
6
+ wait_until('info.state') { %w(success error).member? info.state }
7
+ case info.state
8
+ when 'success'
9
+ info.result
10
+ when 'error'
11
+ raise info.error
12
+ end
13
+ end
14
+
15
+ # Wait for a task to finish, with progress notifications.
16
+ # @return (see #wait_for_completion)
17
+ # @raise (see #wait_for_completion)
18
+ # @yield [info.progress]
19
+ def wait_for_progress
20
+ wait_until('info.state', 'info.progress') do
21
+ yield info.progress if block_given?
22
+ %w(success error).member? info.state
23
+ end
24
+ case info.state
25
+ when 'success'
26
+ info.result
27
+ when 'error'
28
+ raise info.error
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ class RbVmomi::VIM::VirtualMachine
2
+ # Retrieve the MAC addresses for all virtual NICs.
3
+ # @return [Hash] Keyed by device label.
4
+ def macs
5
+ Hash[self.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard).map { |x| [x.deviceInfo.label, x.macAddress] }]
6
+ end
7
+ end
@@ -1,22 +1,14 @@
1
1
  require 'test/unit'
2
2
  require 'rbvmomi'
3
- include RbVmomi
3
+ VIM ||= RbVmomi::VIM
4
4
 
5
5
  class DeserializationTest < Test::Unit::TestCase
6
6
  def setup
7
- @soap = RbVmomi::Soap.new(ns: 'urn:vim25', rev: '4.0')
7
+ @soap = VIM.new(ns: 'urn:vim25', rev: '4.0')
8
8
  end
9
9
 
10
10
  def check str, expected, type
11
11
  got = @soap.xml2obj Nokogiri(str).root, type
12
-
13
- puts "expected:"
14
- pp expected
15
- puts
16
- puts "got:"
17
- pp got
18
- puts
19
-
20
12
  assert_equal expected, got
21
13
  end
22
14
 
@@ -79,7 +71,7 @@ class DeserializationTest < Test::Unit::TestCase
79
71
  )
80
72
 
81
73
  check <<-EOS, obj, 'ObjectContent'
82
- <root xmlns:xsi="#{RbVmomi::Soap::NS_XSI}">
74
+ <root xmlns:xsi="#{VIM::NS_XSI}">
83
75
  <obj type="Folder">ha-folder-root</obj>
84
76
  <propSet>
85
77
  <name>childEntity</name>
@@ -96,8 +88,6 @@ def test_array2
96
88
  dynamicProperty: [],
97
89
  linkUp: true,
98
90
  blocked: false,
99
- vmDirectPathGen2InactiveReasonNetwork: [],
100
- vmDirectPathGen2InactiveReasonOther: [],
101
91
  vlanIds: [
102
92
  VIM::NumericRange(dynamicProperty: [], start: 5, end: 7),
103
93
  VIM::NumericRange(dynamicProperty: [], start: 10, end: 20),
@@ -123,8 +113,6 @@ end
123
113
  def test_empty_array
124
114
  obj = VIM.DVPortStatus(
125
115
  dynamicProperty: [],
126
- vmDirectPathGen2InactiveReasonNetwork: [],
127
- vmDirectPathGen2InactiveReasonOther: [],
128
116
  linkUp: true,
129
117
  blocked: false,
130
118
  vlanIds: []
@@ -149,7 +137,7 @@ end
149
137
  )
150
138
 
151
139
  check <<-EOS, obj, "LocalizedMethodFault"
152
- <error xmlns:xsi="#{RbVmomi::Soap::NS_XSI}">
140
+ <error xmlns:xsi="#{VIM::NS_XSI}">
153
141
  <fault xsi:type="InvalidPowerState">
154
142
  <requestedState>poweredOn</requestedState>
155
143
  <existingState>poweredOff</existingState>
@@ -189,7 +177,7 @@ end
189
177
  )
190
178
 
191
179
  check <<-EOS, obj, "UpdateSet"
192
- <returnval xmlns:xsi="#{RbVmomi::Soap::NS_XSI}">
180
+ <returnval xmlns:xsi="#{VIM::NS_XSI}">
193
181
  <version>7</version>
194
182
  <filterSet>
195
183
  <filter type="PropertyFilter">session[528BA5EB-335B-4AF6-B49C-6160CF5E8D5B]71E3AC7E-7927-4D9E-8BC3-522769F22DAF</filter>
@@ -238,6 +226,7 @@ end
238
226
  EOS
239
227
  end
240
228
 
229
+ =begin
241
230
  def test_runtime_state
242
231
  obj = VIM::VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState(
243
232
  dynamicProperty: [],
@@ -246,40 +235,21 @@ end
246
235
  vmDirectPathGen2InactiveReasonVm: []
247
236
  )
248
237
  check <<-EOS, obj, 'VirtualMachineDeviceRuntimeInfoDeviceRuntimeState'
249
- <runtimeState xsi:type="VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState" xmlns:xsi="#{RbVmomi::Soap::NS_XSI}">
238
+ <runtimeState xsi:type="VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState" xmlns:xsi="#{VIM::NS_XSI}">
250
239
  <vmDirectPathGen2Active>false</vmDirectPathGen2Active>
251
240
  <vmDirectPathGen2InactiveReasonOther>vmNptIncompatibleHost</vmDirectPathGen2InactiveReasonOther>
252
241
  </runtimeState>
253
242
  EOS
254
243
  end
244
+ =end
255
245
 
256
246
  def test_runtime_info
257
- obj = RbVmomi::VIM::VirtualMachineRuntimeInfo(
247
+ obj = VIM::VirtualMachineRuntimeInfo(
258
248
  bootTime: Time.parse('2010-08-20 05:44:35 UTC'),
259
249
  connectionState: "connected",
260
- device: [RbVmomi::VIM::VirtualMachineDeviceRuntimeInfo(
261
- dynamicProperty: [],
262
- key: 4000,
263
- runtimeState: RbVmomi::VIM::VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState(
264
- dynamicProperty: [],
265
- vmDirectPathGen2Active: false,
266
- vmDirectPathGen2InactiveReasonOther: [],
267
- vmDirectPathGen2InactiveReasonVm: ["vmNptIncompatibleAdapterType"]
268
- )
269
- ),
270
- RbVmomi::VIM::VirtualMachineDeviceRuntimeInfo(
271
- dynamicProperty: [],
272
- key: 4001,
273
- runtimeState: RbVmomi::VIM::VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState(
274
- dynamicProperty: [],
275
- vmDirectPathGen2Active: false,
276
- vmDirectPathGen2InactiveReasonOther: ["vmNptIncompatibleHost"],
277
- vmDirectPathGen2InactiveReasonVm: []
278
- )
279
- )],
280
250
  dynamicProperty: [],
281
251
  faultToleranceState: "notConfigured",
282
- host: RbVmomi::VIM::HostSystem(nil, "host-32"),
252
+ host: VIM::HostSystem(nil, "host-32"),
283
253
  maxCpuUsage: 5612,
284
254
  maxMemoryUsage: 3072,
285
255
  memoryOverhead: 128671744,
@@ -291,21 +261,7 @@ end
291
261
  )
292
262
 
293
263
  check <<-EOS, obj, 'VirtualMachineRuntimeInfo'
294
- <val xsi:type="VirtualMachineRuntimeInfo" xmlns:xsi="#{RbVmomi::Soap::NS_XSI}">
295
- <device>
296
- <runtimeState xsi:type="VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState">
297
- <vmDirectPathGen2Active>false</vmDirectPathGen2Active>
298
- <vmDirectPathGen2InactiveReasonVm>vmNptIncompatibleAdapterType</vmDirectPathGen2InactiveReasonVm>
299
- </runtimeState>
300
- <key>4000</key>
301
- </device>
302
- <device>
303
- <runtimeState xsi:type="VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState">
304
- <vmDirectPathGen2Active>false</vmDirectPathGen2Active>
305
- <vmDirectPathGen2InactiveReasonOther>vmNptIncompatibleHost</vmDirectPathGen2InactiveReasonOther>
306
- </runtimeState>
307
- <key>4001</key>
308
- </device>
264
+ <val xsi:type="VirtualMachineRuntimeInfo" xmlns:xsi="#{VIM::NS_XSI}">
309
265
  <host type="HostSystem">host-32</host>
310
266
  <connectionState>connected</connectionState>
311
267
  <powerState>poweredOn</powerState>
@@ -1,23 +1,26 @@
1
1
  require 'test/unit'
2
2
  require 'rbvmomi'
3
- include RbVmomi
3
+ VIM ||= RbVmomi::VIM
4
4
 
5
5
  class EmitRequestTest < Test::Unit::TestCase
6
6
  MO = VIM::VirtualMachine(nil, "foo")
7
7
 
8
8
  def check desc, str, this, params
9
- soap = RbVmomi::Soap.new(ns: 'urn:vim25', rev: '4.0')
9
+ soap = VIM.new(ns: 'urn:vim25', rev: '4.0')
10
10
  xml = Builder::XmlMarkup.new :indent => 2
11
11
  soap.emit_request xml, 'root', desc, this, params
12
12
 
13
- puts "expected:"
14
- puts str
15
- puts
16
- puts "got:"
17
- puts xml.target!
18
- puts
19
-
20
- assert_equal str, xml.target!
13
+ begin
14
+ assert_equal str, xml.target!
15
+ rescue MiniTest::Assertion
16
+ puts "expected:"
17
+ puts str
18
+ puts
19
+ puts "got:"
20
+ puts xml.target!
21
+ puts
22
+ raise
23
+ end
21
24
  end
22
25
 
23
26
  def test_string_array
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require 'rbvmomi'
3
+ VIM ||= RbVmomi::VIM
4
+
5
+ class ExceptionTest < Test::Unit::TestCase
6
+ def test_fault
7
+ begin
8
+ fault = VIM::InvalidArgument.new invalidProperty: 'foo'
9
+ assert_raises RbVmomi::Fault do
10
+ raise RbVmomi::Fault.new('A specified parameter was not correct.', fault)
11
+ end
12
+ rescue VIM::InvalidArgument
13
+ assert_equal 'foo', $!.invalidProperty
14
+ end
15
+ end
16
+ end
@@ -1,19 +1,11 @@
1
1
  require 'test/unit'
2
2
  require 'rbvmomi'
3
- include RbVmomi
3
+ VIM ||= RbVmomi::VIM
4
4
 
5
5
  class ParseResponseTest < Test::Unit::TestCase
6
6
  def check desc, str, expected
7
- soap = RbVmomi::Soap.new(ns: 'urn:vim25', rev: '4.0')
7
+ soap = VIM.new(ns: 'urn:vim25', rev: '4.0')
8
8
  got = soap.parse_response Nokogiri(str).root, desc
9
-
10
- puts "expected:"
11
- pp expected
12
- puts
13
- puts "got:"
14
- pp got
15
- puts
16
-
17
9
  assert_equal expected, got
18
10
  end
19
11
 
@@ -1,21 +1,24 @@
1
1
  require 'test/unit'
2
2
  require 'rbvmomi'
3
- include RbVmomi
3
+ VIM ||= RbVmomi::VIM
4
4
 
5
5
  class SerializationTest < Test::Unit::TestCase
6
6
  def check str, obj, type, array=false
7
- @soap = RbVmomi::Soap.new(ns: 'urn:vim25', rev: '4.0')
7
+ @soap = VIM.new(ns: 'urn:vim25', rev: '4.0')
8
8
  xml = Builder::XmlMarkup.new :indent => 2
9
- soap.obj2xml(xml, 'root', type, array, obj)
9
+ @soap.obj2xml(xml, 'root', type, array, obj)
10
10
 
11
- puts "expected:"
12
- puts str
13
- puts
14
- puts "got:"
15
- puts xml.target!
16
- puts
17
-
18
- assert_equal str, xml.target!
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
19
22
  end
20
23
 
21
24
  def test_moref
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbvmomi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
7
+ - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ version: 1.1.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Rich Lane
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-11-11 00:00:00 -08:00
17
+ date: 2011-02-20 00:00:00 -08:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 5
30
28
  segments:
31
29
  - 1
32
30
  - 4
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ">="
44
42
  - !ruby/object:Gem::Version
45
- hash: 3
46
43
  segments:
47
44
  - 0
48
45
  version: "0"
@@ -56,7 +53,6 @@ dependencies:
56
53
  requirements:
57
54
  - - ">="
58
55
  - !ruby/object:Gem::Version
59
- hash: 3
60
56
  segments:
61
57
  - 0
62
58
  version: "0"
@@ -70,7 +66,6 @@ dependencies:
70
66
  requirements:
71
67
  - - ">="
72
68
  - !ruby/object:Gem::Version
73
- hash: 3
74
69
  segments:
75
70
  - 0
76
71
  version: "0"
@@ -84,25 +79,44 @@ extensions: []
84
79
 
85
80
  extra_rdoc_files:
86
81
  - LICENSE
87
- - README.md
82
+ - README.rdoc
88
83
  files:
89
- - .gitignore
84
+ - .yardopts
90
85
  - LICENSE
91
- - README.md
86
+ - README.rdoc
92
87
  - Rakefile
93
88
  - VERSION
94
89
  - devel/analyze-vim-declarations.rb
95
90
  - devel/analyze-xml.rb
91
+ - examples/create_vm.rb
92
+ - examples/extraConfig.rb
93
+ - examples/power.rb
94
+ - examples/readme-1.rb
95
+ - examples/readme-2.rb
96
96
  - lib/rbvmomi.rb
97
- - lib/rbvmomi/extensions.rb
98
- - lib/rbvmomi/profile.rb
97
+ - lib/rbvmomi/basic_types.rb
98
+ - lib/rbvmomi/connection.rb
99
+ - lib/rbvmomi/fault.rb
100
+ - lib/rbvmomi/trivial_soap.rb
99
101
  - lib/rbvmomi/trollop.rb
100
- - lib/rbvmomi/types.rb
101
- - lib/trivial_soap.rb
102
- - test/runner.rb
103
- - test/test.rb
102
+ - lib/rbvmomi/type_loader.rb
103
+ - lib/rbvmomi/vim.rb
104
+ - lib/rbvmomi/vim/ComputeResource.rb
105
+ - lib/rbvmomi/vim/Datacenter.rb
106
+ - lib/rbvmomi/vim/Datastore.rb
107
+ - lib/rbvmomi/vim/Folder.rb
108
+ - lib/rbvmomi/vim/ManagedEntity.rb
109
+ - lib/rbvmomi/vim/ManagedObject.rb
110
+ - lib/rbvmomi/vim/ObjectContent.rb
111
+ - lib/rbvmomi/vim/ObjectUpdate.rb
112
+ - lib/rbvmomi/vim/OvfManager.rb
113
+ - lib/rbvmomi/vim/ResourcePool.rb
114
+ - lib/rbvmomi/vim/ServiceInstance.rb
115
+ - lib/rbvmomi/vim/Task.rb
116
+ - lib/rbvmomi/vim/VirtualMachine.rb
104
117
  - test/test_deserialization.rb
105
118
  - test/test_emit_request.rb
119
+ - test/test_exceptions.rb
106
120
  - test/test_parse_response.rb
107
121
  - test/test_serialization.rb
108
122
  - vmodl.cdb
@@ -111,8 +125,8 @@ homepage: https://github.com/rlane/rbvmomi
111
125
  licenses: []
112
126
 
113
127
  post_install_message:
114
- rdoc_options:
115
- - --charset=UTF-8
128
+ rdoc_options: []
129
+
116
130
  require_paths:
117
131
  - lib
118
132
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -120,7 +134,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
134
  requirements:
121
135
  - - ">="
122
136
  - !ruby/object:Gem::Version
123
- hash: 49
124
137
  segments:
125
138
  - 1
126
139
  - 9
@@ -131,7 +144,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
144
  requirements:
132
145
  - - ">="
133
146
  - !ruby/object:Gem::Version
134
- hash: 3
135
147
  segments:
136
148
  - 0
137
149
  version: "0"
@@ -143,9 +155,13 @@ signing_key:
143
155
  specification_version: 3
144
156
  summary: Ruby interface to the VI API
145
157
  test_files:
146
- - test/runner.rb
147
- - test/test_serialization.rb
148
- - test/test.rb
158
+ - examples/create_vm.rb
159
+ - examples/extraConfig.rb
160
+ - examples/power.rb
161
+ - examples/readme-1.rb
162
+ - examples/readme-2.rb
149
163
  - test/test_deserialization.rb
150
- - test/test_parse_response.rb
151
164
  - test/test_emit_request.rb
165
+ - test/test_exceptions.rb
166
+ - test/test_parse_response.rb
167
+ - test/test_serialization.rb