Skip to content

Commit

Permalink
Handle non-managed_object arguments and nil responses
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Dec 9, 2023
1 parent 83029bb commit c725309
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/VMwareWebService/VimService.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,8 @@ def handle_memory_and_gc(response)
end

def parse_response(response, _rType)
return if response.nil?

{"returnval" => rbvmomi_to_vim_type(response)}
end

Expand Down
15 changes: 11 additions & 4 deletions lib/VMwareWebService/handsoap_stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class Service < Handsoap::Service
def initialize(ep)
super

uri = URI.parse(ep[:uri])
uri = ep[:uri]
uri = URI.parse(uri) unless uri.kind_of?(URI)

require 'rbvmomi/vim'
@vim = RbVmomi::VIM.new(:host => uri.host, :port => uri.port, :insecure => true, :ssl => uri.scheme == "https", :ns => @ns["n1"], :path => "/sdk", :rev => "8.0")
Expand All @@ -16,7 +17,7 @@ def initialize(ep)
def dispatch(doc, action)
args = xml_doc_to_rbvmomi(doc, action)
this = args.delete("_this")
this.send(action.to_sym, *args)
this.send(action.to_sym, args)
end

private
Expand All @@ -35,9 +36,15 @@ def xml_doc_to_rbvmomi(doc, action)
def xml_to_rbvmomi(xml)
# TODO handle more than ManagedObjects

type = xml.instance_variable_get(:@attributes)["type"]
managed_object_type = xml.instance_variable_get(:@attributes)&.dig("type")
name = xml.instance_variable_get(:@node_name)
value = xml.instance_variable_get(:@children).first.to_s
RbVmomi::VIM.const_get(type).new(@vim, value)

if managed_object_type
RbVmomi::VIM.const_get(managed_object_type).new(@vim, value)
else
value
end
end

def rbvmomi_to_vim_type(obj)
Expand Down

0 comments on commit c725309

Please sign in to comment.