lib/wbem/cimxml.rb in wbem-0.3.0 vs lib/wbem/cimxml.rb in wbem-0.5.0
- old
+ new
@@ -50,10 +50,47 @@
end
public
#
+ # parse ObjectPath to Sfcc::Cim::ObjectPath
+ # 1. root/cimv2:Linux_ComputerSystem.CreationClassName="Linux_ComputerSystem",Name="foo.bar"
+ # 2. localhost:5989/root/cimv2:Linux_ComputerSystem.CreationClassName="Linux_ComputerSystem",Name="heron.suse.de"
+ #
+ #
+ def self.parse_object_path s
+ op = nil
+ front, values = s.split(".",2)
+ STDERR.puts "self.parse_object_path >#{front}<(#{values})"
+ frontargs = front.split(":")
+ if frontargs.size == 2
+ # case 1 above
+ namespace, classname = frontargs
+ op = Sfcc::Cim::ObjectPath.new(namespace, classname)
+ elsif frontargs.size == 3
+ host, port_and_namespace, classname = frontargs
+ port, namespace = port_and_namespace.split("/", 2)
+ op = Sfcc::Cim::ObjectPath.new(namespace, classname)
+ else
+ raise "CimxmlClient.parse_object_path: Can't parse >#{frontargs.inspect}<"
+ end
+ # add values
+ while values && !values.empty?
+ puts "Values >#{values.inspect}<"
+ name, rest = values.split("=", 2)
+ arg, values = if rest[0,1] == '"' # quoted arg
+ rest[1..-1].split(/\",?/, 2)
+ else # non-quoted arg
+ rest.split(",", 2)
+ end
+ puts "name(#{name}), arg(#{arg})"
+ op.add_key(name, arg)
+ end
+ puts "Op #{op}"
+ op
+ end
+ #
# Initialize a CIMXML client connection
#
def initialize url, auth_scheme = nil
super url, auth_scheme
@client = Sfcc::Cim::Client.connect( { :uri => url, :verify => false } )
@@ -123,14 +160,16 @@
# @param namespace : String or Sfcc::Cim::ObjectPath
# @param classname : String (optional)
# @param properties : Hash (optional)
#
def instance_names namespace, classname=nil, properties={}
+ # if namespace is unset, sfcc will generate invalid XML
+ namespace ||= "root/cimv2"
case namespace
when Sfcc::Cim::ObjectPath
objectpath = namespace
- namespace = objectpath.namespace
+ namespace = objectpath.namespace
else
objectpath = objectpath namespace.to_s, classname, properties
end
ret = []
begin
@@ -142,10 +181,36 @@
end
ret
end
#
+ # get instance by reference
+ #
+ # call-seq
+ # get Sfcc::Cim::ObjectPath -> Wbem::Instance
+ # get ObjectPath-as-String -> Wbem::Instance
+ # get "ClassName", "key" => "value", :namespace => "root/interop"
+ #
+ def get instance_reference, keys = nil
+ if keys
+ namespace = keys.delete(:namespace) || "root/cimv2"
+ instance_reference = Sfcc::Cim::ObjectPath.new(namespace, instance_reference)
+ keys.each do |k,v|
+ instance_reference.add_key k, v
+ end
+ end
+ puts "@client.get #{instance_reference.class}..." if Wbem.debug
+ case instance_reference
+ when Sfcc::Cim::ObjectPath
+ get_by_objectpath instance_reference
+ when String
+ get_by_objectpath CimxmlClient.parse_object_path(instance_reference)
+ else
+ raise "Unsupported Wbem::get #{instance_reference.class}"
+ end
+ end
+ #
# Return matching Wbem::Instance for first instance
# matching namespace, classname, properties
# @param namespace : String or Sfcc::Cim::ObjectPath
# @param classname : String (optional)
# @param properties : Hash (optional)
@@ -188,7 +253,14 @@
end
rescue Sfcc::Cim::ErrorInvalidClass, Sfcc::Cim::ErrorInvalidNamespace
end
end
+ #
+ # get instance by objectpath
+ #
+ def get_by_objectpath objpath
+ STDERR.puts "#{self.class}.get_by_objectpath #{objpath}" if Wbem.debug
+ @client.get_instance(objpath)
+ end
end # class
end # module