Created
February 14, 2020 21:16
-
-
Save agrare/1632469372df5d68a068afe5367679f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rbvmomi' | |
require 'byebug' | |
def load_vim_types(vim_types_xsd) | |
vim_types_xsd.dig("schema", "complexType").each_with_object({}) do |type, vim_types| | |
complex_content = type.dig("complexContent", "extension", "sequence") | |
next unless complex_content.kind_of?(Hash) | |
complex_content = Array.wrap(complex_content["element"]).index_by { |p| p["name"] } | |
vim_types[type["name"]] = complex_content | |
end | |
end | |
def string_to_klass(type) | |
if type.start_with?("xsd:") | |
type | |
else | |
"RbVmomi::VIM::#{type}".constantize | |
end | |
end | |
require "pathname" | |
require 'active_support/core_ext/hash/conversions' | |
require 'active_support/core_ext/enumerable' | |
raise "You must pass the path to the VC SDK wsdl directory" if ARGV[0].nil? | |
vim25_wsdl_dir = Pathname.new(ARGV[0]) | |
vim_types_xsd = Hash.from_xml(vim25_wsdl_dir.join("vim25", "vim-types.xsd").read) | |
vim_types = load_vim_types(vim_types_xsd) | |
vmodl = Marshal.load(File.read("vmodl.db")) | |
vim_types.each do |wsdl_name, wsdl_props| | |
next unless vmodl.key?(wsdl_name) | |
vmodl[wsdl_name]["props"].each do |vmodl_prop| | |
vmodl_type = string_to_klass(vmodl_prop["wsdl_type"]) | |
wsdl_type = string_to_klass(wsdl_props[vmodl_prop["name"]]["type"].split("vim25:").last) | |
next if vmodl_type.kind_of?(Class) && vmodl_type < RbVmomi::BasicTypes::Base && wsdl_type == RbVmomi::BasicTypes::ManagedObjectReference | |
unless vmodl_type == wsdl_type | |
puts "#{wsdl_name}.#{vmodl_prop["name"]} should be #{wsdl_type} but is #{vmodl_type}" | |
vmodl_prop["wsdl_type"] = wsdl_type | |
end | |
end | |
end | |
File.write("vmodl.db", Marshal.dump(vmodl)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment