rbvmomi 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/VERSION +1 -1
- data/devel/benchmark.rb +117 -0
- data/devel/collisions.rb +18 -0
- data/devel/merge-internal-vmodl.rb +7 -0
- data/lib/rbvmomi/basic_types.rb +20 -3
- data/lib/rbvmomi/connection.rb +59 -93
- data/lib/rbvmomi/deserialization.rb +235 -0
- data/lib/rbvmomi/trivial_soap.rb +6 -3
- data/lib/rbvmomi/type_loader.rb +23 -23
- data/lib/rbvmomi/vim.rb +2 -17
- data/lib/rbvmomi/vim/ComputeResource.rb +1 -1
- data/lib/rbvmomi/vim/Datastore.rb +6 -6
- data/lib/rbvmomi/vim/Folder.rb +48 -16
- data/lib/rbvmomi/vim/HostSystem.rb +13 -1
- data/lib/rbvmomi/vim/ManagedEntity.rb +36 -25
- data/lib/rbvmomi/vim/ManagedObject.rb +3 -3
- data/lib/rbvmomi/vim/PropertyCollector.rb +4 -2
- data/lib/rbvmomi/vim/ReflectManagedMethodExecuter.rb +2 -2
- data/lib/rbvmomi/vim/ResourcePool.rb +38 -1
- data/lib/rbvmomi/vim/ServiceInstance.rb +3 -3
- data/test/test_deserialization.rb +94 -9
- data/test/test_emit_request.rb +1 -3
- data/test/test_exceptions.rb +1 -3
- data/test/test_helper.rb +14 -0
- data/test/test_misc.rb +7 -3
- data/test/test_parse_response.rb +1 -3
- data/test/test_serialization.rb +17 -5
- data/vmodl.db +0 -0
- metadata +7 -2
@@ -6,7 +6,19 @@ class VIM::HostSystem
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def dtm
|
9
|
-
@cached_dtm ||=
|
9
|
+
@cached_dtm ||= begin
|
10
|
+
RetrieveDynamicTypeManager()
|
11
|
+
rescue VIM::MethodNotFound
|
12
|
+
if summary.config.product.version >= '4.1.0'
|
13
|
+
if summary.config.product.version < '5.0.0' and direct?
|
14
|
+
VIM::InternalDynamicTypeManager(_connection, 'ha-dynamic-type-manager')
|
15
|
+
else
|
16
|
+
raise "esxcli not supported through VC before 5.0.0"
|
17
|
+
end
|
18
|
+
else
|
19
|
+
raise "esxcli not supported before 4.1.0"
|
20
|
+
end
|
21
|
+
end
|
10
22
|
end
|
11
23
|
|
12
24
|
def dti
|
@@ -2,39 +2,50 @@ class RbVmomi::VIM::ManagedEntity
|
|
2
2
|
# Retrieve the ancestors of the entity.
|
3
3
|
# @return [Array] Ancestors of this entity, starting with the root.
|
4
4
|
def path
|
5
|
+
self.class.paths([self])[self]
|
6
|
+
end
|
7
|
+
|
8
|
+
# Retrieve the ancestors of a list of entries.
|
9
|
+
# @return [Hash] Object-indexed hash of ancestors of entities, starting with the root.
|
10
|
+
def self.paths objs
|
5
11
|
filterSpec = RbVmomi::VIM.PropertyFilterSpec(
|
6
|
-
:objectSet =>
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
:objectSet => objs.map do |obj|
|
13
|
+
RbVmomi::VIM.ObjectSpec(
|
14
|
+
:obj => obj,
|
15
|
+
:selectSet => [
|
16
|
+
RbVmomi::VIM.TraversalSpec(
|
17
|
+
:name => "tsME",
|
18
|
+
:type => 'ManagedEntity',
|
19
|
+
:path => 'parent',
|
20
|
+
:skip => false,
|
21
|
+
:selectSet => [
|
22
|
+
RbVmomi::VIM.SelectionSpec(:name => "tsME")
|
23
|
+
]
|
24
|
+
)
|
25
|
+
]
|
26
|
+
)
|
27
|
+
end,
|
20
28
|
:propSet => [{
|
21
29
|
:pathSet => %w(name parent),
|
22
30
|
:type => 'ManagedEntity'
|
23
31
|
}]
|
24
32
|
)
|
25
33
|
|
26
|
-
|
34
|
+
propCollector = objs.first._connection.propertyCollector
|
35
|
+
result = propCollector.RetrieveProperties(:specSet => [filterSpec])
|
27
36
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
Hash[objs.map do |obj|
|
38
|
+
tree = {}
|
39
|
+
result.each { |x| tree[x.obj] = [x['parent'], x['name']] }
|
40
|
+
a = []
|
41
|
+
cur = obj
|
42
|
+
while cur
|
43
|
+
parent, name = *tree[cur]
|
44
|
+
a << [cur, name]
|
45
|
+
cur = parent
|
46
|
+
end
|
47
|
+
[obj, a.reverse]
|
48
|
+
end]
|
38
49
|
end
|
39
50
|
|
40
51
|
# Return a string representation of +path+ suitable for display.
|
@@ -8,13 +8,13 @@ class RbVmomi::VIM::ManagedObject
|
|
8
8
|
# @todo Pass the current property values to the block.
|
9
9
|
def wait_until *pathSet, &b
|
10
10
|
all = pathSet.empty?
|
11
|
-
filter =
|
11
|
+
filter = _connection.propertyCollector.CreateFilter :spec => {
|
12
12
|
:propSet => [{ :type => self.class.wsdl_name, :all => all, :pathSet => pathSet }],
|
13
13
|
:objectSet => [{ :obj => self }],
|
14
14
|
}, :partialUpdates => false
|
15
15
|
ver = ''
|
16
16
|
loop do
|
17
|
-
result =
|
17
|
+
result = _connection.propertyCollector.WaitForUpdates(:version => ver)
|
18
18
|
ver = result.version
|
19
19
|
if x = b.call
|
20
20
|
return x
|
@@ -35,7 +35,7 @@ class RbVmomi::VIM::ManagedObject
|
|
35
35
|
:type => self.class.wsdl_name
|
36
36
|
}]
|
37
37
|
}
|
38
|
-
|
38
|
+
_connection.propertyCollector.RetrieveProperties(:specSet => [spec])[0].to_hash
|
39
39
|
end
|
40
40
|
|
41
41
|
# Efficiently retrieve multiple properties from an object.
|
@@ -1,5 +1,7 @@
|
|
1
1
|
class RbVmomi::VIM::PropertyCollector
|
2
2
|
def collectMultiple objs, *pathSet
|
3
|
+
return {} if objs.empty?
|
4
|
+
|
3
5
|
klasses = objs.map{|x| x.class}.uniq
|
4
6
|
klass = if klasses.length > 1
|
5
7
|
# common superclass
|
@@ -7,7 +9,7 @@ class RbVmomi::VIM::PropertyCollector
|
|
7
9
|
else
|
8
10
|
klasses.first
|
9
11
|
end
|
10
|
-
|
12
|
+
|
11
13
|
spec = {
|
12
14
|
:objectSet => objs.map{|x| { :obj => x }},
|
13
15
|
:propSet => [{
|
@@ -20,4 +22,4 @@ class RbVmomi::VIM::PropertyCollector
|
|
20
22
|
[x.obj, x.to_hash]
|
21
23
|
end]
|
22
24
|
end
|
23
|
-
end
|
25
|
+
end
|
@@ -4,7 +4,7 @@ class VIM::ReflectManagedMethodExecuter
|
|
4
4
|
def fetch moid, prop
|
5
5
|
result = FetchSoap(:moid => moid, :version => 'urn:vim25/5.0', :prop => prop)
|
6
6
|
xml = Nokogiri(result.response)
|
7
|
-
_connection.
|
7
|
+
_connection.deserializer.deserialize xml.root, nil
|
8
8
|
end
|
9
9
|
|
10
10
|
def execute moid, method, args
|
@@ -18,7 +18,7 @@ class VIM::ReflectManagedMethodExecuter
|
|
18
18
|
end
|
19
19
|
result = ExecuteSoap(:moid => moid, :version => 'urn:vim25/5.0',
|
20
20
|
:method => method, :argument => soap_args)
|
21
|
-
_connection.
|
21
|
+
_connection.deserializer.deserialize Nokogiri(result.response).root, nil
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -3,7 +3,7 @@ class RbVmomi::VIM::ResourcePool
|
|
3
3
|
# @param name [String] Name of the child.
|
4
4
|
# @return [VIM::ResourcePool]
|
5
5
|
def find name
|
6
|
-
|
6
|
+
_connection.searchIndex.FindChild(:entity => self, :name => name)
|
7
7
|
end
|
8
8
|
|
9
9
|
# Retrieve a descendant of this ResourcePool.
|
@@ -15,4 +15,41 @@ class RbVmomi::VIM::ResourcePool
|
|
15
15
|
f.find(e) || return
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
def resourcePoolSubTree fields = []
|
20
|
+
self.class.resourcePoolSubTree [self], fields
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.resourcePoolSubTree objs, fields = []
|
24
|
+
fields = (fields + ['name', 'resourcePool']).uniq
|
25
|
+
filterSpec = RbVmomi::VIM.PropertyFilterSpec(
|
26
|
+
:objectSet => objs.map do |obj|
|
27
|
+
RbVmomi::VIM.ObjectSpec(
|
28
|
+
:obj => obj,
|
29
|
+
:selectSet => [
|
30
|
+
RbVmomi::VIM.TraversalSpec(
|
31
|
+
:name => "tsRP",
|
32
|
+
:type => 'ResourcePool',
|
33
|
+
:path => 'resourcePool',
|
34
|
+
:skip => false,
|
35
|
+
:selectSet => [
|
36
|
+
RbVmomi::VIM.SelectionSpec(:name => "tsRP")
|
37
|
+
]
|
38
|
+
)
|
39
|
+
]
|
40
|
+
)
|
41
|
+
end,
|
42
|
+
:propSet => [{
|
43
|
+
:pathSet => fields,
|
44
|
+
:type => 'ResourcePool'
|
45
|
+
}]
|
46
|
+
)
|
47
|
+
|
48
|
+
propCollector = objs.first._connection.propertyCollector
|
49
|
+
result = propCollector.RetrieveProperties(:specSet => [filterSpec])
|
50
|
+
|
51
|
+
Hash[result.map do |x|
|
52
|
+
[x.obj, x.to_hash]
|
53
|
+
end]
|
54
|
+
end
|
18
55
|
end
|
@@ -23,14 +23,14 @@ class RbVmomi::VIM::ServiceInstance
|
|
23
23
|
interested = (interested + ['info.state']).uniq
|
24
24
|
task_props = Hash.new { |h,k| h[k] = {} }
|
25
25
|
|
26
|
-
filter =
|
26
|
+
filter = _connection.propertyCollector.CreateFilter :spec => {
|
27
27
|
:propSet => [{ :type => 'Task', :all => false, :pathSet => interested }],
|
28
28
|
:objectSet => tasks.map { |x| { :obj => x } },
|
29
29
|
}, :partialUpdates => false
|
30
30
|
|
31
31
|
begin
|
32
32
|
until task_props.size == tasks.size and task_props.all? { |k,h| %w(success error).member? h['info.state'] }
|
33
|
-
result =
|
33
|
+
result = _connection.propertyCollector.WaitForUpdates(:version => version)
|
34
34
|
version = result.version
|
35
35
|
os = result.filterSet[0].objectSet
|
36
36
|
|
@@ -46,7 +46,7 @@ class RbVmomi::VIM::ServiceInstance
|
|
46
46
|
yield task_props if block_given?
|
47
47
|
end
|
48
48
|
ensure
|
49
|
-
|
49
|
+
_connection.propertyCollector.CancelWaitForUpdates
|
50
50
|
filter.DestroyPropertyFilter
|
51
51
|
end
|
52
52
|
|
@@ -1,14 +1,13 @@
|
|
1
|
-
require '
|
2
|
-
require 'rbvmomi'
|
3
|
-
VIM = RbVmomi::VIM unless Object.const_defined? :VIM
|
1
|
+
require 'test_helper'
|
4
2
|
|
5
3
|
class DeserializationTest < Test::Unit::TestCase
|
6
4
|
def setup
|
7
|
-
|
5
|
+
conn = VIM.new(:ns => 'urn:vim25', :rev => '4.0')
|
6
|
+
@deserializer = RbVmomi::Deserializer.new conn
|
8
7
|
end
|
9
8
|
|
10
9
|
def check str, expected, type
|
11
|
-
got = @
|
10
|
+
got = @deserializer.deserialize Nokogiri(str).root, type
|
12
11
|
assert_equal expected, got
|
13
12
|
end
|
14
13
|
|
@@ -37,14 +36,14 @@ class DeserializationTest < Test::Unit::TestCase
|
|
37
36
|
|
38
37
|
check <<-EOS, obj, 'DatastoreSummary'
|
39
38
|
<root>
|
40
|
-
<capacity>1000</capacity>
|
41
|
-
<accessible>1</accessible>
|
42
39
|
<datastore type="Datastore">foo</datastore>
|
40
|
+
<name>baz</name>
|
41
|
+
<url>http://foo/</url>
|
42
|
+
<capacity>1000</capacity>
|
43
43
|
<freeSpace>31</freeSpace>
|
44
|
+
<accessible>1</accessible>
|
44
45
|
<multipleHostAccess>false</multipleHostAccess>
|
45
|
-
<name>baz</name>
|
46
46
|
<type>VMFS</type>
|
47
|
-
<url>http://foo/</url>
|
48
47
|
</root>
|
49
48
|
EOS
|
50
49
|
end
|
@@ -292,4 +291,90 @@ end
|
|
292
291
|
</root>
|
293
292
|
EOS
|
294
293
|
end
|
294
|
+
|
295
|
+
def test_boolean
|
296
|
+
check "<root>1</root>", true, 'xsd:boolean'
|
297
|
+
check "<root>true</root>", true, 'xsd:boolean'
|
298
|
+
check "<root>0</root>", false, 'xsd:boolean'
|
299
|
+
check "<root>false</root>", false, 'xsd:boolean'
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_int
|
303
|
+
check "<root>5</root>", 5, 'xsd:byte'
|
304
|
+
check "<root>5</root>", 5, 'xsd:short'
|
305
|
+
check "<root>5</root>", 5, 'xsd:int'
|
306
|
+
check "<root>5</root>", 5, 'xsd:long'
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_float
|
310
|
+
obj = 1.2
|
311
|
+
check <<-EOS, obj, 'xsd:float'
|
312
|
+
<root>1.2</root>
|
313
|
+
EOS
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_date
|
317
|
+
time_str = '2010-08-20T05:44:35.0Z'
|
318
|
+
obj = Time.parse(time_str)
|
319
|
+
check <<-EOS, obj, 'xsd:dateTime'
|
320
|
+
<root>#{time_str}</root>
|
321
|
+
EOS
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_array_mangling
|
325
|
+
obj = ["foo"]
|
326
|
+
check <<-EOS, obj, 'ArrayOfString'
|
327
|
+
<root><e>foo</e></root>
|
328
|
+
EOS
|
329
|
+
|
330
|
+
time_str = '2010-08-20T05:44:35.0Z'
|
331
|
+
obj = [Time.parse(time_str)]
|
332
|
+
check <<-EOS, obj, 'ArrayOfDateTime'
|
333
|
+
<root><e>#{time_str}</e></root>
|
334
|
+
EOS
|
335
|
+
|
336
|
+
obj = [1]
|
337
|
+
check <<-EOS, obj, 'ArrayOfAnyType'
|
338
|
+
<root xmlns:xsi="#{VIM::NS_XSI}">
|
339
|
+
<e xsi:type="xsd:int">1</e>
|
340
|
+
</root>
|
341
|
+
EOS
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_propertypath
|
345
|
+
check "<root>foo</root>", "foo", 'PropertyPath'
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_methodname
|
349
|
+
check "<root>foo</root>", "foo", 'MethodName'
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_typename
|
353
|
+
check "<root>foo</root>", "foo", 'TypeName'
|
354
|
+
end
|
355
|
+
|
356
|
+
def test_new_fields
|
357
|
+
obj = VIM::HostBlockHba(
|
358
|
+
:dynamicProperty => [],
|
359
|
+
:key => 'key-vim.host.BlockHba-vmhba0',
|
360
|
+
:device => 'vmhba0',
|
361
|
+
:bus => 0,
|
362
|
+
:status => 'unknown',
|
363
|
+
:model => 'Virtual Machine Chipset',
|
364
|
+
:driver => 'ata_piix',
|
365
|
+
:pci => '00:07.1')
|
366
|
+
|
367
|
+
check <<-EOS, obj, "HostBlockHba"
|
368
|
+
<hostBusAdapter xsi:type="HostBlockHba">
|
369
|
+
<key>key-vim.host.BlockHba-vmhba0</key>
|
370
|
+
<device>vmhba0</device>
|
371
|
+
<bus>0</bus>
|
372
|
+
<status>unknown</status>
|
373
|
+
<foo>bar</foo>
|
374
|
+
<model>Virtual Machine Chipset</model>
|
375
|
+
<driver>ata_piix</driver>
|
376
|
+
<pci>00:07.1</pci>
|
377
|
+
</hostBusAdapter>
|
378
|
+
EOS
|
379
|
+
end
|
295
380
|
end
|
data/test/test_emit_request.rb
CHANGED
data/test/test_exceptions.rb
CHANGED
data/test/test_helper.rb
ADDED
data/test/test_misc.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'rbvmomi'
|
3
|
-
VIM = RbVmomi::VIM unless Object.const_defined? :VIM
|
1
|
+
require 'test_helper'
|
4
2
|
|
5
3
|
class MiscTest < Test::Unit::TestCase
|
6
4
|
def test_overridden_const
|
@@ -16,5 +14,11 @@ class MiscTest < Test::Unit::TestCase
|
|
16
14
|
assert(VIM::ClusterAttemptedVmInfo < RbVmomi::BasicTypes::Base)
|
17
15
|
assert_equal 'ClusterAttemptedVmInfo', VIM::ClusterAttemptedVmInfo.wsdl_name
|
18
16
|
end
|
17
|
+
|
18
|
+
def test_loader
|
19
|
+
klass = VIM.loader.get('HostSystem')
|
20
|
+
klass2 = VIM::HostSystem
|
21
|
+
assert_equal klass, klass2
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
data/test/test_parse_response.rb
CHANGED
data/test/test_serialization.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
require '
|
2
|
-
require 'rbvmomi'
|
3
|
-
VIM = RbVmomi::VIM unless Object.const_defined? :VIM
|
1
|
+
require 'test_helper'
|
4
2
|
|
5
3
|
class SerializationTest < Test::Unit::TestCase
|
6
4
|
def check str, obj, type, array=false
|
7
|
-
|
5
|
+
conn = VIM.new(:ns => 'urn:vim25', :rev => '4.0')
|
8
6
|
xml = Builder::XmlMarkup.new :indent => 2
|
9
|
-
|
7
|
+
conn.obj2xml(xml, 'root', type, array, obj)
|
10
8
|
|
11
9
|
begin
|
12
10
|
assert_equal str, xml.target!
|
@@ -226,4 +224,18 @@ class SerializationTest < Test::Unit::TestCase
|
|
226
224
|
</root>
|
227
225
|
EOS
|
228
226
|
end
|
227
|
+
|
228
|
+
def test_datetime
|
229
|
+
obj = DateTime.new(2011, 11, 16, 13, 36, 8, Rational(-8,24))
|
230
|
+
check <<-EOS, obj, 'xsd:dateTime', false
|
231
|
+
<root>2011-11-16T13:36:08-08:00</root>
|
232
|
+
EOS
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_time
|
236
|
+
obj = Time.at DateTime.new(2011, 11, 16, 13, 36, 8, Rational(-8,24)).strftime("%s").to_i
|
237
|
+
check <<-EOS, obj, 'xsd:dateTime', false
|
238
|
+
<root>2011-11-16T13:36:08-08:00</root>
|
239
|
+
EOS
|
240
|
+
end
|
229
241
|
end
|