rbvmomi2 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -25
  3. data/exe/rbvmomish +50 -48
  4. data/lib/rbvmomi/basic_types.rb +318 -294
  5. data/lib/rbvmomi/connection.rb +221 -216
  6. data/lib/rbvmomi/deserialization.rb +201 -205
  7. data/lib/rbvmomi/fault.rb +10 -9
  8. data/lib/rbvmomi/optimist.rb +51 -50
  9. data/lib/rbvmomi/pbm.rb +52 -50
  10. data/lib/rbvmomi/sms/SmsStorageManager.rb +2 -1
  11. data/lib/rbvmomi/sms.rb +48 -46
  12. data/lib/rbvmomi/sso.rb +13 -18
  13. data/lib/rbvmomi/trivial_soap.rb +9 -8
  14. data/lib/rbvmomi/type_loader.rb +100 -101
  15. data/lib/rbvmomi/utils/admission_control.rb +90 -106
  16. data/lib/rbvmomi/utils/deploy.rb +77 -85
  17. data/lib/rbvmomi/utils/leases.rb +31 -33
  18. data/lib/rbvmomi/utils/perfdump.rb +177 -207
  19. data/lib/rbvmomi/version.rb +2 -1
  20. data/lib/rbvmomi/vim/ComputeResource.rb +17 -15
  21. data/lib/rbvmomi/vim/Datacenter.rb +1 -0
  22. data/lib/rbvmomi/vim/Datastore.rb +18 -15
  23. data/lib/rbvmomi/vim/DynamicTypeMgrAllTypeInfo.rb +7 -6
  24. data/lib/rbvmomi/vim/DynamicTypeMgrDataTypeInfo.rb +3 -2
  25. data/lib/rbvmomi/vim/DynamicTypeMgrManagedTypeInfo.rb +7 -6
  26. data/lib/rbvmomi/vim/Folder.rb +37 -33
  27. data/lib/rbvmomi/vim/HostSystem.rb +139 -136
  28. data/lib/rbvmomi/vim/ManagedEntity.rb +15 -14
  29. data/lib/rbvmomi/vim/ManagedObject.rb +11 -10
  30. data/lib/rbvmomi/vim/ObjectContent.rb +3 -1
  31. data/lib/rbvmomi/vim/ObjectUpdate.rb +3 -1
  32. data/lib/rbvmomi/vim/OvfManager.rb +50 -57
  33. data/lib/rbvmomi/vim/PerfCounterInfo.rb +4 -3
  34. data/lib/rbvmomi/vim/PerformanceManager.rb +28 -31
  35. data/lib/rbvmomi/vim/PropertyCollector.rb +8 -7
  36. data/lib/rbvmomi/vim/ReflectManagedMethodExecuter.rb +22 -21
  37. data/lib/rbvmomi/vim/ResourcePool.rb +19 -18
  38. data/lib/rbvmomi/vim/ServiceInstance.rb +8 -7
  39. data/lib/rbvmomi/vim/Task.rb +6 -5
  40. data/lib/rbvmomi/vim/VirtualMachine.rb +8 -7
  41. data/lib/rbvmomi/vim.rb +112 -129
  42. data/lib/rbvmomi.rb +1 -0
  43. metadata +54 -10
@@ -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
- NS_XSI = 'http://www.w3.org/2001/XMLSchema-instance'
19
+ class Connection < TrivialSoap
20
+ NS_XSI = 'http://www.w3.org/2001/XMLSchema-instance'
20
21
 
21
- attr_accessor :rev
22
- attr_reader :profile
23
- attr_reader :profile_summary
24
- attr_accessor :profiling
25
- attr_reader :deserializer
22
+ attr_accessor :rev
23
+ attr_reader :profile
24
+ attr_reader :profile_summary
25
+ attr_accessor :profiling
26
+ attr_reader :deserializer
26
27
 
