wbem 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +20 -0
- data/Gemfile +2 -0
- data/MIT-LICENSE +22 -0
- data/Rakefile +6 -0
- data/bin/genclassinfo +59 -0
- data/lib/wbem.rb +8 -4
- data/lib/wbem/cimxml.rb +73 -1
- data/lib/wbem/class_factory.rb +163 -0
- data/lib/wbem/class_template.erb +48 -0
- data/lib/wbem/conversion.rb +173 -0
- data/lib/wbem/openwsman.rb +51 -0
- data/lib/wbem/version.rb +1 -1
- data/lib/wbem/wbem.rb +108 -4
- data/lib/wbem/wsman.rb +58 -168
- data/lib/wbem/wsman_instance.rb +148 -0
- data/samples/amt.rb +129 -0
- data/samples/enum.rb +34 -0
- data/samples/get.rb +47 -0
- data/tasks/clean.rake +2 -0
- data/tasks/doc.rake +15 -0
- data/tasks/test.rake +6 -0
- data/test/helper.rb +3 -0
- data/test/test_class_factory.rb +25 -0
- data/test/test_classnames.rb +68 -0
- data/test/test_connect.rb +91 -0
- data/test/test_epr.rb +27 -0
- data/test/test_loading.rb +13 -0
- data/test/test_namespaces.rb +28 -0
- data/test/test_product.rb +56 -0
- data/test/test_profiles.rb +33 -0
- data/test/test_services.rb +33 -0
- data/test/test_systems.rb +34 -0
- data/wbem.gemspec +37 -0
- metadata +76 -7
@@ -0,0 +1,173 @@
|
|
1
|
+
#
|
2
|
+
# Type conversion
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'openwsman'
|
6
|
+
|
7
|
+
module Wbem
|
8
|
+
class Conversion
|
9
|
+
#
|
10
|
+
# Convert CIM DateTime string representation (see DSP0004, 2.2.1)
|
11
|
+
# to Ruby Time (timestamp) or Float (interval, as seconds with fraction)
|
12
|
+
# 00000000001111111111222222
|
13
|
+
# 01234567890123456789012345
|
14
|
+
# East: yyyymmddhhmmss.mmmmmm+utc -> Time (utc = offset in minutes)
|
15
|
+
# West: yyyymmddhhmmss.mmmmmm-utc -> Time
|
16
|
+
# 2011-11-01T00:00:00Z
|
17
|
+
# Interval: ddddddddhhmmss.mmmmmm:000 -> Float (interval in seconds, with fraction)
|
18
|
+
#
|
19
|
+
def self.cimdatetime_to_ruby str
|
20
|
+
# puts "Cmpi.cimdatetime_to_ruby(#{str})"
|
21
|
+
case str[21,1]
|
22
|
+
when '+', '-'
|
23
|
+
# create Time from yyyymmddhhmmss and utc
|
24
|
+
t = Time.new(str[0,4].to_i, str[4,2].to_i, str[6,2].to_i, str[8,2].to_i, str[10,2].to_i, str[12,2].to_i, str[22,3].to_i * ((str[21,1]=='+')?60:-60))
|
25
|
+
off = str[15,6].to_i / 1000
|
26
|
+
# Add fractional part
|
27
|
+
return t + off
|
28
|
+
when ':'
|
29
|
+
# time offset
|
30
|
+
off = str[0,8].to_i * 24 * 60 * 60
|
31
|
+
off += str[8,2].to_i * 60 * 60 + str[10,2].to_i * 60 + str[12,2].to_i
|
32
|
+
off += str[15,6].to_i / 1000
|
33
|
+
return off
|
34
|
+
when nil
|
35
|
+
# 2011-11-01T00:00:00Z
|
36
|
+
t = Time.new(str[0,4].to_i, str[5,2].to_i, str[8,2].to_i, str[11,2].to_i, str[14,2].to_i, str[17,2].to_i, (str[19,1] == 'Z')?0:0)
|
37
|
+
else
|
38
|
+
begin
|
39
|
+
require 'date'
|
40
|
+
DateTime.parse str
|
41
|
+
rescue
|
42
|
+
raise ::TypeError.new("Invalid CIM DateTime '#{str}'")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Convert Ruby value to CIM DateTime string representation (see DSP0004, 2.2.1)
|
49
|
+
# 00000000001111111111222222
|
50
|
+
# 01234567890123456789012345
|
51
|
+
# East: yyyymmddhhmmss.mmmmmm+utc -> Time (utc = offset in minutes, mmmmmm is the microsecond within the second
|
52
|
+
# West: yyyymmddhhmmss.mmmmmm-utc -> Time
|
53
|
+
# Interval: ddddddddhhmmss.mmmmmm:000 -> Float (interval in seconds, with fraction)
|
54
|
+
#
|
55
|
+
def self.ruby_to_cimdatetime val
|
56
|
+
require 'date'
|
57
|
+
# puts "Cmpi.ruby_to_cimdatetime(#{val}[#{val.class}])"
|
58
|
+
t = nil
|
59
|
+
case val
|
60
|
+
when Time
|
61
|
+
s = val.strftime "%Y%m%d%H%M%S.%6N"
|
62
|
+
utc = val.utc_offset # offset in seconds
|
63
|
+
if utc < 0
|
64
|
+
s << "-"
|
65
|
+
utc = -utc
|
66
|
+
else
|
67
|
+
s << "+"
|
68
|
+
end
|
69
|
+
val = s + ("%03d" % (utc/60))
|
70
|
+
when Numeric
|
71
|
+
if val < 0
|
72
|
+
# treat it as seconds before epoch
|
73
|
+
val = self.ruby_to_cimdatetime( Time.at(val) )
|
74
|
+
else
|
75
|
+
# treat as interval in microseconds
|
76
|
+
secs = (val / 1000000).to_i
|
77
|
+
usecs = (val % 1000000).to_i
|
78
|
+
days = secs / (24 * 60 * 60)
|
79
|
+
secs = secs % (24 * 60 * 60) # seconds within the day
|
80
|
+
hours = (secs / (60 * 60)).to_i
|
81
|
+
secs = secs % (60 * 60)
|
82
|
+
mins = (secs / 60).to_i
|
83
|
+
secs = secs % 60
|
84
|
+
val = "%08d%02d%02d%02d.%06d:000" % [ days, hours, mins, secs, usecs ]
|
85
|
+
end
|
86
|
+
when /^\d{14}\.\d{6}[-+:]\d{3}$/
|
87
|
+
# fallthru
|
88
|
+
when String
|
89
|
+
val = self.ruby_to_cimdatetime val.to_f # retry as Numeric
|
90
|
+
else
|
91
|
+
val = self.ruby_to_cimdatetime val.to_s # retry as string
|
92
|
+
end
|
93
|
+
val
|
94
|
+
end
|
95
|
+
|
96
|
+
# generic type conversion
|
97
|
+
# CIM -> Ruby
|
98
|
+
#
|
99
|
+
def self.to_ruby type, value
|
100
|
+
text = case value
|
101
|
+
when Openwsman::XmlNode
|
102
|
+
value.text
|
103
|
+
when String
|
104
|
+
value
|
105
|
+
else
|
106
|
+
value.to_s
|
107
|
+
end
|
108
|
+
case type
|
109
|
+
when :null,:void
|
110
|
+
nil
|
111
|
+
when :boolean
|
112
|
+
text == 'true'
|
113
|
+
when :char16
|
114
|
+
text.to_i
|
115
|
+
when :string
|
116
|
+
text
|
117
|
+
when :uint8,:sint8,:uint16,:sint16,:uint32,:sint32,:uint64,:sint64
|
118
|
+
text.to_i
|
119
|
+
when :real32,:real64
|
120
|
+
text.to_f
|
121
|
+
when :dateTime
|
122
|
+
Wbem::Conversion.cimdatetime_to_ruby text
|
123
|
+
when :class
|
124
|
+
# puts "to_ruby :class, #{value.to_xml}"
|
125
|
+
uri = value.ResourceURI
|
126
|
+
if uri # assume ResourceURI and SelectorSet
|
127
|
+
# puts "to_ruby :class uri #{uri.text}"
|
128
|
+
epr = Openwsman::EndPointReference.new(uri.text)
|
129
|
+
value.SelectorSet.each do |s|
|
130
|
+
k = s.attr("Name").value
|
131
|
+
v = s.text
|
132
|
+
epr.add_selector(k, v)
|
133
|
+
end
|
134
|
+
epr
|
135
|
+
else
|
136
|
+
# try EndpointReference
|
137
|
+
Openwsman::EndPointReference.new(value.to_xml)
|
138
|
+
end
|
139
|
+
# when :class
|
140
|
+
# when :reference
|
141
|
+
# when :array
|
142
|
+
else
|
143
|
+
raise "Unhandled type in to_ruby #{type.inspect}"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
# generic type conversion
|
147
|
+
# Ruby -> CIM
|
148
|
+
#
|
149
|
+
def self.from_ruby type, value
|
150
|
+
case type
|
151
|
+
when :null,:void
|
152
|
+
""
|
153
|
+
when :boolean
|
154
|
+
(value)?'true':'false'
|
155
|
+
when :char16
|
156
|
+
value.to_s
|
157
|
+
when :string
|
158
|
+
value.to_s
|
159
|
+
when :uint8,:sint8,:uint16,:sint16,:uint32,:sint32,:uint64,:sint64
|
160
|
+
value.to_i.to_s
|
161
|
+
when :real32,:real64
|
162
|
+
value.to_f.to_s
|
163
|
+
when :dateTime
|
164
|
+
Wbem::Conversion.ruby_to_cimdatetime value
|
165
|
+
# when :class
|
166
|
+
# when :reference
|
167
|
+
# when :array
|
168
|
+
else
|
169
|
+
raise "Unhandled type in from_ruby #{type.inspect}"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end # class Conversion
|
173
|
+
end # module Wbem
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Openwsman helper methods for wbem/wsman-instance
|
3
|
+
#
|
4
|
+
|
5
|
+
module Openwsman
|
6
|
+
class Transport
|
7
|
+
def Transport.auth_request_callback( client, auth_type )
|
8
|
+
STDERR.puts "\t *** Transport.auth_request_callback"
|
9
|
+
return nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
#
|
13
|
+
# Capture Fault as Exception
|
14
|
+
#
|
15
|
+
class Exception < ::RuntimeError
|
16
|
+
def initialize fault
|
17
|
+
unless fault.is_a? Openwsman::Fault
|
18
|
+
raise "#{fault} is not a fault" unless fault.fault?
|
19
|
+
fault = Openwsman::Fault.new fault
|
20
|
+
end
|
21
|
+
@fault = fault
|
22
|
+
end
|
23
|
+
def to_s
|
24
|
+
"Fault code #{@fault.code}, subcode #{@fault.subcode}" +
|
25
|
+
"\n\treason \"#{@fault.reason}\"" +
|
26
|
+
"\n\tdetail \"#{@fault.detail}\""
|
27
|
+
end
|
28
|
+
end
|
29
|
+
#
|
30
|
+
# Capture namespace, classname, and properties as ObjectPath
|
31
|
+
#
|
32
|
+
class ObjectPath
|
33
|
+
attr_reader :namespace, :classname, :properties
|
34
|
+
def initialize namespace, classname = nil, properties = {}
|
35
|
+
@namespace = namespace
|
36
|
+
@classname = classname
|
37
|
+
@properties = properties
|
38
|
+
end
|
39
|
+
end
|
40
|
+
#
|
41
|
+
# Provide Cim::ObjectPath like accessors for EndPointReference
|
42
|
+
#
|
43
|
+
class EndPointReference
|
44
|
+
alias :keys :selector_names
|
45
|
+
alias :key_count :selector_count
|
46
|
+
alias :add_key :add_selector
|
47
|
+
def each_key
|
48
|
+
keys.each { |key| yield key }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/wbem/version.rb
CHANGED
data/lib/wbem/wbem.rb
CHANGED
@@ -8,6 +8,10 @@
|
|
8
8
|
# Licensed under the MIT license
|
9
9
|
#
|
10
10
|
module Wbem
|
11
|
+
# class forward declaration
|
12
|
+
class WbemClient; end
|
13
|
+
class WsmanClient < WbemClient; end
|
14
|
+
class CimxmlClient < WbemClient; end
|
11
15
|
#
|
12
16
|
# WbemClient - base class for CimxmlClient and WsmanClient
|
13
17
|
#
|
@@ -23,6 +27,10 @@ module Wbem
|
|
23
27
|
@auth_scheme = auth_scheme.to_s.to_sym rescue nil
|
24
28
|
end
|
25
29
|
|
30
|
+
def factory
|
31
|
+
@factory ||= Wbem::ClassFactory.new
|
32
|
+
end
|
33
|
+
|
26
34
|
def response_code
|
27
35
|
@client.response_code
|
28
36
|
end
|
@@ -44,7 +52,59 @@ public
|
|
44
52
|
def class_names op, deep_inheritance=false
|
45
53
|
raise "#{self.class}.class_names not implemented"
|
46
54
|
end
|
47
|
-
|
55
|
+
|
56
|
+
#
|
57
|
+
# Enumerate class refs
|
58
|
+
# Returns Array of Instance References (Sfcc::Cim::ObjectPath or Openwsman::EndPointReference)
|
59
|
+
#
|
60
|
+
def enumerate classname
|
61
|
+
raise "#{self.class}.enumerate not implemented"
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# get instance by reference
|
66
|
+
#
|
67
|
+
# call-seq
|
68
|
+
# get Openwsman::EndPointReference -> Wbem::Instance
|
69
|
+
# get Sfcc::Cim::ObjectPath -> Wbem::Instance
|
70
|
+
# get EndPointReference-as-String -> Wbem::Instance
|
71
|
+
# get ObjectPath-as-String -> Wbem::Instance
|
72
|
+
# get "ClassName", "key" => "value", :namespace => "root/interop"
|
73
|
+
#
|
74
|
+
def get instance_reference, keys = nil
|
75
|
+
if keys
|
76
|
+
if self.class == Wbem::WsmanClient
|
77
|
+
uri = Openwsman.epr_uri_for "", instance_reference
|
78
|
+
instance_reference = Openwsman::EndPointReference.new(uri, nil, keys)
|
79
|
+
elsif self.class == Wbem::CimxmlClient
|
80
|
+
namespace = keys.delete(:namespace) || "root/cimv2"
|
81
|
+
instance_reference = Sfcc::Cim::ObjectPath.new(namespace, instance_reference)
|
82
|
+
keys.each do |k,v|
|
83
|
+
instance_reference.add_key k, v
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
puts "@client.get #{instance_reference.class}..." if Wbem.debug
|
88
|
+
case instance_reference
|
89
|
+
when Openwsman::EndPointReference
|
90
|
+
get_by_epr instance_reference
|
91
|
+
when Sfcc::Cim::ObjectPath
|
92
|
+
get_by_objectpath instance_reference
|
93
|
+
when String
|
94
|
+
if self.class == WsmanClient
|
95
|
+
get_by_epr Openwsman::EndPointReference.new(instance_reference)
|
96
|
+
elsif self.class == CimxmlClient
|
97
|
+
get_by_objectpath CimxmlClient.parse_object_path(instance_reference)
|
98
|
+
else
|
99
|
+
raise "Unsupported Wbem::get #{instance_reference.class} for #{self.class}"
|
100
|
+
end
|
101
|
+
else
|
102
|
+
raise "Unsupported Wbem::get #{instance_reference.class}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
#
|
106
|
+
# ComputerSystem
|
107
|
+
#
|
48
108
|
def system_class_name
|
49
109
|
case @product
|
50
110
|
when :winrm then "Win32_ComputerSystem"
|
@@ -56,7 +116,10 @@ public
|
|
56
116
|
ns = "" if @product == :iamt
|
57
117
|
instance_names ns, system_class_name
|
58
118
|
end
|
59
|
-
|
119
|
+
|
120
|
+
#
|
121
|
+
# RegisteredProfile
|
122
|
+
#
|
60
123
|
def profile_class_name
|
61
124
|
"CIM_RegisteredProfile"
|
62
125
|
end
|
@@ -64,7 +127,10 @@ public
|
|
64
127
|
ns = "" if @product == :iamt
|
65
128
|
instance_names ns, profile_class_name
|
66
129
|
end
|
67
|
-
|
130
|
+
|
131
|
+
#
|
132
|
+
# Service
|
133
|
+
#
|
68
134
|
def service_class_name
|
69
135
|
case @product
|
70
136
|
when :winrm then "Win32_Service"
|
@@ -80,6 +146,10 @@ public
|
|
80
146
|
ns = "" if @product == :iamt
|
81
147
|
instance_names ns, (@product == :winrm) ? "Win32_Process" : "CIM_Process"
|
82
148
|
end
|
149
|
+
|
150
|
+
#
|
151
|
+
# NetworkAdapter, NetworkPort
|
152
|
+
#
|
83
153
|
def network_class_name
|
84
154
|
case @product
|
85
155
|
when :winrm then "Win32_NetworkAdapter"
|
@@ -92,6 +162,10 @@ public
|
|
92
162
|
ns = "" if @product == :iamt
|
93
163
|
instance_names ns, network_class_name
|
94
164
|
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# DiskDrive, StorageExtent
|
168
|
+
#
|
95
169
|
def storage_class_name
|
96
170
|
case @product
|
97
171
|
when :winrm then "Win32_DiskDrive"
|
@@ -105,5 +179,35 @@ public
|
|
105
179
|
instance_names ns, storage_class_name
|
106
180
|
end
|
107
181
|
|
108
|
-
end # Class
|
182
|
+
end # Class WbemClient
|
183
|
+
|
184
|
+
#
|
185
|
+
# Instance class
|
186
|
+
#
|
187
|
+
# Represents instance of a CIM object on a client
|
188
|
+
#
|
189
|
+
# *ABSTRACT*
|
190
|
+
#
|
191
|
+
# Gets instantiated via a CIM class generated by 'genclassinfo'
|
192
|
+
#
|
193
|
+
#
|
194
|
+
class Instance
|
195
|
+
private
|
196
|
+
#
|
197
|
+
#
|
198
|
+
#
|
199
|
+
def initialize client, reference, data = nil
|
200
|
+
case client
|
201
|
+
when Wbem::WsmanClient
|
202
|
+
require "wbem/wsman_instance"
|
203
|
+
self.extend(WsmanInstance)
|
204
|
+
wsman_initialize client, reference, data
|
205
|
+
when Wbem::CimxmlClient
|
206
|
+
self.extend(CimxmlInstance)
|
207
|
+
cimxml_initialize client, reference, data
|
208
|
+
else
|
209
|
+
STDERR.puts "Unkwown client class #{client.class}"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
109
213
|
end # Module
|
data/lib/wbem/wsman.rb
CHANGED
@@ -8,164 +8,13 @@
|
|
8
8
|
# Licensed under the MIT license
|
9
9
|
#
|
10
10
|
require "wbem/wbem"
|
11
|
+
require "wbem/wsman_instance"
|
11
12
|
require "openwsman"
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
module Openwsman
|
17
|
-
class Transport
|
18
|
-
def Transport.auth_request_callback( client, auth_type )
|
19
|
-
STDERR.puts "\t *** Transport.auth_request_callback"
|
20
|
-
return nil
|
21
|
-
end
|
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
|
-
#
|
43
|
-
class ObjectPath
|
44
|
-
attr_reader :namespace, :classname, :properties
|
45
|
-
def initialize namespace, classname = nil, properties = {}
|
46
|
-
@namespace = namespace
|
47
|
-
@classname = classname
|
48
|
-
@properties = properties
|
49
|
-
end
|
50
|
-
end
|
51
|
-
#
|
52
|
-
# Provide Cim::ObjectPath like accessors for EndPointReference
|
53
|
-
#
|
54
|
-
class EndPointReference
|
55
|
-
alias :keys :selector_names
|
56
|
-
alias :key_count :selector_count
|
57
|
-
alias :add_key :add_selector
|
58
|
-
def each_key
|
59
|
-
keys.each { |key| yield key }
|
60
|
-
end
|
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
|
165
|
-
end
|
166
|
-
|
13
|
+
require "wbem/openwsman"
|
14
|
+
require "cim"
|
167
15
|
|
168
16
|
module Wbem
|
17
|
+
|
169
18
|
class WsmanClient < WbemClient
|
170
19
|
private
|
171
20
|
#
|
@@ -221,13 +70,32 @@ private
|
|
221
70
|
# STDERR.puts "Return #{doc.to_xml}"
|
222
71
|
doc
|
223
72
|
end
|
73
|
+
#
|
74
|
+
# Get Wbem::Instance by EndPointReference
|
75
|
+
#
|
76
|
+
def get_by_epr epr
|
77
|
+
options = Openwsman::ClientOptions.new
|
78
|
+
options.set_dump_request if Wbem.debug
|
79
|
+
# puts "***\t@client.get_by_epr #{epr.GroupComponent}\n"
|
80
|
+
doc = @client.get_from_epr( options, epr )
|
81
|
+
unless doc
|
82
|
+
raise RuntimeError.new "Identify failed: HTTP #{@client.response_code}, Err #{@client.last_error}:#{@client.fault_string}"
|
83
|
+
end
|
84
|
+
puts doc.to_xml if Wbem.debug
|
85
|
+
if doc.fault?
|
86
|
+
raise Openwsman::Fault.new(doc).to_s
|
87
|
+
end
|
88
|
+
klass = factory.class_for epr.classname
|
89
|
+
klass.new self, epr, doc
|
90
|
+
end
|
91
|
+
|
224
92
|
public
|
225
93
|
attr_reader :client
|
226
94
|
|
227
95
|
def initialize uri, auth_scheme = nil
|
228
96
|
super uri, auth_scheme
|
229
97
|
@url.path = "/wsman" if @url.path.nil? || @url.path.empty?
|
230
|
-
|
98
|
+
Openwsman::debug = -1 if Wbem.debug
|
231
99
|
STDERR.puts "WsmanClient connecting to #{uri}, auth #{@auth_scheme.inspect}" if Wbem.debug
|
232
100
|
|
233
101
|
@client = Openwsman::Client.new @url.to_s
|
@@ -254,7 +122,7 @@ public
|
|
254
122
|
raise "Unknown auth_scheme #{@auth_scheme.inspect}"
|
255
123
|
end
|
256
124
|
@options = Openwsman::ClientOptions.new
|
257
|
-
|
125
|
+
|
258
126
|
# STDERR.puts "auth #{@auth_scheme.inspect} -> #{@client.transport.auth_method}"
|
259
127
|
|
260
128
|
doc = _identify
|
@@ -356,7 +224,7 @@ public
|
|
356
224
|
items = result.Items rescue nil
|
357
225
|
if items
|
358
226
|
items.each do |inst|
|
359
|
-
yield
|
227
|
+
yield Wbem::Instance.new(self, uri, inst)
|
360
228
|
end
|
361
229
|
end
|
362
230
|
context = result.context
|
@@ -450,14 +318,13 @@ public
|
|
450
318
|
else
|
451
319
|
uri = epr_uri_for(namespace, classname)
|
452
320
|
end
|
453
|
-
@options.flags = Openwsman::FLAG_ENUMERATION_ENUM_EPR
|
454
|
-
@options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
|
321
|
+
@options.flags = Openwsman::FLAG_ENUMERATION_ENUM_EPR | Openwsman::FLAG_ENUMERATION_OPTIMIZATION
|
455
322
|
@options.max_elements = 999
|
456
323
|
@options.cim_namespace = namespace if @product == :openwsman
|
457
|
-
@options.set_dump_request
|
324
|
+
@options.set_dump_request if Wbem.debug
|
458
325
|
@options.selectors = properties unless properties.empty?
|
459
326
|
start = Time.now
|
460
|
-
STDERR.puts "instance_names enumerate (#{uri})"
|
327
|
+
STDERR.puts "instance_names enumerate (#{uri})" if Wbem.debug
|
461
328
|
result = @client.enumerate( @options, nil, uri )
|
462
329
|
names = []
|
463
330
|
loop do
|
@@ -475,10 +342,33 @@ public
|
|
475
342
|
break unless context
|
476
343
|
result = @client.pull( @options, nil, uri, context )
|
477
344
|
end
|
478
|
-
STDERR.puts "Enumerated #{names.size} items in #{Time.now-start} seconds"
|
345
|
+
STDERR.puts "Enumerated #{names.size} items in #{Time.now-start} seconds" if Wbem.debug
|
479
346
|
return names
|
480
347
|
end
|
481
348
|
|
349
|
+
#
|
350
|
+
# get instance by reference
|
351
|
+
#
|
352
|
+
# call-seq
|
353
|
+
# get Openwsman::EndPointReference -> Wbem::Instance
|
354
|
+
# get EndPointReference-as-String -> Wbem::Instance
|
355
|
+
# get "ClassName", "key" => "value", :namespace => "root/interop"
|
356
|
+
#
|
357
|
+
def get instance_reference, keys = nil
|
358
|
+
if keys
|
359
|
+
uri = Openwsman.epr_uri_for "", instance_reference
|
360
|
+
instance_reference = Openwsman::EndPointReference.new(uri, nil, keys)
|
361
|
+
end
|
362
|
+
puts "@client.get #{instance_reference.class}..." if Wbem.debug
|
363
|
+
case instance_reference
|
364
|
+
when Openwsman::EndPointReference
|
365
|
+
get_by_epr instance_reference
|
366
|
+
when String
|
367
|
+
get_by_epr Openwsman::EndPointReference.new(instance_reference)
|
368
|
+
else
|
369
|
+
raise "Unsupported Wbem::get #{instance_reference.class}"
|
370
|
+
end
|
371
|
+
end
|
482
372
|
#
|
483
373
|
# Return matching Wbem::Instance for first instance
|
484
374
|
# matching namespace, classname, properties
|
@@ -503,14 +393,14 @@ public
|
|
503
393
|
else
|
504
394
|
uri = epr_uri_for(namespace, classname)
|
505
395
|
end
|
506
|
-
@options.set_dump_request
|
396
|
+
@options.set_dump_request if Wbem.debug
|
507
397
|
@options.cim_namespace = namespace if @product == :openwsman
|
508
398
|
@options.selectors = properties unless properties.empty?
|
509
|
-
STDERR.puts "@client.get(namepace '#{@options.cim_namespace}', props #{properties.inspect}, uri #{uri}"
|
399
|
+
STDERR.puts "@client.get(namepace '#{@options.cim_namespace}', props #{properties.inspect}, uri #{uri}" if Wbem.debug
|
510
400
|
res = @client.get(@options, uri)
|
511
401
|
raise Openwsman::Exception.new res if res.fault?
|
512
|
-
|
402
|
+
Wbem::Instance.new self, Openwsman::EndPointReference.new(uri, "", properties), res
|
513
403
|
end
|
514
404
|
|
515
|
-
end
|
516
|
-
end # module
|
405
|
+
end # class WsmanClient
|
406
|
+
end # module Wbem
|