github.com/vmware/govmomi@v0.51.0/gen/gen_from_wsdl.rb (about) 1 # © Broadcom. All Rights Reserved. 2 # The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 # SPDX-License-Identifier: Apache-2.0 4 5 $:.unshift(File.expand_path(File.dirname(__FILE__))) 6 7 require "vim_wsdl" 8 9 require "yaml" 10 11 if !File.directory?(ARGV.first) 12 raise "first argument not a directory" 13 end 14 15 target = ARGV[1] 16 17 # Load the vijson yaml to fetch vijson schemas. 18 vijson_path = File.join(File.expand_path("../sdk", __FILE__), target+".yaml") 19 vijson = nil 20 if File.exists?(vijson_path) 21 vijson = YAML::load(File.open(vijson_path))["components"]["schemas"] 22 end 23 24 wsdl = WSDL.new(WSDL.read(target+".wsdl"), vijson) 25 wsdl.validate_assumptions! 26 wsdl.peek() 27 28 ifs = Peek.types.keys.select { |name| Peek.base?(name) }.size() 29 puts "%d classes, %d interfaces" % [Peek.types.size(), ifs] 30 31 File.open(File.join(ARGV.first, "types/enum.go"), "w") do |io| 32 io.print WSDL.header("types") 33 34 wsdl. 35 types. 36 sort_by { |x| x.name }. 37 uniq { |x| x.name }. 38 select { |t| t.is_enum? }. 39 each { |e| e.dump(io); e.dump_init(io) } 40 end 41 42 File.open(File.join(ARGV.first, "types/types.go"), "w") do |io| 43 io.print WSDL.header("types") 44 if target != "vim" 45 io.print <<EOF 46 import ( 47 "context" 48 "github.com/vmware/govmomi/vim25/types" 49 ) 50 EOF 51 end 52 53 wsdl. 54 types. 55 sort_by { |x| x.name }. 56 uniq { |x| x.name }. 57 select { |t| !t.is_enum? }. 58 each { |e| e.dump(io); e.dump_init(io) } 59 end 60 61 File.open(File.join(ARGV.first, "types/if.go"), "w") do |io| 62 io.print WSDL.header("types") 63 64 Peek.dump_interfaces(io) 65 end 66 67 File.open(File.join(ARGV.first, "methods/methods.go"), "w") do |io| 68 io.print WSDL.header("methods") 69 if target == "vim" 70 target += "25" 71 end 72 73 io.print <<EOF 74 import ( 75 "context" 76 "github.com/vmware/govmomi/#{target}/types" 77 "github.com/vmware/govmomi/vim25/soap" 78 ) 79 EOF 80 81 wsdl. 82 operations. 83 sort_by { |x| x.name }. 84 each { |e| e.dump(io) } 85 end 86 87 exit(0)