rbvmomi2 3.0.0 → 3.0.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.
- checksums.yaml +4 -4
- data/README.md +11 -25
- data/exe/rbvmomish +50 -48
- data/lib/rbvmomi/basic_types.rb +318 -294
- data/lib/rbvmomi/connection.rb +221 -216
- data/lib/rbvmomi/deserialization.rb +201 -205
- data/lib/rbvmomi/fault.rb +10 -9
- data/lib/rbvmomi/optimist.rb +51 -50
- data/lib/rbvmomi/pbm.rb +52 -50
- data/lib/rbvmomi/sms/SmsStorageManager.rb +2 -1
- data/lib/rbvmomi/sms.rb +48 -46
- data/lib/rbvmomi/sso.rb +13 -18
- data/lib/rbvmomi/trivial_soap.rb +9 -8
- data/lib/rbvmomi/type_loader.rb +100 -101
- data/lib/rbvmomi/utils/admission_control.rb +90 -106
- data/lib/rbvmomi/utils/deploy.rb +77 -85
- data/lib/rbvmomi/utils/leases.rb +31 -33
- data/lib/rbvmomi/utils/perfdump.rb +177 -207
- data/lib/rbvmomi/version.rb +2 -1
- data/lib/rbvmomi/vim/ComputeResource.rb +17 -15
- data/lib/rbvmomi/vim/Datacenter.rb +1 -0
- data/lib/rbvmomi/vim/Datastore.rb +18 -15
- data/lib/rbvmomi/vim/DynamicTypeMgrAllTypeInfo.rb +7 -6
- data/lib/rbvmomi/vim/DynamicTypeMgrDataTypeInfo.rb +3 -2
- data/lib/rbvmomi/vim/DynamicTypeMgrManagedTypeInfo.rb +7 -6
- data/lib/rbvmomi/vim/Folder.rb +37 -33
- data/lib/rbvmomi/vim/HostSystem.rb +139 -136
- data/lib/rbvmomi/vim/ManagedEntity.rb +15 -14
- data/lib/rbvmomi/vim/ManagedObject.rb +11 -10
- data/lib/rbvmomi/vim/ObjectContent.rb +3 -1
- data/lib/rbvmomi/vim/ObjectUpdate.rb +3 -1
- data/lib/rbvmomi/vim/OvfManager.rb +50 -57
- data/lib/rbvmomi/vim/PerfCounterInfo.rb +4 -3
- data/lib/rbvmomi/vim/PerformanceManager.rb +28 -31
- data/lib/rbvmomi/vim/PropertyCollector.rb +8 -7
- data/lib/rbvmomi/vim/ReflectManagedMethodExecuter.rb +22 -21
- data/lib/rbvmomi/vim/ResourcePool.rb +19 -18
- data/lib/rbvmomi/vim/ServiceInstance.rb +8 -7
- data/lib/rbvmomi/vim/Task.rb +6 -5
- data/lib/rbvmomi/vim/VirtualMachine.rb +8 -7
- data/lib/rbvmomi/vim.rb +112 -129
- data/lib/rbvmomi.rb +1 -0
- metadata +54 -10
data/lib/rbvmomi/connection.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
|
2
3
|
# SPDX-License-Identifier: MIT
|
3
4
|
|
@@ -11,262 +12,266 @@ require_relative 'deserialization'
|
|
11
12
|
|
12
13
|
module RbVmomi
|
13
14
|
|
14
|
-
IS_JRUBY = RUBY_PLATFORM == 'java'
|
15
|
+
IS_JRUBY = RUBY_PLATFORM == 'java'
|
15
16
|
|
16
|
-
class DeserializationFailed < Exception; end
|
17
|
+
class DeserializationFailed < Exception; end
|
17
18
|
|
18
|
-
class Connection < TrivialSoap
|
19
|
-
|
19
|
+
class Connection < TrivialSoap
|
20
|
+
NS_XSI = 'http://www.w3.org/2001/XMLSchema-instance'
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
attr_accessor :rev
|
23
|
+
attr_reader :profile
|
24
|
+
attr_reader :profile_summary
|
25
|
+
attr_accessor :profiling
|
26
|
+
attr_reader :deserializer
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
def initialize opts
|
29
|
+
@ns = opts[:ns] or raise 'no namespace specified'
|
30
|
+
@rev = opts[:rev] or raise 'no revision specified'
|
31
|
+
@deserializer = Deserializer.new self
|
32
|
+
reset_profiling
|
33
|
+
@profiling = false
|
34
|
+
super opts
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
def reset_profiling
|
38
|
+
@profile = {}
|
39
|
+
@profile_summary = {network_latency: 0, request_emit: 0, response_parse: 0, num_calls: 0}
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
42
|
+
def emit_request xml, method, descs, this, params
|
43
|
+
xml.tag! method, xmlns: @ns do
|
44
|
+
obj2xml xml, '_this', 'ManagedObject', false, this
|
45
|
+
descs.each do |d|
|
46
|
+
k = d['name']
|
47
|
+
k = k.to_sym if !params.member?(k) && params.member?(k.to_sym)
|
48
|
+
v = params[k]
|
49
|
+
if not v == nil
|
50
|
+
obj2xml xml, d['name'], d['wsdl_type'], d['is-array'], v
|
51
|
+
else
|
52
|
+
raise "missing required parameter #{d['name']}" unless d['is-optional']
|
53
|
+
end
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
55
|
-
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
else
|
68
|
-
if desc
|
69
|
-
type = desc['is-task'] ? 'Task' : desc['wsdl_type']
|
70
|
-
returnvals = resp.children.select(&:element?).map { |c| @deserializer.deserialize c, type }
|
71
|
-
(desc['is-array'] && !desc['is-task']) ? returnvals : returnvals.first
|
58
|
+
def parse_response resp, desc
|
59
|
+
if resp.at('faultcode')
|
60
|
+
detail = resp.at('detail')
|
61
|
+
fault = detail && @deserializer.deserialize(detail.children.first, 'MethodFault')
|
62
|
+
msg = resp.at('faultstring').text
|
63
|
+
if fault
|
64
|
+
raise RbVmomi::Fault.new(msg, fault)
|
65
|
+
else
|
66
|
+
raise "#{resp.at('faultcode').text}: #{msg}"
|
67
|
+
end
|
72
68
|
else
|
73
|
-
|
69
|
+
if desc
|
70
|
+
type = desc['is-task'] ? 'Task' : desc['wsdl_type']
|
71
|
+
returnvals = resp.children.select(&:element?).map { |c| @deserializer.deserialize c, type }
|
72
|
+
(desc['is-array'] && !desc['is-task']) ? returnvals : returnvals.first
|
73
|
+
else
|
74
|
+
nil
|
75
|
+
end
|
74
76
|
end
|
75
77
|
end
|
76
|
-
end
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
79
|
+
def call method, desc, this, params
|
80
|
+
raise 'this is not a managed object' unless this.is_a? BasicTypes::ManagedObject
|
81
|
+
raise 'parameters must be passed as a hash' unless params.is_a? Hash
|
82
|
+
raise unless desc.is_a? Hash
|
83
|
+
|
84
|
+
t1 = Time.now
|
85
|
+
body = soap_envelope do |xml|
|
86
|
+
emit_request xml, method, desc['params'], this, params
|
87
|
+
end.target!
|
88
|
+
|
89
|
+
t2 = Time.now
|
90
|
+
resp, resp_size = request "#{@ns}/#{@rev}", body
|
91
|
+
|
92
|
+
t3 = Time.now
|
93
|
+
out = parse_response resp, desc['result']
|
94
|
+
|
95
|
+
if @profiling
|
96
|
+
t4 = Time.now
|
97
|
+
@profile[method] ||= []
|
98
|
+
profile_info = {
|
99
|
+
network_latency: (t3 - t2),
|
100
|
+
request_emit: t2 - t1,
|
101
|
+
response_parse: t4 - t3,
|
102
|
+
params: params,
|
103
|
+
obj: this,
|
104
|
+
backtrace: caller,
|
105
|
+
request_size: body.length,
|
106
|
+
response_size: resp_size,
|
107
|
+
}
|
108
|
+
@profile[method] << profile_info
|
109
|
+
@profile_summary[:network_latency] += profile_info[:network_latency]
|
110
|
+
@profile_summary[:response_parse] += profile_info[:response_parse]
|
111
|
+
@profile_summary[:request_emit] += profile_info[:request_emit]
|
112
|
+
@profile_summary[:num_calls] += 1
|
113
|
+
end
|
114
|
+
|
115
|
+
out
|
112
116
|
end
|
113
117
|
|
114
|
-
|
115
|
-
|
118
|
+
# hic sunt dracones
|
119
|
+
def obj2xml xml, name, type, is_array, o, attrs={}
|
120
|
+
expected = type(type)
|
121
|
+
raise "expected array for '#{name}', got #{o.class.wsdl_name}" if is_array and not (o.is_a? Array or (o.is_a? Hash and expected == BasicTypes::KeyValue))
|
116
122
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
o.each do |e|
|
133
|
-
obj2xml xml, name, expected.wsdl_name, false, e, attrs
|
123
|
+
case o
|
124
|
+
when Array, BasicTypes::KeyValue
|
125
|
+
if o.is_a? BasicTypes::KeyValue and expected != BasicTypes::KeyValue
|
126
|
+
raise "expected #{expected.wsdl_name} for '#{name}', got KeyValue"
|
127
|
+
elsif expected == BasicTypes::KeyValue and not is_array
|
128
|
+
xml.tag! name, attrs do
|
129
|
+
xml.tag! 'key', o[0].to_s
|
130
|
+
xml.tag! 'value', o[1].to_s
|
131
|
+
end
|
132
|
+
else
|
133
|
+
raise "expected #{expected.wsdl_name} for '#{name}', got array" unless is_array
|
134
|
+
|
135
|
+
o.each do |e|
|
136
|
+
obj2xml xml, name, expected.wsdl_name, false, e, attrs
|
137
|
+
end
|
134
138
|
end
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
139
|
+
when BasicTypes::ManagedObject
|
140
|
+
raise "expected #{expected.wsdl_name} for '#{name}', got #{o.class.wsdl_name} for field #{name.inspect}" if expected and not expected >= o.class and not expected == BasicTypes::AnyType
|
141
|
+
|
142
|
+
xml.tag! name, o._ref, type: o.class.wsdl_name
|
143
|
+
when BasicTypes::DataObject
|
144
|
+
raise "expected #{expected.wsdl_name} for '#{name}', got #{o.class.wsdl_name} for field #{name.inspect}" if expected and not expected >= o.class and not expected == BasicTypes::AnyType
|
145
|
+
|
146
|
+
xml.tag! name, attrs.merge('xsi:type' => o.class.wsdl_name) do
|
147
|
+
o.class.full_props_desc.each do |desc|
|
148
|
+
if o.props.member? desc['name'].to_sym
|
149
|
+
v = o.props[desc['name'].to_sym]
|
150
|
+
next if v.nil?
|
151
|
+
|
152
|
+
obj2xml xml, desc['name'], desc['wsdl_type'], desc['is-array'], v
|
153
|
+
end
|
149
154
|
end
|
150
155
|
end
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
156
|
+
when BasicTypes::Enum
|
157
|
+
xml.tag! name, o.value.to_s, attrs
|
158
|
+
when Hash
|
159
|
+
if expected == BasicTypes::KeyValue and is_array
|
160
|
+
obj2xml xml, name, type, is_array, o.to_a, attrs
|
161
|
+
else
|
162
|
+
raise "expected #{expected.wsdl_name} for '#{name}', got a hash" unless expected <= BasicTypes::DataObject
|
163
|
+
|
164
|
+
obj2xml xml, name, type, false, expected.new(o), attrs
|
165
|
+
end
|
166
|
+
when true, false
|
167
|
+
raise "expected #{expected.wsdl_name} for '#{name}', got a boolean" unless [BasicTypes::Boolean, BasicTypes::AnyType].member? expected
|
168
|
+
|
169
|
+
attrs['xsi:type'] = 'xsd:boolean' if expected == BasicTypes::AnyType
|
170
|
+
xml.tag! name, (o ? '1' : '0'), attrs
|
171
|
+
when Symbol, String
|
172
|
+
if expected == BasicTypes::Binary
|
173
|
+
attrs['xsi:type'] = 'xsd:base64Binary' if expected == BasicTypes::AnyType
|
174
|
+
xml.tag! name, [o].pack('m').chomp.gsub("\n", ''), attrs
|
175
|
+
else
|
176
|
+
attrs['xsi:type'] = 'xsd:string' if expected == BasicTypes::AnyType
|
177
|
+
xml.tag! name, o.to_s, attrs
|
178
|
+
end
|
179
|
+
when Integer
|
180
|
+
attrs['xsi:type'] = 'xsd:long' if expected == BasicTypes::AnyType
|
181
|
+
xml.tag! name, o.to_s, attrs
|
182
|
+
when Float
|
183
|
+
attrs['xsi:type'] = 'xsd:double' if expected == BasicTypes::AnyType
|
171
184
|
xml.tag! name, o.to_s, attrs
|
185
|
+
when DateTime
|
186
|
+
attrs['xsi:type'] = 'xsd:dateTime' if expected == BasicTypes::AnyType
|
187
|
+
xml.tag! name, o.strftime('%FT%T%:z'), attrs
|
188
|
+
when Time
|
189
|
+
attrs['xsi:type'] = 'xsd:dateTime' if expected == BasicTypes::AnyType
|
190
|
+
xml.tag! name, o.iso8601, attrs
|
191
|
+
when BasicTypes::Int
|
192
|
+
attrs['xsi:type'] = 'xsd:int'
|
193
|
+
xml.tag! name, o.to_s, attrs
|
194
|
+
else raise "unexpected object class #{o.class} for '#{name}'"
|
172
195
|
end
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
xml.tag! name, o.to_s, attrs
|
179
|
-
when DateTime
|
180
|
-
attrs['xsi:type'] = 'xsd:dateTime' if expected == BasicTypes::AnyType
|
181
|
-
xml.tag! name, o.strftime('%FT%T%:z'), attrs
|
182
|
-
when Time
|
183
|
-
attrs['xsi:type'] = 'xsd:dateTime' if expected == BasicTypes::AnyType
|
184
|
-
xml.tag! name, o.iso8601, attrs
|
185
|
-
when BasicTypes::Int
|
186
|
-
attrs['xsi:type'] = 'xsd:int'
|
187
|
-
xml.tag! name, o.to_s, attrs
|
188
|
-
else fail "unexpected object class #{o.class} for '#{name}'"
|
196
|
+
xml
|
197
|
+
rescue
|
198
|
+
$stderr.puts "#{$!.class} while serializing #{name} (#{type}):"
|
199
|
+
PP.pp o, $stderr
|
200
|
+
raise
|
189
201
|
end
|
190
|
-
xml
|
191
|
-
rescue
|
192
|
-
$stderr.puts "#{$!.class} while serializing #{name} (#{type}):"
|
193
|
-
PP.pp o, $stderr
|
194
|
-
raise
|
195
|
-
end
|
196
202
|
|
197
|
-
|
198
|
-
|
199
|
-
name = $' if name.to_s =~ /^xsd:/
|
200
|
-
case name.to_sym
|
201
|
-
when :anyType then BasicTypes::AnyType
|
202
|
-
when :boolean then BasicTypes::Boolean
|
203
|
-
when :string then String
|
204
|
-
when :int, :long, :short, :byte then Integer
|
205
|
-
when :float, :double then Float
|
206
|
-
when :dateTime then Time
|
207
|
-
when :base64Binary then BasicTypes::Binary
|
208
|
-
when :KeyValue then BasicTypes::KeyValue
|
209
|
-
else
|
210
|
-
first_char = name[0].chr
|
211
|
-
if first_char.downcase == first_char
|
212
|
-
name = "%s%s" % [first_char.upcase, name[1..-1]]
|
213
|
-
end
|
203
|
+
def self.type name
|
204
|
+
raise unless name and (name.is_a? String or name.is_a? Symbol)
|
214
205
|
|
215
|
-
if
|
216
|
-
|
206
|
+
name = $' if name.to_s =~ /^xsd:/
|
207
|
+
case name.to_sym
|
208
|
+
when :anyType then BasicTypes::AnyType
|
209
|
+
when :boolean then BasicTypes::Boolean
|
210
|
+
when :string then String
|
211
|
+
when :int, :long, :short, :byte then Integer
|
212
|
+
when :float, :double then Float
|
213
|
+
when :dateTime then Time
|
214
|
+
when :base64Binary then BasicTypes::Binary
|
215
|
+
when :KeyValue then BasicTypes::KeyValue
|
217
216
|
else
|
218
|
-
|
217
|
+
first_char = name[0].chr
|
218
|
+
name = '%s%s' % [first_char.upcase, name[1..-1]] if first_char.downcase == first_char
|
219
|
+
|
220
|
+
if @loader.has? name
|
221
|
+
const_get(name)
|
222
|
+
else
|
223
|
+
raise "no such type #{name.inspect}"
|
224
|
+
end
|
219
225
|
end
|
220
226
|
end
|
221
|
-
end
|
222
227
|
|
223
|
-
|
224
|
-
|
225
|
-
|
228
|
+
def type name
|
229
|
+
self.class.type name
|
230
|
+
end
|
226
231
|
|
227
|
-
|
228
|
-
|
229
|
-
|
232
|
+
def instanceUuid
|
233
|
+
nil
|
234
|
+
end
|
230
235
|
|
231
|
-
|
232
|
-
|
233
|
-
|
236
|
+
def self.extension_dirs
|
237
|
+
@extension_dirs ||= []
|
238
|
+
end
|
234
239
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
240
|
+
def self.add_extension_dir dir
|
241
|
+
extension_dirs << dir
|
242
|
+
@loader.reload_extensions_dir dir if @loader
|
243
|
+
end
|
239
244
|
|
240
|
-
|
241
|
-
|
242
|
-
|
245
|
+
def self.reload_extensions
|
246
|
+
@loader.reload_extensions
|
247
|
+
end
|
243
248
|
|
244
|
-
|
249
|
+
def self.loader; @loader; end
|
245
250
|
|
246
|
-
protected
|
251
|
+
protected
|
247
252
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
253
|
+
def self.const_missing sym
|
254
|
+
name = sym.to_s
|
255
|
+
if @loader and @loader.has? name
|
256
|
+
@loader.get(name)
|
257
|
+
else
|
258
|
+
super
|
259
|
+
end
|
254
260
|
end
|
255
|
-
end
|
256
261
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
262
|
+
def self.method_missing sym, *a
|
263
|
+
name = sym.to_s
|
264
|
+
if @loader and @loader.has? name
|
265
|
+
@loader.get(name).new(*a)
|
266
|
+
else
|
267
|
+
super
|
268
|
+
end
|
263
269
|
end
|
264
|
-
end
|
265
270
|
|
266
|
-
|
267
|
-
|
268
|
-
|
271
|
+
def self.load_vmodl fn
|
272
|
+
@loader = RbVmomi::TypeLoader.new fn, extension_dirs, self
|
273
|
+
nil
|
274
|
+
end
|
269
275
|
end
|
270
|
-
end
|
271
276
|
|
272
277
|
end
|