wbem 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +9 -0
- data/lib/wbem.rb +3 -3
- data/lib/wbem/cimxml.rb +63 -16
- data/lib/wbem/version.rb +1 -1
- data/lib/wbem/wbem.rb +6 -29
- data/lib/wbem/wsman.rb +261 -30
- metadata +27 -12
data/CHANGELOG.rdoc
CHANGED
data/lib/wbem.rb
CHANGED
@@ -41,13 +41,13 @@ module Wbem
|
|
41
41
|
u = uri
|
42
42
|
protocol_given = uri.port
|
43
43
|
end
|
44
|
-
case protocol.
|
45
|
-
when
|
44
|
+
case protocol.to_s
|
45
|
+
when "wsman"
|
46
46
|
unless protocol_given
|
47
47
|
u.port = (u.scheme == "http") ? 5985 : 5986
|
48
48
|
end
|
49
49
|
return WsmanClient.new u, auth_scheme
|
50
|
-
when
|
50
|
+
when "cimxml"
|
51
51
|
unless protocol_given
|
52
52
|
u.port = (u.scheme == "http") ? 5988 : 5989
|
53
53
|
end
|
data/lib/wbem/cimxml.rb
CHANGED
@@ -14,7 +14,7 @@ module Sfcc
|
|
14
14
|
class ObjectPath
|
15
15
|
def keys
|
16
16
|
res = []
|
17
|
-
each_key { |key| res << key }
|
17
|
+
each_key { |key,value| res << key }
|
18
18
|
res
|
19
19
|
end
|
20
20
|
end
|
@@ -33,7 +33,6 @@ private
|
|
33
33
|
def _identify
|
34
34
|
# sfcb has /root/interop:CIM_ObjectManager
|
35
35
|
sfcb_op = objectpath "root/interop", "CIM_ObjectManager"
|
36
|
-
STDERR.puts "Looking for #{sfcb_op}"
|
37
36
|
begin
|
38
37
|
@client.instances(sfcb_op).each do |inst|
|
39
38
|
@product = inst.Description
|
@@ -44,6 +43,7 @@ private
|
|
44
43
|
raise "Unknown CIMOM"
|
45
44
|
end
|
46
45
|
end
|
46
|
+
|
47
47
|
public
|
48
48
|
|
49
49
|
#
|
@@ -54,19 +54,38 @@ public
|
|
54
54
|
@client = Sfcc::Cim::Client.connect( { :uri => url, :verify => false } )
|
55
55
|
_identify
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
#
|
59
|
-
#
|
59
|
+
# return list of namespaces
|
60
60
|
#
|
61
|
-
def
|
62
|
-
|
61
|
+
def namespaces
|
62
|
+
result = []
|
63
|
+
each_instance( "root/interop", "CIM_Namespace" ) do |inst|
|
64
|
+
result << inst.Name
|
65
|
+
end
|
66
|
+
result.uniq
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Create ObjectPath from namespace, classname, and properties
|
71
|
+
#
|
72
|
+
def objectpath namespace, classname = nil, properties = {}
|
73
|
+
op = Sfcc::Cim::ObjectPath.new(namespace, classname, @client)
|
74
|
+
properties.each do |k,v|
|
75
|
+
op.add_key k,v
|
76
|
+
end
|
77
|
+
op
|
63
78
|
end
|
64
79
|
|
65
80
|
#
|
66
81
|
# Return instances for namespace and classname
|
67
82
|
#
|
68
|
-
def each_instance(
|
69
|
-
op =
|
83
|
+
def each_instance( namespace_or_objectpath, classname = nil )
|
84
|
+
op = if namespace_or_objectpath.is_a? Sfcc::Cim::ObjectPath
|
85
|
+
namespace_or_objectpath
|
86
|
+
else
|
87
|
+
objectpath namespace_or_objectpath, classname
|
88
|
+
end
|
70
89
|
begin
|
71
90
|
@client.instances(op).each do |inst|
|
72
91
|
yield inst
|
@@ -76,15 +95,16 @@ public
|
|
76
95
|
end
|
77
96
|
|
78
97
|
#
|
79
|
-
# Return list of classnames for given
|
98
|
+
# Return list of classnames for given object_path
|
80
99
|
#
|
81
|
-
def class_names
|
82
|
-
STDERR.puts "#{@client}.class_names(#{namespace})"
|
100
|
+
def class_names op, deep_inheritance = false
|
83
101
|
ret = []
|
84
|
-
op
|
102
|
+
unless op.is_a? Sfcc::Cim::ObjectPath
|
103
|
+
op = Sfcc::Cim::ObjectPath.new(op.to_s, nil) # assume namespace
|
104
|
+
end
|
85
105
|
flags = deep_inheritance ? Sfcc::Flags::DeepInheritance : 0
|
86
106
|
begin
|
87
|
-
@client.class_names(op,flags).each do |name|
|
107
|
+
@client.class_names(op, flags).each do |name|
|
88
108
|
ret << name.to_s
|
89
109
|
end
|
90
110
|
rescue Sfcc::Cim::ErrorInvalidNamespace
|
@@ -95,10 +115,18 @@ public
|
|
95
115
|
#
|
96
116
|
# Return list of Wbem::EndpointReference (object pathes) for instances
|
97
117
|
# of namespace, classname
|
118
|
+
# @param namespace : String or Sfcc::Cim::ObjectPath
|
119
|
+
# @param classname : String (optional)
|
120
|
+
# @param properties : Hash (optional)
|
98
121
|
#
|
99
|
-
def instance_names namespace, classname
|
100
|
-
|
101
|
-
|
122
|
+
def instance_names namespace, classname=nil, properties={}
|
123
|
+
case namespace
|
124
|
+
when Sfcc::Cim::ObjectPath
|
125
|
+
objectpath = namespace
|
126
|
+
namespace = objectpath.namespace
|
127
|
+
else
|
128
|
+
objectpath = objectpath namespace.to_s, classname, properties
|
129
|
+
end
|
102
130
|
ret = []
|
103
131
|
begin
|
104
132
|
@client.instance_names(objectpath).each do |path|
|
@@ -109,5 +137,24 @@ public
|
|
109
137
|
end
|
110
138
|
ret
|
111
139
|
end
|
140
|
+
|
141
|
+
#
|
142
|
+
# Return matching Wbem::Instance for first instance
|
143
|
+
# matching namespace, classname, properties
|
144
|
+
# @param namespace : String or Sfcc::Cim::ObjectPath
|
145
|
+
# @param classname : String (optional)
|
146
|
+
# @param properties : Hash (optional)
|
147
|
+
#
|
148
|
+
def get_instance namespace, classname=nil, properties={}
|
149
|
+
case namespace
|
150
|
+
when Sfcc::Cim::ObjectPath
|
151
|
+
objectpath = namespace
|
152
|
+
namespace = objectpath.namespace
|
153
|
+
else
|
154
|
+
objectpath = objectpath namespace.to_s, classname, properties
|
155
|
+
end
|
156
|
+
ret = []
|
157
|
+
@client.get_instance(objectpath)
|
158
|
+
end
|
112
159
|
end # class
|
113
160
|
end # module
|
data/lib/wbem/version.rb
CHANGED
data/lib/wbem/wbem.rb
CHANGED
@@ -20,7 +20,7 @@ module Wbem
|
|
20
20
|
|
21
21
|
def initialize url, auth_scheme = :basic
|
22
22
|
@url = (url.is_a? URI) ? url : URI.parse(url)
|
23
|
-
@auth_scheme = auth_scheme.to_s.to_sym
|
23
|
+
@auth_scheme = auth_scheme.to_s.to_sym rescue nil
|
24
24
|
end
|
25
25
|
|
26
26
|
def response_code
|
@@ -35,36 +35,13 @@ module Wbem
|
|
35
35
|
raise "#{self.class}.objectpath not implemented"
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
def _namespaces ns, cn
|
41
|
-
result = nil
|
42
|
-
# each_instance is the downcall to cimxml or wsman
|
43
|
-
each_instance( ns, cn ) do |inst|
|
44
|
-
result ||= [ns]
|
45
|
-
name = "#{ns}/#{inst.Name}"
|
46
|
-
unless result.include? name
|
47
|
-
result << name
|
48
|
-
result.concat(_namespaces name, cn)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
result || []
|
52
|
-
end
|
53
|
-
public
|
54
|
-
# return list of namespaces
|
55
|
-
def namespaces
|
56
|
-
STDERR.puts "Namespaces for #{@url}"
|
57
|
-
result = []
|
58
|
-
['root', 'Interop', 'interop'].each do |ns|
|
59
|
-
["CIM_Namespace", "__Namespace", "__NAMESPACE"].each do |cn|
|
60
|
-
result.concat(_namespaces ns, cn)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
result.uniq
|
38
|
+
def to_s
|
39
|
+
"#{@product}(#{@url})"
|
64
40
|
end
|
65
41
|
|
66
|
-
|
67
|
-
|
42
|
+
public
|
43
|
+
# return list of classnames for ObjectPath op
|
44
|
+
def class_names op, deep_inheritance=false
|
68
45
|
raise "#{self.class}.class_names not implemented"
|
69
46
|
end
|
70
47
|
|
data/lib/wbem/wsman.rb
CHANGED
@@ -20,27 +20,167 @@ module Openwsman
|
|
20
20
|
return nil
|
21
21
|
end
|
22
22
|
end
|
23
|
+
#
|
24
|
+
# Capture Fault as Exception
|
25
|
+
#
|
26
|
+
class Exception < ::RuntimeError
|
27
|
+
def initialize fault
|
28
|
+
unless fault.is_a? Openwsman::Fault
|
29
|
+
raise "#{fault} is not a fault" unless fault.fault?
|
30
|
+
fault = Openwsman::Fault.new fault
|
31
|
+
end
|
32
|
+
@fault = fault
|
33
|
+
end
|
34
|
+
def to_s
|
35
|
+
"Fault code #{@fault.code}, subcode #{@fault.subcode}" +
|
36
|
+
"\n\treason #{@fault.reason}" +
|
37
|
+
"\n\tdetail #{@fault.detail}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
#
|
41
|
+
# Capture namespace, classname, and properties as ObjectPath
|
42
|
+
#
|
23
43
|
class ObjectPath
|
24
|
-
attr_reader :namespace, :classname
|
25
|
-
def initialize namespace, classname = nil
|
44
|
+
attr_reader :namespace, :classname, :properties
|
45
|
+
def initialize namespace, classname = nil, properties = {}
|
26
46
|
@namespace = namespace
|
27
47
|
@classname = classname
|
48
|
+
@properties = properties
|
28
49
|
end
|
29
50
|
end
|
30
|
-
#
|
51
|
+
#
|
52
|
+
# Provide Cim::ObjectPath like accessors for EndPointReference
|
53
|
+
#
|
31
54
|
class EndPointReference
|
32
|
-
alias keys selector_names
|
33
|
-
alias key_count selector_count
|
34
|
-
alias add_key add_selector
|
55
|
+
alias :keys :selector_names
|
56
|
+
alias :key_count :selector_count
|
57
|
+
alias :add_key :add_selector
|
35
58
|
def each_key
|
36
59
|
keys.each { |key| yield key }
|
37
60
|
end
|
38
61
|
end
|
62
|
+
#
|
63
|
+
# Capture XmlDoc + WsmanClient as Instance
|
64
|
+
#
|
65
|
+
class Instance
|
66
|
+
def initialize node, client, epr_or_uri
|
67
|
+
@node = (node.is_a? Openwsman::XmlDoc) ? node.body : node
|
68
|
+
@epr = (epr_or_uri.is_a? Openwsman::EndPointReference) ? epr_or_uri : Openwsman::EndPointReference.new(epr_or_uri)
|
69
|
+
@client = client
|
70
|
+
end
|
71
|
+
#
|
72
|
+
#
|
73
|
+
#
|
74
|
+
def to_s
|
75
|
+
"Instance #{@client}\n\t#{@epr}\n\t#{@node.to_xml}"
|
76
|
+
end
|
77
|
+
#
|
78
|
+
# Instance#<property>
|
79
|
+
# Instance#<method>(<args>)
|
80
|
+
#
|
81
|
+
def method_missing name, *args
|
82
|
+
if args.empty?
|
83
|
+
# try property first
|
84
|
+
res = @node.send name
|
85
|
+
return res.text if res
|
86
|
+
end
|
87
|
+
# try as method invocation
|
88
|
+
options = Openwsman::ClientOptions.new
|
89
|
+
options.set_dump_request
|
90
|
+
selectors = {}
|
91
|
+
@epr.each do |k,v|
|
92
|
+
selectors[k] = v
|
93
|
+
end
|
94
|
+
options.selectors = selectors # instance key properties
|
95
|
+
uri = @epr.resource_uri
|
96
|
+
|
97
|
+
#
|
98
|
+
# get method input parameter information
|
99
|
+
#
|
100
|
+
classname = @epr.classname
|
101
|
+
s = "mof/#{classname}"
|
102
|
+
begin
|
103
|
+
require s
|
104
|
+
rescue LoadError
|
105
|
+
raise RuntimeError.new "Cannot load #{s} for type information"
|
106
|
+
end
|
107
|
+
methods = MOF.class_eval "#{classname}::METHODS"
|
108
|
+
method = methods[name.to_s]
|
109
|
+
raise RuntimeError.new("Unknown method #{name} for #{classname}") unless method
|
110
|
+
result_type = method[:type]
|
111
|
+
parameters = method[:parameters] || {}
|
112
|
+
input = parameters[:in]
|
113
|
+
output = parameters[:out]
|
114
|
+
argsin = {}
|
115
|
+
i = 0
|
116
|
+
if input
|
117
|
+
while i < input.size
|
118
|
+
value = args.shift
|
119
|
+
raise "Argument for #{input[i]} is nil, not allowed !" unless value
|
120
|
+
argsin[input[i]] = value
|
121
|
+
# FIXME more typecheck of args ?
|
122
|
+
i += 2
|
123
|
+
end
|
124
|
+
end
|
125
|
+
STDERR.puts "\n\tproperties #{argsin.inspect}\n"
|
126
|
+
options.properties = argsin
|
127
|
+
#
|
128
|
+
# output parameters ?
|
129
|
+
#
|
130
|
+
argsout = nil
|
131
|
+
if output
|
132
|
+
if args.empty?
|
133
|
+
raise "Function #{name} has output arguments, please add an empty hash to the call"
|
134
|
+
end
|
135
|
+
argsout = args.shift
|
136
|
+
unless argsout.kind_of? Hash
|
137
|
+
raise "Function #{name} has output arguments, last argument must be a Hash"
|
138
|
+
end
|
139
|
+
unless args.empty?
|
140
|
+
raise "Function call to #{name} has excess arguments"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
STDERR.puts "\n\targsout #{argsout.inspect}\n"
|
144
|
+
Openwsman.debug = -1
|
145
|
+
STDERR.puts "\n\tinvoke #{uri}.#{name}\n"
|
146
|
+
res = @client.client.invoke(options, uri, name.to_s)
|
147
|
+
raise Openwsman::Exception.new(res) if res.fault?
|
148
|
+
STDERR.puts "\n\tresult #{res.to_xml}\n"
|
149
|
+
result = res.find(uri, "#{name}_OUTPUT").find(uri, "ReturnValue").text
|
150
|
+
case result_type
|
151
|
+
when :boolean
|
152
|
+
result == "true" ? true : false
|
153
|
+
when :uint8, :uint16, :uint32, :uint64
|
154
|
+
result.to_i
|
155
|
+
when :string
|
156
|
+
result
|
157
|
+
when :float
|
158
|
+
result.to_f
|
159
|
+
when :datetime
|
160
|
+
else
|
161
|
+
raise "Unsupported result_type #{result_type.inspect}"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
39
165
|
end
|
40
166
|
|
167
|
+
|
41
168
|
module Wbem
|
42
169
|
class WsmanClient < WbemClient
|
43
170
|
private
|
171
|
+
#
|
172
|
+
# create end point reference URI
|
173
|
+
#
|
174
|
+
def epr_uri_for(namespace,classname)
|
175
|
+
case @product
|
176
|
+
when :winrm
|
177
|
+
# winrm embeds namespace in resource URI
|
178
|
+
Openwsman::epr_uri_for(namespace,classname) rescue "http://schema.suse.com/wbem/wscim/1/cim-schema/2/#{namespace}/#{classname}"
|
179
|
+
else
|
180
|
+
(Openwsman::epr_prefix_for(classname)+"/#{classname}") rescue "http://schema.suse.com/wbem/wscim/1/cim-schema/2/#{classname}"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
44
184
|
#
|
45
185
|
# Handle client connection or protocol fault
|
46
186
|
#
|
@@ -48,15 +188,17 @@ private
|
|
48
188
|
#
|
49
189
|
def _handle_fault client, result
|
50
190
|
if result.nil?
|
51
|
-
STDERR.puts "Client connection failed:\n\tResult code #{
|
191
|
+
STDERR.puts "Client connection failed:\n\tResult code #{client.response_code}, Fault: #{client.fault_string}" if Wbem.debug
|
52
192
|
return true
|
53
193
|
end
|
54
194
|
if result.fault?
|
55
195
|
fault = Openwsman::Fault.new result
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
196
|
+
if Wbem.debug
|
197
|
+
STDERR.puts "Client protocol failed for (#{client})"
|
198
|
+
STDERR.puts "\tFault code #{fault.code}, subcode #{fault.subcode}"
|
199
|
+
STDERR.puts "\t\treason #{fault.reason}"
|
200
|
+
STDERR.puts "\t\tdetail #{fault.detail}"
|
201
|
+
end
|
60
202
|
return true
|
61
203
|
end
|
62
204
|
false
|
@@ -73,13 +215,14 @@ private
|
|
73
215
|
end
|
74
216
|
if doc.fault?
|
75
217
|
fault = doc.fault
|
76
|
-
STDERR.puts "Fault: #{fault.to_xml}"
|
77
|
-
raise fault
|
218
|
+
STDERR.puts "Fault: #{fault.to_xml}" if Wbem.debug
|
219
|
+
raise Openwsman::Exception.new fault
|
78
220
|
end
|
79
221
|
# STDERR.puts "Return #{doc.to_xml}"
|
80
222
|
doc
|
81
223
|
end
|
82
224
|
public
|
225
|
+
attr_reader :client
|
83
226
|
|
84
227
|
def initialize uri, auth_scheme = nil
|
85
228
|
super uri, auth_scheme
|
@@ -92,7 +235,7 @@ public
|
|
92
235
|
@client.transport.timeout = 5
|
93
236
|
@client.transport.verify_peer = 0
|
94
237
|
@client.transport.verify_host = 0
|
95
|
-
case @auth_scheme
|
238
|
+
case @auth_scheme.to_s
|
96
239
|
when nil, ""
|
97
240
|
@client.transport.auth_method = nil # negotiate
|
98
241
|
when /none/i
|
@@ -172,15 +315,40 @@ public
|
|
172
315
|
|
173
316
|
end
|
174
317
|
|
175
|
-
|
176
|
-
|
318
|
+
public
|
319
|
+
#
|
320
|
+
# return list of namespaces
|
321
|
+
#
|
322
|
+
def namespaces ns = "root", cn = "__Namespace"
|
323
|
+
result = []
|
324
|
+
each_instance( ns, cn ) do |inst|
|
325
|
+
name = "#{ns}/#{inst.Name}"
|
326
|
+
result << name
|
327
|
+
result.concat namespaces name, cn
|
328
|
+
end
|
329
|
+
result.uniq
|
330
|
+
end
|
331
|
+
|
332
|
+
#
|
333
|
+
# Create ObjectPath from namespace, classname, and properties
|
334
|
+
#
|
335
|
+
def objectpath namespace, classname = nil, properties = {}
|
336
|
+
Openwsman::ObjectPath.new namespace, classname, properties
|
177
337
|
end
|
178
338
|
|
179
|
-
|
339
|
+
#
|
340
|
+
# Enumerate instances
|
341
|
+
#
|
342
|
+
def each_instance( namespace_or_objectpath, classname = nil )
|
343
|
+
op = if namespace_or_objectpath.is_a? Openwsman::ObjectPath
|
344
|
+
namespace_or_objectpath
|
345
|
+
else
|
346
|
+
objectpath namespace_or_objectpath, classname
|
347
|
+
end
|
180
348
|
@options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
|
181
349
|
@options.max_elements = 999
|
182
|
-
|
183
|
-
result = @client.enumerate( @options, nil,
|
350
|
+
uri = epr_uri_for op.namespace, op.classname
|
351
|
+
result = @client.enumerate( @options, nil, uri )
|
184
352
|
loop do
|
185
353
|
if _handle_fault @client, result
|
186
354
|
break
|
@@ -188,34 +356,39 @@ public
|
|
188
356
|
items = result.Items rescue nil
|
189
357
|
if items
|
190
358
|
items.each do |inst|
|
191
|
-
yield inst
|
359
|
+
yield Openwsman::Instance.new(inst, self, uri)
|
192
360
|
end
|
193
361
|
end
|
194
362
|
context = result.context
|
195
363
|
break unless context
|
196
|
-
result = @client.pull( @options, nil,
|
364
|
+
result = @client.pull( @options, nil, uri, context )
|
197
365
|
end
|
198
366
|
end
|
199
367
|
|
200
|
-
|
368
|
+
#
|
369
|
+
# Enumerate class names
|
370
|
+
#
|
371
|
+
def class_names op, deep_inheritance = false
|
201
372
|
@options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
|
202
373
|
@options.max_elements = 999
|
203
|
-
|
374
|
+
namespace = (op.is_a? Sfcc::ObjectPath) ? op.namespace : op
|
375
|
+
classname = (op.is_a? Sfcc::ObjectPath) ? op.classname : nil
|
204
376
|
case @product
|
205
377
|
when :openwsman
|
206
|
-
|
378
|
+
if @product_version < "2.2"
|
207
379
|
STDERR.puts "ENUMERATE_CLASS_NAMES unsupported for #{@product_vendor} #{@product_version}, please upgrade"
|
208
380
|
return []
|
209
381
|
end
|
210
382
|
method = Openwsman::CIM_ACTION_ENUMERATE_CLASS_NAMES
|
211
383
|
uri = Openwsman::XML_NS_CIM_INTRINSIC
|
384
|
+
@options.cim_namespace = namespace
|
212
385
|
@options.add_selector("DeepInheritance", "True") if deep_inheritance
|
213
386
|
result = @client.invoke( @options, uri, method )
|
214
387
|
when :winrm
|
215
388
|
# see https://github.com/kkaempf/openwsman/blob/master/bindings/ruby/tests/winenum.rb
|
216
389
|
filter = Openwsman::Filter.new
|
217
390
|
query = "select * from meta_class"
|
218
|
-
query << " where __SuperClass is null" unless deep_inheritance
|
391
|
+
query << " where __SuperClass is #{classname?classname:'null'}" unless deep_inheritance
|
219
392
|
filter.wql query
|
220
393
|
uri = "#{@prefix}#{namespace}/*"
|
221
394
|
result = @client.enumerate( @options, filter, uri )
|
@@ -247,19 +420,43 @@ public
|
|
247
420
|
break unless context
|
248
421
|
# get the next chunk
|
249
422
|
result = @client.pull( @options, nil, uri, context)
|
250
|
-
break if _handle_fault
|
423
|
+
break if _handle_fault @client, result
|
251
424
|
end
|
252
425
|
end
|
253
426
|
return classes
|
254
427
|
end
|
255
428
|
|
256
|
-
|
429
|
+
#
|
430
|
+
# Return list of Wbem::EndpointReference (object pathes) for instances
|
431
|
+
# of namespace, classname
|
432
|
+
# @param namespace : String or Sfcc::Cim::ObjectPath
|
433
|
+
# @param classname : String (optional)
|
434
|
+
# @param properties : Hash (optional)
|
435
|
+
#
|
436
|
+
def instance_names namespace, classname=nil, properties = {}
|
437
|
+
case namespace
|
438
|
+
when Openwsman::ObjectPath
|
439
|
+
classname = namespace.classname
|
440
|
+
properties = namespace.properties
|
441
|
+
namespace = namespace.namespace
|
442
|
+
uri = epr_uri_for(namespace,classname)
|
443
|
+
when Openwsman::EndPointReference
|
444
|
+
namespace.each do |k,v|
|
445
|
+
properties[k] = v
|
446
|
+
end
|
447
|
+
classname = namespace.classname
|
448
|
+
uri = namespace.resource_uri
|
449
|
+
namespace = namespace.namespace
|
450
|
+
else
|
451
|
+
uri = epr_uri_for(namespace, classname)
|
452
|
+
end
|
257
453
|
@options.flags = Openwsman::FLAG_ENUMERATION_ENUM_EPR # get EPRs
|
258
454
|
@options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
|
259
455
|
@options.max_elements = 999
|
260
456
|
@options.cim_namespace = namespace if @product == :openwsman
|
261
457
|
@options.set_dump_request
|
262
|
-
|
458
|
+
@options.selectors = properties unless properties.empty?
|
459
|
+
start = Time.now
|
263
460
|
STDERR.puts "instance_names enumerate (#{uri})"
|
264
461
|
result = @client.enumerate( @options, nil, uri )
|
265
462
|
names = []
|
@@ -278,8 +475,42 @@ public
|
|
278
475
|
break unless context
|
279
476
|
result = @client.pull( @options, nil, uri, context )
|
280
477
|
end
|
478
|
+
STDERR.puts "Enumerated #{names.size} items in #{Time.now-start} seconds"
|
281
479
|
return names
|
282
480
|
end
|
283
|
-
|
481
|
+
|
482
|
+
#
|
483
|
+
# Return matching Wbem::Instance for first instance
|
484
|
+
# matching namespace, classname, properties
|
485
|
+
# @param namespace : String or Sfcc::Cim::ObjectPath
|
486
|
+
# @param classname : String (optional)
|
487
|
+
# @param properties : Hash (optional)
|
488
|
+
#
|
489
|
+
def get_instance namespace, classname=nil, properties={}
|
490
|
+
case namespace
|
491
|
+
when Openwsman::ObjectPath
|
492
|
+
classname = namespace.classname
|
493
|
+
properties = namespace.properties
|
494
|
+
namespace = namespace.namespace
|
495
|
+
uri = epr_uri_for(namespace, classname)
|
496
|
+
when Openwsman::EndPointReference
|
497
|
+
namespace.each do |k,v|
|
498
|
+
properties[k] = v
|
499
|
+
end
|
500
|
+
classname = namespace.classname
|
501
|
+
uri = namespace.resource_uri
|
502
|
+
namespace = namespace.namespace
|
503
|
+
else
|
504
|
+
uri = epr_uri_for(namespace, classname)
|
505
|
+
end
|
506
|
+
@options.set_dump_request
|
507
|
+
@options.cim_namespace = namespace if @product == :openwsman
|
508
|
+
@options.selectors = properties unless properties.empty?
|
509
|
+
STDERR.puts "@client.get(namepace '#{@options.cim_namespace}', props #{properties.inspect}, uri #{uri}"
|
510
|
+
res = @client.get(@options, uri)
|
511
|
+
raise Openwsman::Exception.new res if res.fault?
|
512
|
+
Openwsman::Instance.new res, self, Openwsman::EndPointReference.new(uri, "", properties)
|
513
|
+
end
|
514
|
+
|
284
515
|
end
|
285
|
-
end # module
|
516
|
+
end # module
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wbem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-04-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0.5'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.5'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: sfcc
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 0.4.1
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.4.1
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: openwsman
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,7 +53,12 @@ dependencies:
|
|
43
53
|
version: 2.3.2
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.3.2
|
47
62
|
description: ruby-wbem allows to access a CIMOM transparently through CIM/XML or WS-Management
|
48
63
|
email:
|
49
64
|
- kkaempf@suse.de
|
@@ -51,11 +66,11 @@ executables: []
|
|
51
66
|
extensions: []
|
52
67
|
extra_rdoc_files: []
|
53
68
|
files:
|
54
|
-
- lib/wbem.rb
|
55
|
-
- lib/wbem/wbem.rb
|
56
|
-
- lib/wbem/cimxml.rb
|
57
69
|
- lib/wbem/version.rb
|
70
|
+
- lib/wbem/cimxml.rb
|
71
|
+
- lib/wbem/wbem.rb
|
58
72
|
- lib/wbem/wsman.rb
|
73
|
+
- lib/wbem.rb
|
59
74
|
- CHANGELOG.rdoc
|
60
75
|
- README.rdoc
|
61
76
|
homepage: http://www.github.com/kkaempf/ruby-wbem
|
@@ -79,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
94
|
version: 1.3.6
|
80
95
|
requirements: []
|
81
96
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.8.
|
97
|
+
rubygems_version: 1.8.23
|
83
98
|
signing_key:
|
84
99
|
specification_version: 3
|
85
100
|
summary: WBEM client for Ruby based on ruby-sfcc and openwsman
|