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
 
@@ -5,379 +6,402 @@ require 'pp'
5
6
  require 'set'
6
7
 
7
8
  module RbVmomi
8
- module BasicTypes
9
+ module BasicTypes
9
10
 
10
- BUILTIN = Set.new %w(ManagedObject DataObject TypeName PropertyPath ManagedObjectReference MethodName MethodFault LocalizedMethodFault KeyValue)
11
+ BUILTIN = Set.new %w(ManagedObject DataObject TypeName PropertyPath ManagedObjectReference MethodName MethodFault LocalizedMethodFault KeyValue)
11
12
 
12
- class Base
13
- class << self
14
- attr_accessor :wsdl_name
13
+ class Base
14
+ class << self
15
+ attr_accessor :wsdl_name
15
16
 
16
- def init wsdl_name=self.name
17
- @wsdl_name = wsdl_name
18
- end
17
+ def init wsdl_name=self.name
18
+ @wsdl_name = wsdl_name
19
+ end
20
+
21
+ def to_s
22
+ @wsdl_name
23
+ end
24
+ end
19
25
 
20
- def to_s
21
- @wsdl_name
26
+ init
22
27
  end
23
- end
24
28
 
25
- init
26
- end
29
+ class ObjectWithProperties < Base
30
+ class << self
31
+ attr_accessor :props_desc
32
+
33
+ def init name=self.name, props=[]
34
+ super name
35
+ @props_desc = props
36
+ @props_desc.each do |d|
37
+ sym = d['name'].to_sym
38
+ define_method(sym) { _get_property sym }
39
+ define_method(:"#{sym}=") { |x| _set_property sym, x }
40
+ end
41
+ end
42
+
43
+ def full_props_set
44
+ @full_props_set ||= Set.new(full_props_desc.map { |x| x['name'] })
45
+ end
27
46
 
28
- class ObjectWithProperties < Base
29
- class << self
30
- attr_accessor :props_desc
47
+ def full_props_desc
48
+ @full_props_desc ||= (self == ObjectWithProperties ? [] : superclass.full_props_desc) + props_desc
49
+ end
31
50
 
32
- def init name=self.name, props=[]
33
- super name
34
- @props_desc = props
35
- @props_desc.each do |d|
36
- sym = d['name'].to_sym
37
- define_method(sym) { _get_property sym }
38
- define_method(:"#{sym}=") { |x| _set_property sym, x }
51
+ def find_prop_desc name
52
+ full_props_desc.find { |x| x['name'] == name.to_s }
53
+ end
39
54
  end
40
- end
41
55
 
42
- def full_props_set
43
- @full_props_set ||= Set.new(full_props_desc.map { |x| x['name'] })
44
- end
56
+ def _get_property sym
57
+ raise 'unimplemented'
58
+ end
45
59
 
46
- def full_props_desc
47
- @full_props_desc ||= (self == ObjectWithProperties ? [] : superclass.full_props_desc) + props_desc
48
- end
60
+ def _set_property sym, val
61
+ raise 'unimplemented'
62
+ end
49
63
 
50
- def find_prop_desc name
51
- full_props_desc.find { |x| x['name'] == name.to_s }
64
+ init
52
65
  end
53
- end
54
66
 
55
- def _get_property sym
56
- fail 'unimplemented'
57
- end
58
-
59
- def _set_property sym, val
60
- fail 'unimplemented'
61
- end
62
-
63
- init
64
- end
67
+ class ObjectWithMethods < ObjectWithProperties
68
+ class << self
69
+ attr_accessor :methods_desc
65
70
 
66
- class ObjectWithMethods < ObjectWithProperties
67
- class << self
68
- attr_accessor :methods_desc
71
+ def init name=self.name, props=[], methods={}
72
+ super name, props
73
+ @methods_desc = methods
69
74
 
70
- def init name=self.name, props=[], methods={}
71
- super name, props
72
- @methods_desc = methods
75
+ @methods_desc.each do |k, d|
76
+ sym = k.to_sym
77
+ define_method(sym) { |*args| _call sym, *args }
78
+ define_method(:"#{sym}!") { |*args| _call sym, *args }
79
+ end
80
+ end
73
81
 
