lib/wbem.rb in wbem-0.1.0 vs lib/wbem.rb in wbem-0.1.1

- old
+ new

@@ -1,5 +1,15 @@ +# +# wbem.rb +# +# A CIM client abstraction layer on top of sfcc (cim/xml) and openwsman (WS-Management) +# +# Copyright (c) 2011, SUSE Linux Products GmbH +# Written by Klaus Kaempf <kkaempf@suse.de> +# +# Licensed under the MIT license +# module Wbem @@debug = nil def Wbem.debug @@debug end @@ -9,39 +19,48 @@ class Client require 'uri' require 'wbem/wsman' require 'wbem/cimxml' - attr_reader :url, :response - # # Wbem::Client.connect uri, protocol = nil # # Connect to remote client identified by uri and protocol # Possible values for protocol: # :cimxml - connect via CIM/XML # :wsman - connect via WS-Management # else - probe connection (cim/xml first) # def self.connect uri, protocol = nil - STDERR.puts "Wbem::Client.connect(#{uri},#{protocol})" if Wbem.debug - u = uri.is_a?(URI) ? uri : URI.parse(uri) + STDERR.puts "Wbem::Client.connect(#{uri},#{protocol})" + unless uri.is_a?(URI) + u = URI.parse(uri) + protocol_given = uri.match(/:\d/) + else + u = uri + protocol_given = uri.port + end case protocol when :wsman + unless protocol_given + u.port = (u.scheme == "http") ? 5985 : 5986 + end return WsmanClient.new u when :cimxml + unless protocol_given + u.port = (u.scheme == "http") ? 5988 : 5989 + end return CimxmlClient.new u end - STDERR.puts "no connect, check known ports" # no connect, check known ports case u.port when 8888, 8889, 5985, 5986 return WsmanClient.new u when 5988, 5989 return CimxmlClient.new u end - STDERR.puts "no known ports" +# STDERR.puts "no known ports" port = u.port # keep orig port as we change u.port below [:wsman, :cimxml].each do |protocol| # enforce port if uri provides scheme and host only if port == 80 && u.scheme == 'http' # http://hostname u.port = (protocol == :cimxml) ? 5988: 5985 @@ -49,10 +68,10 @@ if port == 443 && u.scheme == 'https' # https://hostname u.port = (protocol == :cimxml) ? 5989: 5986 end c = Wbem::Client.connect u, protocol if c - STDERR.puts "Connect #{u} as #{c}" +# STDERR.puts "Connect #{u} as #{c}" return c end end end