rbvmomi 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bin/rbvmomish +0 -0
- data/lib/rbvmomi/basic_types.rb +3 -2
- data/lib/rbvmomi/connection.rb +21 -8
- data/lib/rbvmomi/trivial_soap.rb +1 -1
- data/lib/rbvmomi/type_loader.rb +20 -0
- data/lib/rbvmomi/vim.rb +2 -6
- data/lib/rbvmomi/vim/OvfManager.rb +2 -2
- data/test/test_serialization.rb +54 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.1
|
data/bin/rbvmomish
CHANGED
File without changes
|
data/lib/rbvmomi/basic_types.rb
CHANGED
@@ -145,7 +145,8 @@ class DataObject < ObjectWithProperties
|
|
145
145
|
q.text '('
|
146
146
|
q.breakable
|
147
147
|
props = @props.sort_by { |k,v| k.to_s }
|
148
|
-
q.seplist props, nil, :each do |
|
148
|
+
q.seplist props, nil, :each do |e|
|
149
|
+
k, v = e
|
149
150
|
q.group do
|
150
151
|
q.text k.to_s
|
151
152
|
q.text ': '
|
@@ -337,7 +338,7 @@ class ::Float
|
|
337
338
|
end
|
338
339
|
|
339
340
|
class KeyValue
|
340
|
-
def self.wsdl_name; '
|
341
|
+
def self.wsdl_name; 'KeyValue' end
|
341
342
|
attr_accessor :key, :value
|
342
343
|
|
343
344
|
def initialize k, v
|
data/lib/rbvmomi/connection.rb
CHANGED
@@ -115,15 +115,15 @@ class Connection < TrivialSoap
|
|
115
115
|
# hic sunt dracones
|
116
116
|
def obj2xml xml, name, type, is_array, o, attrs={}
|
117
117
|
expected = type(type)
|
118
|
-
fail "expected array, got #{o.class.wsdl_name}" if is_array and not o.is_a? Array
|
118
|
+
fail "expected array, got #{o.class.wsdl_name}" if is_array and not (o.is_a? Array or (o.is_a? Hash and expected == BasicTypes::KeyValue))
|
119
119
|
case o
|
120
120
|
when Array, BasicTypes::KeyValue
|
121
121
|
if o.is_a? BasicTypes::KeyValue and expected != BasicTypes::KeyValue
|
122
122
|
fail "expected #{expected.wsdl_name}, got KeyValue"
|
123
|
-
elsif expected == BasicTypes::KeyValue
|
123
|
+
elsif expected == BasicTypes::KeyValue and not is_array
|
124
124
|
xml.tag! name, attrs do
|
125
|
-
xml.tag! 'key', o[0]
|
126
|
-
xml.tag! 'value', o[1]
|
125
|
+
xml.tag! 'key', o[0].to_s
|
126
|
+
xml.tag! 'value', o[1].to_s
|
127
127
|
end
|
128
128
|
else
|
129
129
|
fail "expected #{expected.wsdl_name}, got array" unless is_array
|
@@ -148,8 +148,12 @@ class Connection < TrivialSoap
|
|
148
148
|
when BasicTypes::Enum
|
149
149
|
xml.tag! name, o.value.to_s, attrs
|
150
150
|
when Hash
|
151
|
-
|
152
|
-
|
151
|
+
if expected == BasicTypes::KeyValue and is_array
|
152
|
+
obj2xml xml, name, type, is_array, o.to_a, attrs
|
153
|
+
else
|
154
|
+
fail "expected #{expected.wsdl_name}, got a hash" unless expected <= BasicTypes::DataObject
|
155
|
+
obj2xml xml, name, type, false, expected.new(o), attrs
|
156
|
+
end
|
153
157
|
when true, false
|
154
158
|
fail "expected #{expected.wsdl_name}, got a boolean" unless [BasicTypes::Boolean, BasicTypes::AnyType].member? expected
|
155
159
|
attrs['xsi:type'] = 'xsd:boolean' if expected == BasicTypes::AnyType
|
@@ -208,8 +212,17 @@ class Connection < TrivialSoap
|
|
208
212
|
self.class.type name
|
209
213
|
end
|
210
214
|
|
211
|
-
def self.
|
212
|
-
|
215
|
+
def self.extension_dirs
|
216
|
+
@extension_dirs ||= []
|
217
|
+
end
|
218
|
+
|
219
|
+
def self.add_extension_dir dir
|
220
|
+
extension_dirs << dir
|
221
|
+
@loader.reload_extensions_dir dir if @loader
|
222
|
+
end
|
223
|
+
|
224
|
+
def self.reload_extensions
|
225
|
+
@loader.reload_extensions
|
213
226
|
end
|
214
227
|
|
215
228
|
def self.loader; @loader; end
|
data/lib/rbvmomi/trivial_soap.rb
CHANGED
@@ -49,7 +49,7 @@ class RbVmomi::TrivialSoap
|
|
49
49
|
end
|
50
50
|
@http.set_debug_output(STDERR) if $DEBUG
|
51
51
|
@http.read_timeout = 1000000
|
52
|
-
@http.open_timeout =
|
52
|
+
@http.open_timeout = 60
|
53
53
|
def @http.on_connect
|
54
54
|
@socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
55
55
|
end
|
data/lib/rbvmomi/type_loader.rb
CHANGED
@@ -25,6 +25,26 @@ class TypeLoader
|
|
25
25
|
names.each { |x| get(x) }
|
26
26
|
end
|
27
27
|
|
28
|
+
# Reload all extensions for loaded VMODL types
|
29
|
+
def reload_extensions
|
30
|
+
@extension_dirs.each do |path|
|
31
|
+
reload_extensions_dir path
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Reload all extensions for loaded VMODL types from the given directory
|
36
|
+
def reload_extensions_dir path
|
37
|
+
loaded = Set.new(typenames.select { |x| @namespace.const_defined? x })
|
38
|
+
Dir.open(path) do |dir|
|
39
|
+
dir.each do |file|
|
40
|
+
next unless file =~ /\.rb$/
|
41
|
+
next unless loaded.member? $`
|
42
|
+
file_path = File.join(dir, file)
|
43
|
+
load file_path
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
28
48
|
def has? name
|
29
49
|
fail unless name.is_a? String
|
30
50
|
@db.member?(name) or BasicTypes::BUILTIN.member?(name)
|
data/lib/rbvmomi/vim.rb
CHANGED
@@ -86,12 +86,8 @@ class VIM < Connection
|
|
86
86
|
pp.text "VIM(#{@opts[:host]})"
|
87
87
|
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
# Directories to search for extensions
|
92
|
-
def self.extension_dirs
|
93
|
-
@extension_dirs
|
94
|
-
end
|
89
|
+
add_extension_dir File.join(File.dirname(__FILE__), "vim")
|
90
|
+
(ENV['RBVMOMI_VIM_EXTENSION_PATH']||'').split(':').each { |dir| add_extension_dir dir }
|
95
91
|
|
96
92
|
load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../vmodl.db"))
|
97
93
|
end
|
@@ -31,7 +31,7 @@ class RbVmomi::VIM::OvfManager
|
|
31
31
|
:entityName => opts[:vmName],
|
32
32
|
:deploymentOption => "",
|
33
33
|
:networkMapping => opts[:networkMappings].map{|from, to| RbVmomi::VIM::OvfNetworkMapping(:name => from, :network => to)},
|
34
|
-
:propertyMapping => opts[:propertyMappings].
|
34
|
+
:propertyMapping => opts[:propertyMappings].to_a,
|
35
35
|
:diskProvisioning => opts[:diskProvisioning]
|
36
36
|
)
|
37
37
|
|
@@ -101,7 +101,7 @@ class RbVmomi::VIM::OvfManager
|
|
101
101
|
vm
|
102
102
|
end
|
103
103
|
rescue Exception
|
104
|
-
nfcLease.HttpNfcLeaseAbort if nfcLease
|
104
|
+
(nfcLease.HttpNfcLeaseAbort rescue nil) if nfcLease
|
105
105
|
raise
|
106
106
|
end
|
107
107
|
end
|
data/test/test_serialization.rb
CHANGED
@@ -221,6 +221,60 @@ class SerializationTest < Test::Unit::TestCase
|
|
221
221
|
<root>
|
222
222
|
<key>a</key>
|
223
223
|
<value>b</value>
|
224
|
+
</root>
|
225
|
+
EOS
|
226
|
+
|
227
|
+
obj = [['a', 'b'], ['c', 'd']]
|
228
|
+
check <<-EOS, obj, 'KeyValue', true
|
229
|
+
<root>
|
230
|
+
<key>a</key>
|
231
|
+
<value>b</value>
|
232
|
+
</root>
|
233
|
+
<root>
|
234
|
+
<key>c</key>
|
235
|
+
<value>d</value>
|
236
|
+
</root>
|
237
|
+
EOS
|
238
|
+
|
239
|
+
obj = { 'a' => 'b', :c => 'd' }
|
240
|
+
check <<-EOS, obj, 'KeyValue', true
|
241
|
+
<root>
|
242
|
+
<key>a</key>
|
243
|
+
<value>b</value>
|
244
|
+
</root>
|
245
|
+
<root>
|
246
|
+
<key>c</key>
|
247
|
+
<value>d</value>
|
248
|
+
</root>
|
249
|
+
EOS
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_ovf_import_spec_params
|
253
|
+
obj = RbVmomi::VIM::OvfCreateImportSpecParams(
|
254
|
+
:hostSystem => VIM::HostSystem(nil, "myhost"),
|
255
|
+
:locale => "US",
|
256
|
+
:entityName => "myvm",
|
257
|
+
:deploymentOption => "",
|
258
|
+
:networkMapping => [],
|
259
|
+
:propertyMapping => [['a', 'b'], ['c', 'd']],
|
260
|
+
:diskProvisioning => :thin
|
261
|
+
)
|
262
|
+
|
263
|
+
check <<-EOS, obj, 'OvfCreateImportSpecParams', false
|
264
|
+
<root xsi:type="OvfCreateImportSpecParams">
|
265
|
+
<locale>US</locale>
|
266
|
+
<deploymentOption></deploymentOption>
|
267
|
+
<entityName>myvm</entityName>
|
268
|
+
<hostSystem type="HostSystem">myhost</hostSystem>
|
269
|
+
<propertyMapping>
|
270
|
+
<key>a</key>
|
271
|
+
<value>b</value>
|
272
|
+
</propertyMapping>
|
273
|
+
<propertyMapping>
|
274
|
+
<key>c</key>
|
275
|
+
<value>d</value>
|
276
|
+
</propertyMapping>
|
277
|
+
<diskProvisioning>thin</diskProvisioning>
|
224
278
|
</root>
|
225
279
|
EOS
|
226
280
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rbvmomi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.5.
|
5
|
+
version: 1.5.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Rich Lane
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2012-03-12 00:00:00 -07:00
|
14
14
|
default_executable: rbvmomish
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|