74
- @methods_desc.each do |k,d|
75
- sym = k.to_sym
76
- define_method(sym) { |*args| _call sym, *args }
77
- define_method(:"#{sym}!") { |*args| _call sym, *args }
82
+ # XXX cache
83
+ def full_methods_desc
84
+ (self == ObjectWithMethods ? {} : superclass.full_methods_desc).merge methods_desc
85
+ end
78
86
  end
79
- end
80
87
 
81
- # XXX cache
82
- def full_methods_desc
83
- (self == ObjectWithMethods ? {} : superclass.full_methods_desc).merge methods_desc
88
+ init
84
89
  end
85
- end
86
90
 
87
- init
88
- end
91
+ class DataObject < ObjectWithProperties
92
+ attr_reader :props
89
93
 
90
- class DataObject < ObjectWithProperties
91
- attr_reader :props
94
+ def self.kind; :data end
92
95
 
93
- def self.kind; :data end
96
+ def initialize props={}
97
+ # Deserialization fast path
98
+ if props == nil
99
+ @props = {}
100
+ return
101
+ end
94
102
 
95
- def initialize props={}
96
- # Deserialization fast path
97
- if props == nil
98
- @props = {}
99
- return
100
- end
103
+ @props = Hash[props.map { |k, v| [k.to_sym, v] }]
104
+ #self.class.full_props_desc.each do |desc|
105
+ #fail "missing required property #{desc['name'].inspect} of #{self.class.wsdl_name}" if @props[desc['name'].to_sym].nil? and not desc['is-optional']
106
+ #end
107
+ @props.each do |k, v|
108
+ raise "unexpected property name #{k}" unless self.class.find_prop_desc(k)
109
+ end
110
+ end
101
111
 
102
- @props = Hash[props.map { |k,v| [k.to_sym, v] }]
103
- #self.class.full_props_desc.each do |desc|
104
- #fail "missing required property #{desc['name'].inspect} of #{self.class.wsdl_name}" if @props[desc['name'].to_sym].nil? and not desc['is-optional']
105
- #end
106
- @props.each do |k,v|
107
- fail "unexpected property name #{k}" unless self.class.find_prop_desc(k)
108
- end
109
- end
112
+ def initialize_copy(source)
113
+ super
114
+ @props = @props.dup
115
+ end
116
+
117
+ def _get_property sym
118
+ @props[sym]
119
+ end
110
120
 
111
- def initialize_copy(source)
112
- super
113
- @props = @props.dup
114
- end
121
+ def [] sym
122
+ _get_property sym
123
+ end
115
124
 
116
- def _get_property sym
117
- @props[sym]
118
- end
125
+ def _set_property sym, val
126
+ @props[sym] = val
127
+ end
119
128
 
120
- def [] sym
121
- _get_property sym
122
- end
129
+ def []= sym, val
130
+ _set_property sym, val
131
+ end
123
132
 
124
- def _set_property sym, val
125
- @props[sym] = val
126
- end
133
+ def == o
134
+ return false unless o.class == self.class
127
135
 
128
- def []= sym, val
129
- _set_property sym, val
130
- end
136
+ keys = (props.keys + o.props.keys).uniq
137
+ keys.all? { |k| props[k] == o.props[k] }
138
+ end
131
139
 
132
- def == o
133
- return false unless o.class == self.class
134
- keys = (props.keys + o.props.keys).uniq
135
- keys.all? { |k| props[k] == o.props[k] }
136
- end
140
+ alias eql? ==
137
141
 
138
- alias eql? ==
142
+ def hash
143
+ props.hash
144
+ end
139
145
 
140
- def hash
141
- props.hash
142
- end
146
+ def pretty_print q
147
+ q.text self.class.wsdl_name
148
+ q.group 2 do
149
+ q.text '('
150
+ q.breakable
151
+ props = @props.sort_by { |k, v| k.to_s }
152
+ q.seplist props, nil, :each do |e|
153
+ k, v = e
154
+ q.group do
155
+ q.text k.to_s
156
+ q.text ': '
157
+ q.pp v
158
+ end
159
+ end
160
+ end
161
+ q.breakable
162
+ q.text ')'
163
+ end
143
164
 
