rbvmomi2 3.3.0 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cd7c8f7c07cfc8e042bc125747b279ff88430ab531068b3bb56aeb937ec5009
4
- data.tar.gz: 1c76cde83a228ac728cdd747b3367a32d19a2a98c7c07eb796a2a73fd414fd2b
3
+ metadata.gz: 2e2733470acbf2f94651a1b6cb655842e0db2f9e58e8a013c0eefc0cf21c8296
4
+ data.tar.gz: 04ea1dc6b3501c2d7973d6dae477cf7dcbb2039f30d1dce36a8d014bf86b2357
5
5
  SHA512:
6
- metadata.gz: d9779867969725d9d0eeb72fda7193e5a6e8725cc53a5d4c41518089203657ca7eb30ed8bbcf1f5e17f7a48aec52accbb975fb32e6d19a9a63c1c01d2796d560
7
- data.tar.gz: 88421663c3b937da0fe46cb021c3f17830670738cb5297851db5ee3a0a605b994c5c12d3402b835d6418481f5348d4a6e3cb8a354d6cc67192597527bc8bcfad
6
+ metadata.gz: 3ee50ebba478750c19649ae5384ec0b8a339ca18781bc4b975556c55664da643357d13dc84d6318f799d823193bfc3c6d9a08090c33e9ce79d4dd140e499ec56
7
+ data.tar.gz: aa888e61bbba655af5371dab271c3d0e1df6206f6b658ab9773d441212a97ca4298f8d981a71c9093e28141a651fa82f2980539cd70cea11d087ac19dd884593
@@ -3,5 +3,5 @@
3
3
  # SPDX-License-Identifier: MIT
4
4
 
5
5
  module RbVmomi
6
- VERSION = '3.3.0'.freeze
6
+ VERSION = '3.4.1'.freeze
7
7
  end
@@ -50,7 +50,7 @@ class VmodlHelper
50
50
  def verify!
51
51
  # Loop through the ComplexTypes in the WSDL and compare their types
52
52
  # to the types which are defined in the vmodl.db
53
- wsdl_types_by_name.each_value do |type|
53
+ wsdl_classes_by_name.each_value do |type|
54
54
  type_name = type.name.name
55
55
  vmodl_data = @vmodl[type_name]
56
56
 
@@ -60,7 +60,7 @@ class VmodlHelper
60
60
  #
61
61
  # Print a warning that the type is missing and skip it.
62
62
  if vmodl_data.nil?
63
- puts " #{type_name} is missing"
63
+ puts " class #{type_name} is missing"
64
64
  next
65
65
  end
66
66
 
@@ -82,42 +82,49 @@ class VmodlHelper
82
82
  puts "#{type_name}.#{vmodl_prop["name"]} #{wsdl_klass.wsdl_name} doesn't match #{vmodl_klass.wsdl_name}" unless vmodl_klass <= wsdl_klass
83
83
  end
84
84
  end
85
+
86
+ # Loop through the SimpleTypes (enums) in the WSDL
87
+ wsdl_enums_by_name.each_value do |enum|
88
+ enum_name = enum.name.name
89
+ vmodl_data = @vmodl[enum_name]
90
+
91
+ if vmodl_data.nil?
92
+ puts " enum #{enum_name} is missing"
93
+ next
94
+ end
95
+ end
85
96
  end
86
97
 
87
98
  def generate!
88
- wsdl_types_by_name.each_value do |type|
89
- type_name = type.name.name
90
- vmodl_data = @vmodl[type_name]
99
+ wsdl_classes_by_name.each_value do |type|
100
+ type_name = type.name.name
91
101
 
