Class: VmodlHelper
- Inherits:
-
Object
- Object
- VmodlHelper
- Defined in:
- lib/tasks/vmodl_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #generate! ⇒ Object
-
#initialize(vmodl_path:, wsdl_path:) ⇒ VmodlHelper
constructor
A new instance of VmodlHelper.
- #verify! ⇒ Object
Constructor Details
#initialize(vmodl_path:, wsdl_path:) ⇒ VmodlHelper
Returns a new instance of VmodlHelper.
42 43 44 45 46 47 48 |
# File 'lib/tasks/vmodl_helper.rb', line 42 def initialize(vmodl_path:, wsdl_path:) @vmodl_path = Pathname.new(vmodl_path) @wsdl_path = Pathname.new(wsdl_path) @vmodl = load_vmodl(@vmodl_path) @wsdl = load_wsdl(@wsdl_path) end |
Class Method Details
.generate! ⇒ Object
17 18 19 |
# File 'lib/tasks/vmodl_helper.rb', line 17 def generate! run!('generate') end |
.verify! ⇒ Object
13 14 15 |
# File 'lib/tasks/vmodl_helper.rb', line 13 def verify! run!('verify') end |
Instance Method Details
#generate! ⇒ Object
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/tasks/vmodl_helper.rb', line 87 def generate! wsdl_types_by_name.each_value do |type| type_name = type.name.name vmodl_data = @vmodl[type_name] if vmodl_data.nil? base_class = wsdl_types_by_name[type.complexcontent.extension.base.name] inherited_properties = base_class.elements.map { |element| element.name.name } properties = type.elements.reject { |e| inherited_properties.include?(e.name.name) } vmodl_data = { 'kind' => 'data', 'props' => properties.map do |element| { 'name' => element.name.name, 'is-optional' => element.minoccurs == 0, 'is-array' => element.maxoccurs != 1, 'version-id-ref' => nil, 'wsdl_type' => wsdl_to_vmodl_type(element.type) } end, 'wsdl_base' => type.complexcontent.extension.base.name } @vmodl[type_name] = vmodl_data @vmodl['_typenames']['_typenames'] << type_name puts "Adding #{type_name} to vmodl" wsdl_to_rbvmomi_namespace(type).loader.add_types type_name => vmodl_data end end wsdl_types_by_name.each_value do |type| type_name = type.name.name vmodl_data = @vmodl[type_name] elements_by_name = type.elements.index_by { |e| e.name.name } # Loop through the properties defined in the vmodl.db for this type and # compare the type to that property as defined in the wsdl. vmodl_data['props'].each do |vmodl_prop| wsdl_prop = elements_by_name[vmodl_prop['name']] next if wsdl_prop.nil? vmodl_klass = wsdl_constantize(vmodl_prop['wsdl_type']) wsdl_klass = wsdl_constantize(wsdl_prop.type.source) vmodl_prop['wsdl_type'] = wsdl_klass.wsdl_name unless vmodl_klass <= wsdl_klass end end dump_vmodl! end |
#verify! ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tasks/vmodl_helper.rb', line 50 def verify! # Loop through the ComplexTypes in the WSDL and compare their types # to the types which are defined in the vmodl.db wsdl_types_by_name.each_value do |type| type_name = type.name.name vmodl_data = @vmodl[type_name] # If a type exists in the WSDL but not in the vmodl.db this usually # indicates that it was added in a newer version than the current # vmodl.db supports. # # Print a warning that the type is missing and skip it. if vmodl_data.nil? puts " #{type_name} is missing" next end # Index the properties by name to make it simpler to find later elements_by_name = type.elements.index_by { |e| e.name.name } # Loop through the properties defined in the vmodl.db for this type and # compare the type to that property as defined in the wsdl. vmodl_data['props'].each do |vmodl_prop| wsdl_prop = elements_by_name[vmodl_prop['name']] next if wsdl_prop.nil? vmodl_klass = wsdl_constantize(vmodl_prop['wsdl_type']) wsdl_klass = wsdl_constantize(wsdl_prop.type.source) # The vmodl class should be equal to or a subclass of the one in the wsdl. # Example of a subclass is e.g. VirtualMachine.host is defined as a HostSystem # in the vmodl.db but it is a ManagedObjectReference in the wsdl. puts "#{type_name}.#{vmodl_prop["name"]} #{wsdl_klass.wsdl_name} doesn't match #{vmodl_klass.wsdl_name}" unless vmodl_klass <= wsdl_klass end end end |