144
- def pretty_print q
145
- q.text self.class.wsdl_name
146
- q.group 2 do
147
- q.text '('
148
- q.breakable
149
- props = @props.sort_by { |k,v| k.to_s }
150
- q.seplist props, nil, :each do |e|
151
- k, v = e
152
- q.group do
153
- q.text k.to_s
154
- q.text ': '
155
- q.pp v
165
+ def as_hash(val)
166
+ if val.kind_of?(Array)
167
+ val.map { |v| as_hash(v) }
168
+ elsif val.respond_to?(:to_hash)
169
+ val.to_hash
170
+ else
171
+ val
156
172
  end
157
173
  end
174
+
175
+ def to_hash
176
+ props.transform_values { |v| as_hash(v) }
177
+ end
178
+
179
+ def to_json(options = nil)
180
+ to_hash.merge(JSON.create_id => self.class.name).to_json
181
+ end
182
+
183
+ init
158
184
  end
159
- q.breakable
160
- q.text ')'
161
- end
162
185
 
163
- def to_json(*args)
164
- h = self.props
165
- m = h.merge({ JSON.create_id => self.class.name })
166
- m.to_json(*args)
167
- end
186
+ class ManagedObject < ObjectWithMethods
187
+ def self.kind; :managed end
168
188
 
169
- init
170
- end
189
+ def initialize connection, ref
190
+ super()
191
+ @connection = connection
192
+ @soap = @connection # XXX deprecated
193
+ @ref = ref
194
+ end
171
195
 
172
- class ManagedObject < ObjectWithMethods
173
- def self.kind; :managed end
196
+ def _connection
197
+ @connection
198
+ end
174
199
 
175
- def initialize connection, ref
176
- super()
177
- @connection = connection
178
- @soap = @connection # XXX deprecated
179
- @ref = ref
180
- end
200
+ def _ref
201
+ @ref
202
+ end
181
203
 
182
- def _connection
183
- @connection
184
- end
204
+ def _get_property sym
205
+ ret = @connection.propertyCollector.RetrieveProperties(specSet: [{
206
+ propSet: [{ type: self.class.wsdl_name, pathSet: [sym.to_s] }],
207
+ objectSet: [{ obj: self }],
208
+ }])[0]
185
209
 
186
- def _ref
187
- @ref
188
- end
210
+ if !ret
211
+ return nil
212
+ elsif ret.propSet.empty?
213
+ return nil if ret.missingSet.empty?
189
214
 
190
- def _get_property sym
191
- ret = @connection.propertyCollector.RetrieveProperties(:specSet => [{
192
- :propSet => [{ :type => self.class.wsdl_name, :pathSet => [sym.to_s] }],
193
- :objectSet => [{ :obj => self }],
194
- }])[0]
195
-
196
- if !ret
197
- return nil
198
- elsif ret.propSet.empty?
199
- return nil if ret.missingSet.empty?
200
- raise ret.missingSet[0].fault
201
- else
202
- ret.propSet[0].val
203
- end
204
- end
215
+ raise ret.missingSet[0].fault
216
+ else
217
+ ret.propSet[0].val
218
+ end
219
+ end
205
220
 
206
- def _set_property sym, val
207
- fail 'unimplemented'
208
- end
221
+ def _set_property sym, val
222
+ raise 'unimplemented'
223
+ end
209
224
 
210
- def _call method, o={}
211
- fail "parameters must be passed as a hash" unless o.is_a? Hash
212
- desc = self.class.full_methods_desc[method.to_s] or fail "unknown method"
213
- @connection.call method, desc, self, o
214
- end
225
+ def _call method, o={}
226
+ raise 'parameters must be passed as a hash' unless o.is_a? Hash
215
227
 
216
- def to_s
217
- "#{self.class.wsdl_name}(#{@ref.inspect})"
218
- end
228
+ desc = self.class.full_methods_desc[method.to_s] or raise 'unknown method'
229
+ @connection.call method, desc, self, o
230
+ end
219
231
 
220
- def pretty_print pp
221
- pp.text to_s
222
- end
232
+ def to_s
233
+ "#{self.class.wsdl_name}(#{@ref.inspect})"
234
+ end
223
235
 