92
- if vmodl_data.nil?
93
- base_class = wsdl_types_by_name[type.complexcontent.extension.base.name]
94
- inherited_properties = base_class.elements.map { |element| element.name.name }
95
- properties = type.elements.reject { |e| inherited_properties.include?(e.name.name) }
96
-
97
- vmodl_data = {
98
- 'kind' => 'data',
99
- 'props' => properties.map do |element|
100
- {
101
- 'name' => element.name.name,
102
- 'is-optional' => element.minoccurs == 0,
103
- 'is-array' => element.maxoccurs != 1,
104
- 'version-id-ref' => nil,
105
- 'wsdl_type' => wsdl_to_vmodl_type(element.type)
106
- }
107
- end,
108
- 'wsdl_base' => type.complexcontent.extension.base.name
109
- }
110
-
111
- @vmodl[type_name] = vmodl_data
112
- @vmodl['_typenames']['_typenames'] << type_name
113
-
114
- puts "Adding #{type_name} to vmodl"
115
-
116
- wsdl_to_rbvmomi_namespace(type).loader.add_types type_name => vmodl_data
102
+ # Update the existing vmodl object if it exists otherwise instantiate a
103
+ # new one.
104
+ vmodl_data = @vmodl[type_name] || build_wsdl_class!(type)
105
+ props_by_name = vmodl_data['props'].index_by { |prop| prop['name'] }
106
+
107
+ vmodl_data['props'] = wsdl_properties(type).map do |element|
108
+ # NOTE we should prioritize the existing property hash over building a
109
+ # new one because the generic ManagedObjectReferences are manually
110
+ # replaced with their specific counterparts (e.g. Datastore) which
111
+ # cannot be computed programmatically.
112
+ props_by_name[element.name.name] || build_vmodl_property(element)
117
113
  end
114
+
115
+ # Some types (e.g. ManagedObjectReference) have extra properties which are
116
+ # not present in the WSDL but are required for proper function of RbVmomi.
117
+ vmodl_data['props'] += extra_props_for_type(type_name)
118
118
  end
119
119
 
120
- wsdl_types_by_name.each_value do |type|
120
+ wsdl_enums_by_name.each_value do |enum|
121
+ enum_name = enum.name.name
122
+
123
+ vmodl_data = @vmodl[enum_name] || build_wsdl_enum(enum)
124
+ vmodl_data['values'] = enum.restriction.enumeration
125
+ end
126
+
127
+ wsdl_classes_by_name.each_value do |type|
121
128
  type_name = type.name.name
122
129
  vmodl_data = @vmodl[type_name]
123
130
 
@@ -159,12 +166,77 @@ class VmodlHelper
159
166
 
160
167
  private
161
168
 
162
- def wsdl_types_by_name
163
- @wsdl_types_by_name ||= @wsdl.collect_complextypes
169
+ def build_wsdl_class!(type)
170
+ type_name = type.name.name
171
+
172
+ puts "Adding class #{type_name} to vmodl"
173
+
174
+ vmodl_obj = {'kind' => 'data', 'props' => [], 'wsdl_base' => type.complexcontent.extension.base.name}
175
+
176
+ @vmodl[type_name] = vmodl_obj
177
+ @vmodl['_typenames']['_typenames'] << type_name
178
+
179
+ wsdl_to_rbvmomi_namespace(type).loader.add_types(type_name => vmodl_obj)
180
+
181
+ vmodl_obj
182
+ end
183
+
184
+ def build_wsdl_enum(enum)
185
+ enum_name = enum.name.name
186
+
187
+ puts "Adding enum #{enum_name} to vmodl"
188
+
189
+ vmodl_obj = {'kind' => 'enum', 'values' => []}
190
+
191
+ @vmodl[enum_name] = vmodl_obj
192
+ @vmodl['_typenames']['_typenames'] << enum_name
193
+
194
+ wsdl_to_rbvmomi_namespace(enum).loader.add_types(enum_name => vmodl_obj)
195
+
196
+ vmodl_obj
197
+ end
198
+
199
+ def build_vmodl_property(element)
200
+ {
201
+ 'name' => element.name.name,
202
+ 'is-optional' => element.minoccurs == 0,
203
+ 'is-array' => element.maxoccurs != 1,
204
+ 'version-id-ref' => nil,
205
+ 'wsdl_type' => wsdl_to_vmodl_type(element.type)
206
+ }
207
+ end
208
+
209
+ def wsdl_properties(type)
210
+ base_class = wsdl_classes_by_name[type.complexcontent&.extension&.base&.name]
211
+ if base_class
212
+ inherited_properties = base_class.elements.map { |element| element.name.name }
213
+ type.elements.reject { |e| inherited_properties.include?(e.name.name) }
214
+ else
215
+ type.elements
216
+ end
217
+ end
218
+
219
+ def extra_props_for_type(type)
220
+ @extra_props_for_type ||= {
221
+ 'ManagedObjectReference' => [
222
+ {'name' => 'type', 'is-optional' => false, 'is-array' => false, 'version-id-ref' => nil, 'wsdl_type' => 'xsd:string'},
223
+ {'name' => 'value', 'is-optional' => false, 'is-array' => false, 'version-id-ref' => nil, 'wsdl_type' => 'xsd:string'}
224
+ ]
225
+ }
226
+
227
+ @extra_props_for_type[type] || []
228
+ end
229
+
230
+ def wsdl_classes_by_name
231
+ @wsdl_classes_by_name ||= @wsdl.collect_complextypes
164
232
  .reject { |type| type.name.name.match?(/^ArrayOf|RequestType$/) }
