Class: Wbem::WsmanClient
- Inherits:
-
WbemClient
show all
- Defined in:
- lib/wbem/wsman.rb
Instance Attribute Summary
Attributes inherited from WbemClient
#auth_scheme, #product, #response, #url
Instance Method Summary
(collapse)
Methods inherited from WbemClient
#fault_string, #namespaces, #network_class_name, #networks, #processes, #response_code, #service_class_name, #services, #storage_class_name, #storages, #system_class_name, #systems
Constructor Details
- (WsmanClient) initialize(uri, auth_scheme = nil)
A new instance of WsmanClient
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/wbem/wsman.rb', line 84
def initialize uri, auth_scheme = nil
super uri, auth_scheme
@url.path = "/wsman" if @url.path.nil? || @url.path.empty?
STDERR.puts "WsmanClient connecting to #{uri}, auth #{@auth_scheme.inspect}" if Wbem.debug
@client = Openwsman::Client.new @url.to_s
raise "Cannot create Openwsman client" unless @client
@client.transport.timeout = 5
@client.transport.verify_peer = 0
@client.transport.verify_host = 0
case @auth_scheme
when nil, ""
@client.transport.auth_method = nil when /none/i
@client.transport.auth_method = Openwsman::NO_AUTH_STR
when /basic/i
@client.transport.auth_method = Openwsman::BASIC_AUTH_STR
when /digest/i
@client.transport.auth_method = Openwsman::DIGEST_AUTH_STR
when /pass/i
@client.transport.auth_method = Openwsman::PASS_AUTH_STR
when /ntlm/i
@client.transport.auth_method = Openwsman::NTLM_AUTH_STR
when /gss/i
@client.transport.auth_method = Openwsman::GSSNEGOTIATE_AUTH_STR
else
raise "Unknown auth_scheme #{@auth_scheme.inspect}"
end
@options = Openwsman::ClientOptions.new
doc = _identify
@protocol_version = doc.ProtocolVersion.text
@product_vendor = doc.ProductVendor.text
@product_version = doc.ProductVersion.text
if Wbem.debug
STDERR.puts "Protocol_version '#{@protocol_version}'"
STDERR.puts "Product vendor '#{@product_vendor}'"
STDERR.puts "Product version '#{@product_version}'"
end
unless @protocol_version == Openwsman::XML_NS_WS_MAN
raise "Unsupported WS-Management protocol '#{@protocol_version}'"
end
case @product_vendor
when /Microsoft/i
@prefix = "http://schemas.microsoft.com/wbem/wsman/1/wmi/"
if @product_version =~ /^OS:\s([\d\.]+)\sSP:\s([\d\.]+)\sStack:\s([\d\.]+)$/
@product_version = $3
else
STDERR.puts "Unrecognized product version #{@product_version}"
end
@product = :winrm
when /Openwsman/i
@prefix = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"
@product = :openwsman
when /Intel/i
@prefix = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"
@product = :iamt
if @product_version =~ /^AMT\s(\d\.\d)$/
@product_version = $1
end
else
STDERR.puts "Unsupported WS-Management vendor #{@product_vendor}"
@prefix = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"
@product = :unknown
end
STDERR.puts "Connected to vendor '#{@product_vendor}', Version #{@product_version}" if Wbem.debug
end
|
Instance Method Details
- (Object) class_names(namespace, deep_inheritance = false)
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/wbem/wsman.rb', line 200
def class_names namespace, deep_inheritance = false
@options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
@options.max_elements = 999
@options.cim_namespace = namespace if @product == :openwsman
case @product
when :openwsman
unless @product_version >= "2.2"
STDERR.puts "ENUMERATE_CLASS_NAMES unsupported for #{@product_vendor} #{@product_version}, please upgrade"
return []
end
method = Openwsman::CIM_ACTION_ENUMERATE_CLASS_NAMES
uri = Openwsman::XML_NS_CIM_INTRINSIC
@options.add_selector("DeepInheritance", "True") if deep_inheritance
result = @client.invoke( @options, uri, method )
when :winrm
filter = Openwsman::Filter.new
query = "select * from meta_class"
query << " where __SuperClass is null" unless deep_inheritance
filter.wql query
uri = "#{@prefix}#{namespace}/*"
result = @client.enumerate( @options, filter, uri )
else
raise "Unsupported for WSMAN product #{@product}"
end
if _handle_fault @client, result
return []
end
classes = []
case @product
when :openwsman
output = result.body[method]
output.each do |c|
classes << c.to_s
end
when :winrm
loop do
output = result.Items
output.each do |node|
classes << node.name.to_s
end if output
context = result.context
break unless context
result = @client.pull( @options, nil, uri, context)
break if _handle_fault
end
end
return classes
end
|
- (Object) each_instance(ns, cn)
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/wbem/wsman.rb', line 179
def each_instance( ns, cn )
@options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
@options.max_elements = 999
resource = "#{@prefix}#{ns}/#{cn}"
result = @client.enumerate( @options, nil, resource )
loop do
if _handle_fault @client, result
break
end
items = result.Items rescue nil
if items
items.each do |inst|
yield inst
end
end
context = result.context
break unless context
result = @client.pull( @options, nil, resource, context )
end
end
|
- (Object) instance_names(namespace, classname)
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
# File 'lib/wbem/wsman.rb', line 256
def instance_names namespace, classname
@options.flags = Openwsman::FLAG_ENUMERATION_ENUM_EPR @options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
@options.max_elements = 999
@options.cim_namespace = namespace if @product == :openwsman
@options.set_dump_request
uri = Openwsman::epr_prefix_for(classname, namespace) + "/#{classname}"
STDERR.puts "instance_names enumerate (#{uri})"
result = @client.enumerate( @options, nil, uri )
names = []
loop do
if _handle_fault @client, result
break
end
items = result.Items
if items
items.each do |epr|
names << Openwsman::EndPointReference.new(epr)
end
end
context = result.context
break unless context
result = @client.pull( @options, nil, uri, context )
end
return names
end
|
- (Object) objectpath(classname, namespace)
175
176
177
|
# File 'lib/wbem/wsman.rb', line 175
def objectpath classname, namespace
Openwsman::ObjectPath.new classname, namespace
end
|