224
- def [] k
225
- _get_property k
226
- end
236
+ def to_hash
237
+ to_s
238
+ end
227
239
 
228
- def == x
229
- out = (x.class == self.class && x._ref == @ref)
230
- out = (x._connection.instanceUuid == self._connection.instanceUuid) if out && x._connection.host
231
- out
232
- end
240
+ def pretty_print pp
241
+ pp.text to_s
242
+ end
233
243
 
234
- alias eql? ==
244
+ def [] k
245
+ _get_property k
246
+ end
235
247
 
236
- def hash
237
- [self.class, @ref].hash
238
- end
248
+ def == x
249
+ out = (x.class == self.class && x._ref == @ref)
250
+ out = (x._connection.instanceUuid == self._connection.instanceUuid) if out && x._connection.host
251
+ out
252
+ end
239
253
 
240
- init 'ManagedObject'
241
- end
254
+ alias eql? ==
242
255
 
243
- class Enum < Base
244
- class << self
245
- attr_accessor :values
256
+ def hash
257
+ [self.class, @ref].hash
258
+ end
246
259
 
247
- def init name=self.name, values=[]
248
- super name
249
- @values = values
260
+ init 'ManagedObject'
250
261
  end
251
- end
252
262
 
253
- def self.kind; :enum end
263
+ class Enum < Base
264
+ class << self
265
+ attr_accessor :values
254
266
 
255
- attr_reader :value
267
+ def init name=self.name, values=[]
268
+ super name
269
+ @values = values
270
+ end
271
+ end
256
272
 
257
- def initialize value
258
- @value = value
259
- end
273
+ def self.kind; :enum end
260
274
 
261
- init
262
- end
275
+ attr_reader :value
263
276
 
264
- class MethodFault < DataObject
265
- init 'MethodFault', [
266
- {
267
- 'name' => 'faultCause',
268
- 'wsdl_type' => 'LocalizedMethodFault',
269
- 'is-array' => false,
270
- 'is-optional' => true,
271
- }, {
272
- 'name' => 'faultMessage',
273
- 'wsdl_type' => 'LocalizableMessage',
274
- 'is-array' => true,
275
- 'is-optional' => true,
276
- },
277
- ]
278
-
279
- def self.=== exn
280
- exn.class == RbVmomi::Fault and self <= exn.fault.class
281
- end
282
- end
277
+ def initialize value
278
+ @value = value
279
+ end
283
280
 
284
- class LocalizedMethodFault < DataObject
285
- init 'LocalizedMethodFault', [
286
- {
287
- 'name' => 'fault',
288
- 'wsdl_type' => 'MethodFault',
289
- 'is-array' => false,
290
- 'is-optional' => false,
291
- }, {
292
- 'name' => 'localizedMessage',
293
- 'wsdl_type' => 'xsd:string',
294
- 'is-array' => false,
295
- 'is-optional' => true,
296
- },
297
- ]
298
-
299
- def exception
300
- RbVmomi::Fault.new(self.localizedMessage, self.fault)
301
- end
302
- end
281
+ def to_hash
282
+ value
283
+ end
303
284
 
304
- class RuntimeFault < MethodFault
305
- init
306
- end
285
+ init
286
+ end
307
287
 
308
- class MethodName < String
309
- def self.wsdl_name; 'MethodName' end
310
- end
288
+ class MethodFault < DataObject
289
+ init 'MethodFault', [
290
+ {
291
+ 'name' => 'faultCause',
292
+ 'wsdl_type' => 'LocalizedMethodFault',
293
+ 'is-array' => false,
294
+ 'is-optional' => true,
295
+ }, {
296
+ 'name' => 'faultMessage',
297
+ 'wsdl_type' => 'LocalizableMessage',
298
+ 'is-array' => true,
299
+ 'is-optional' => true,
300
+ },
301
+ ]
302
+
303
+ def self.=== exn
304
+ exn.class == RbVmomi::Fault and self <= exn.fault.class
305
+ end
306
+ end
311
307
 