27
- def initialize opts
28
- @ns = opts[:ns] or fail "no namespace specified"
29
- @rev = opts[:rev] or fail "no revision specified"
30
- @deserializer = Deserializer.new self
31
- reset_profiling
32
- @profiling = false
33
- super opts
34
- end
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
- def reset_profiling
37
- @profile = {}
38
- @profile_summary = {:network_latency => 0, :request_emit => 0, :response_parse => 0, :num_calls => 0}
39
- end
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
- def emit_request xml, method, descs, this, params
42
- xml.tag! method, :xmlns => @ns do
43
- obj2xml xml, '_this', 'ManagedObject', false, this
44
- descs.each do |d|
45
- k = d['name']
46
- k = k.to_sym if !params.member?(k) && params.member?(k.to_sym)
47
- v = params[k]
48
- if not v == nil
49
- obj2xml xml, d['name'], d['wsdl_type'], d['is-array'], v
50
- else
51
- fail "missing required parameter #{d['name']}" unless d['is-optional']
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
- def parse_response resp, desc
58
- if resp.at('faultcode')
59
- detail = resp.at('detail')
60
- fault = detail && @deserializer.deserialize(detail.children.first, 'MethodFault')
61
- msg = resp.at('faultstring').text
62
- if fault
63
- raise RbVmomi::Fault.new(msg, fault)
64
- else
65
- fail "#{resp.at('faultcode').text}: #{msg}"
66
- end
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
- nil
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
- def call method, desc, this, params
79
- fail "this is not a managed object" unless this.is_a? BasicTypes::ManagedObject
80
- fail "parameters must be passed as a hash" unless params.is_a? Hash
81
- fail unless desc.is_a? Hash
82
-
83
- t1 = Time.now
84
- body = soap_envelope do |xml|
85
- emit_request xml, method, desc['params'], this, params
86
- end.target!
87
-
88
- t2 = Time.now
89
- resp, resp_size = request "#{@ns}/#{@rev}", body
90
-
91
- t3 = Time.now
92
- out = parse_response resp, desc['result']
93
-
94
- if @profiling
95
- t4 = Time.now
96
- @profile[method] ||= []
97
- profile_info = {
98
- :network_latency => (t3 - t2),
99
- :request_emit => t2 - t1,
100
- :response_parse => t4 - t3,
101
- :params => params,
102
- :obj => this,
103
- :backtrace => caller,
104
- :request_size => body.length,
105
- :response_size => resp_size,
106
- }
107
- @profile[method] << profile_info
108
- @profile_summary[:network_latency] += profile_info[:network_latency]
109
- @profile_summary[:response_parse] += profile_info[:response_parse]
110
- @profile_summary[:request_emit] += profile_info[:request_emit]
111
- @profile_summary[:num_calls] += 1
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
- out
115
- end
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
- # hic sunt dracones
118
- def obj2xml xml, name, type, is_array, o, attrs={}
119
- expected = type(type)
120
- fail "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))
121
- case o
122
- when Array, BasicTypes::KeyValue
123
- if o.is_a? BasicTypes::KeyValue and expected != BasicTypes::KeyValue
124
- fail "expected #{expected.wsdl_name} for '#{name}', got KeyValue"
125
- elsif expected == BasicTypes::KeyValue and not is_array
126
- xml.tag! name, attrs do
127
- xml.tag! 'key', o[0].to_s
128
- xml.tag! 'value', o[1].to_s
129
- end
130
- else
131
- fail "expected #{expected.wsdl_name} for '#{name}', got array" unless is_array
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
- end
136
- when BasicTypes::ManagedObject
137
- fail "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
138
- xml.tag! name, o._ref, :type => o.class.wsdl_name
139
- when BasicTypes::DataObject
140
- if expected and not expected >= o.class and not expected == BasicTypes::AnyType
141
- fail "expected #{expected.wsdl_name} for '#{name}', got #{o.class.wsdl_name} for field #{name.inspect}"
142
- end
143
- xml.tag! name, attrs.merge("xsi:type" => o.class.wsdl_name) do
144
- o.class.full_props_desc.each do |desc|
145
- if o.props.member? desc['name'].to_sym
146
- v = o.props[desc['name'].to_sym]
147
- next if v.nil?
148
- obj2xml xml, desc['name'], desc['wsdl_type'], desc['is-array'], v
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
- end
152
- when BasicTypes::Enum
153
- xml.tag! name, o.value.to_s, attrs
154
- when Hash
155
- if expected == BasicTypes::KeyValue and is_array
156
- obj2xml xml, name, type, is_array, o.to_a, attrs
157
- else
158
- fail "expected #{expected.wsdl_name} for '#{name}', got a hash" unless expected <= BasicTypes::DataObject
159
- obj2xml xml, name, type, false, expected.new(o), attrs
160
- end
161
- when true, false
162
- fail "expected #{expected.wsdl_name} for '#{name}', got a boolean" unless [BasicTypes::Boolean, BasicTypes::AnyType].member? expected
163
- attrs['xsi:type'] = 'xsd:boolean' if expected == BasicTypes::AnyType
164
- xml.tag! name, (o ? '1' : '0'), attrs
165
- when Symbol, String
166
- if expected == BasicTypes::Binary
167
- attrs['xsi:type'] = 'xsd:base64Binary' if expected == BasicTypes::AnyType
168
- xml.tag! name, [o].pack('m').chomp.gsub("\n", ""), attrs
169
- else
170
- attrs['xsi:type'] = 'xsd:string' if expected == BasicTypes::AnyType
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
- when Integer
174
- attrs['xsi:type'] = 'xsd:long' if expected == BasicTypes::AnyType
175
- xml.tag! name, o.to_s, attrs
176
- when Float
177
- attrs['xsi:type'] = 'xsd:double' if expected == BasicTypes::AnyType
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
- def self.type name
198
- fail unless name and (name.is_a? String or name.is_a? Symbol)
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 @loader.has? name
216
- const_get(name)
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
- fail "no such type #{name.inspect}"
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
- def type name
224
- self.class.type name
225
- end
228
+ def type name
229
+ self.class.type name
230
+ end
226
231
 
227
- def instanceUuid
228
- nil
229
- end
232
+ def instanceUuid
233
+ nil
234
+ end
230
235
 
231
- def self.extension_dirs
232
- @extension_dirs ||= []
233
- end
236
+ def self.extension_dirs
237
+ @extension_dirs ||= []
238
+ end
234
239
 
235
- def self.add_extension_dir dir
236
- extension_dirs << dir
237
- @loader.reload_extensions_dir dir if @loader
238
- end
240
+ def self.add_extension_dir dir
241
+ extension_dirs << dir
242
+ @loader.reload_extensions_dir dir if @loader
243
+ end
239
244
 
240
- def self.reload_extensions
241
- @loader.reload_extensions
242
- end
245
+ def self.reload_extensions
246
+ @loader.reload_extensions
247
+ end
243
248
 
244
- def self.loader; @loader; end
249
+ def self.loader; @loader; end
245
250
 
246
- protected
251
+ protected
247
252
 
248
- def self.const_missing sym
249
- name = sym.to_s
250
- if @loader and @loader.has? name
251
- @loader.get(name)
252
- else
253
- super
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
- def self.method_missing sym, *a
258
- name = sym.to_s
259
- if @loader and @loader.has? name
260
- @loader.get(name).new(*a)
261
- else
262
- super
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
- def self.load_vmodl fn
267
- @loader = RbVmomi::TypeLoader.new fn, extension_dirs, self
268
- nil
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