165
233
  .index_by { |type| type.name.name }
166
234
  end
167
235
 
236
+ def wsdl_enums_by_name
237
+ @wsdl_enums_by_name ||= @wsdl.collect_simpletypes.index_by { |type| type.name.name }
238
+ end
239
+
168
240
  def wsdl_to_vmodl_type(type)
169
241
  case type.source
170
242
  when /vim25:/, /pbm:/, /sms:/
@@ -180,7 +252,7 @@ class VmodlHelper
180
252
 
181
253
  def wsdl_to_rbvmomi_namespace(type)
182
254
  case type.targetnamespace
183
- when 'urb:vim25'
255
+ when 'urn:vim25'
184
256
  RbVmomi::VIM
185
257
  when 'urn:pbm'
186
258
  RbVmomi::PBM
@@ -201,6 +273,6 @@ class VmodlHelper
201
273
  type = 'ManagedObject' if type == 'ManagedObjectReference'
202
274
 
203
275
  type = type.camelcase
204
- type.safe_constantize || "RbVmomi::BasicTypes::#{type}".safe_constantize || "RbVmomi::VIM::#{type}".safe_constantize
276
+ type.safe_constantize || "RbVmomi::BasicTypes::#{type}".safe_constantize || "#{wsdl_to_rbvmomi_namespace(@wsdl)}::#{type}".safe_constantize
205
277
  end
206
278
  end
data/vmodl.db CHANGED
Binary file
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbvmomi2
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Grare
8
8
  - Jason Frey
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-03-10 00:00:00.000000000 Z
12
+ date: 2022-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -93,14 +93,14 @@ dependencies:
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.13.1
96
+ version: 0.14.1
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.13.1
103
+ version: 0.14.1
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rake
106
106
  requirement: !ruby/object:Gem::Requirement
@@ -185,7 +185,7 @@ dependencies:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
187
  version: 0.9.25
188
- description:
188
+ description:
189
189
  email:
190
190
  - adam@grare.com
191
191
  - fryguy9@gmail.com
@@ -245,7 +245,7 @@ homepage: https://github.com/ManageIQ/rbvmomi2
245
245
  licenses:
246
246
  - MIT
247
247
  metadata: {}
248
- post_install_message:
248
+ post_install_message:
249
249
  rdoc_options: []
250
250
  require_paths:
251
251
  - lib
@@ -260,8 +260,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
260
  - !ruby/object:Gem::Version
261
261
  version: '0'
262
262
  requirements: []
263
- rubygems_version: 3.3.5
264
- signing_key:
263
+ rubygems_version: 3.3.15
264
+ signing_key:
265
265
  specification_version: 4
266
266
  summary: Ruby interface to the VMware vSphere API
267
267
  test_files: []