312
- class PropertyPath < String
313
- def self.wsdl_name; 'PropertyPath' end
314
- end
308
+ class LocalizedMethodFault < DataObject
309
+ init 'LocalizedMethodFault', [
310
+ {
311
+ 'name' => 'fault',
312
+ 'wsdl_type' => 'MethodFault',
313
+ 'is-array' => false,
314
+ 'is-optional' => false,
315
+ }, {
316
+ 'name' => 'localizedMessage',
317
+ 'wsdl_type' => 'xsd:string',
318
+ 'is-array' => false,
319
+ 'is-optional' => true,
320
+ },
321
+ ]
322
+
323
+ def exception
324
+ RbVmomi::Fault.new(self.localizedMessage, self.fault)
325
+ end
326
+ end
315
327
 
316
- class TypeName < String
317
- def self.wsdl_name; 'TypeName' end
318
- end
328
+ class RuntimeFault < MethodFault
329
+ init
330
+ end
319
331
 
320
- class ManagedObjectReference
321
- def self.wsdl_name; 'ManagedObjectReference' end
322
- end
332
+ class MethodName < String
333
+ def self.wsdl_name; 'MethodName' end
334
+ end
323
335
 
324
- class Boolean
325
- def self.wsdl_name; 'xsd:boolean' end
326
- end
336
+ class PropertyPath < String
337
+ def self.wsdl_name; 'PropertyPath' end
338
+ end
327
339
 
328
- class AnyType
329
- def self.wsdl_name; 'xsd:anyType' end
330
- end
340
+ class TypeName < String
341
+ def self.wsdl_name; 'TypeName' end
342
+ end
331
343
 
332
- class Binary
333
- def self.wsdl_name; 'xsd:base64Binary' end
334
- end
344
+ class ManagedObjectReference
345
+ def self.wsdl_name; 'ManagedObjectReference' end
346
+ end
335
347
 
336
- class ::Class
337
- def wsdl_name; self.class.name end
338
- end
348
+ class Boolean
349
+ def self.wsdl_name; 'xsd:boolean' end
350
+ end
339
351
 
340
- class ::String
341
- def self.wsdl_name; 'xsd:string' end
342
- end
352
+ class AnyType
353
+ def self.wsdl_name; 'xsd:anyType' end
354
+ end
343
355
 
344
- class ::Integer
345
- def self.wsdl_name; 'xsd:int' end
346
- end
356
+ class Binary
357
+ def self.wsdl_name; 'xsd:base64Binary' end
358
+ end
347
359
 
348
- class ::Float
349
- def self.wsdl_name; 'xsd:float' end
350
- end
360
+ class ::Class
361
+ def wsdl_name; self.class.name end
362
+ end
351
363
 
352
- class Int
353
- def self.wsdl_name; 'xsd:int' end
354
-
355
- def initialize x
356
- @val = x
357
- end
358
-
359
- def to_s
360
- @val.to_s
361
- end
362
- end
364
+ class ::String
365
+ def self.wsdl_name; 'xsd:string' end
366
+ end
363
367
 
364
- class KeyValue
365
- def self.wsdl_name; 'KeyValue' end
366
- attr_accessor :key, :value
368
+ class ::Integer
369
+ def self.wsdl_name; 'xsd:int' end
370
+ end
367
371
 
368
- def initialize k, v
369
- @key = k
370
- @value = v
371
- end
372
+ class ::Float
373
+ def self.wsdl_name; 'xsd:float' end
374
+ end
375
+
376
+ class Int
377
+ def self.wsdl_name; 'xsd:int' end
378
+
379
+ def initialize x
380
+ @val = x
381
+ end
372
382
 
373
- def [] i
374
- if i == 0 then @key
375
- elsif i == 1 then @value
376
- else fail "invalid index #{i.inspect}"
383
+ def to_s
384
+ @val.to_s
385
+ end
377
386
  end
378
- end
379
- end
380
387
 
388
+ class KeyValue
389
+ def self.wsdl_name; 'KeyValue' end
390
+ attr_accessor :key, :value
381
391
 
382
- end
392
+ def initialize k, v
393
+ @key = k
394
+ @value = v
395
+ end
396
+
397
+ def [] i
398
+ if i == 0 then @key
399
+ elsif i == 1 then @value
400
+ else raise "invalid index #{i.inspect}"
401
+ end
402
+ end
403
+ end
404
+
405
+
406
+ end
383
407
  end