wbem 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.2.6
2
+
3
+ * Honor iAMT when choosing classnames
4
+ * Detect client connection vs client protocol errors
5
+ * Use optimized enumerations
6
+
1
7
  == 0.2.5
2
8
 
3
9
  * Bugfix release
data/lib/wbem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wbem
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
data/lib/wbem/wbem.rb CHANGED
@@ -68,20 +68,56 @@ public
68
68
  raise "#{self.class}.class_names not implemented"
69
69
  end
70
70
 
71
+ def system_class_name
72
+ case @product
73
+ when :winrm then "Win32_ComputerSystem"
74
+ else
75
+ "CIM_ComputerSystem"
76
+ end
77
+ end
71
78
  def systems ns="root/cimv2"
72
- instance_names ns, (@product == :winrm) ? "Win32_ComputerSystem" : "CIM_ComputerSystem"
79
+ ns = "" if @product == :iamt
80
+ instance_names ns, system_class_name
81
+ end
82
+
83
+ def service_class_name
84
+ case @product
85
+ when :winrm then "Win32_Service"
86
+ else
87
+ "CIM_Service"
88
+ end
73
89
  end
74
90
  def services ns="root/cimv2"
75
- instance_names ns, (@product == :winrm) ? "Win32_Service" : "CIM_Service"
91
+ ns = "" if @product == :iamt
92
+ instance_names ns, service_class_name
76
93
  end
77
94
  def processes ns="root/cimv2"
95
+ ns = "" if @product == :iamt
78
96
  instance_names ns, (@product == :winrm) ? "Win32_Process" : "CIM_Process"
79
97
  end
98
+ def network_class_name
99
+ case @product
100
+ when :winrm then "Win32_NetworkAdapter"
101
+ when :iamt then "CIM_NetworkPort"
102
+ else
103
+ "CIM_NetworkAdapter"
104
+ end
105
+ end
80
106
  def networks ns="root/cimv2"
81
- instance_names ns, (@product == :winrm) ? "Win32_NetworkAdapter" : "CIM_NetworkAdapter"
107
+ ns = "" if @product == :iamt
108
+ instance_names ns, network_class_name
109
+ end
110
+ def storage_class_name
111
+ case @product
112
+ when :winrm then "Win32_DiskDrive"
113
+ when :iamt then "CIM_StorageExtent"
114
+ else
115
+ "CIM_DiskDrive"
116
+ end
82
117
  end
83
118
  def storages ns="root/cimv2"
84
- instance_names ns, (@product == :winrm) ? "Win32_DiskDrive" : "CIM_DiskDrive"
119
+ ns = "" if @product == :iamt
120
+ instance_names ns, storage_class_name
85
121
  end
86
122
 
87
123
  end # Class
data/lib/wbem/wsman.rb CHANGED
@@ -41,6 +41,26 @@ end
41
41
  module Wbem
42
42
  class WsmanClient < WbemClient
43
43
  private
44
+ #
45
+ # Handle client connection or protocol fault
46
+ #
47
+ # @return: true if fault
48
+ #
49
+ def _handle_fault client, result
50
+ if result.nil?
51
+ STDERR.puts "Client connection failed:\n\tResult code #{@client.response_code}, Fault: #{@client.fault_string}"
52
+ return true
53
+ end
54
+ if result.fault?
55
+ fault = Openwsman::Fault.new result
56
+ STDERR.puts "Client protocol failed for (#{uri})"
57
+ STDERR.puts "\tFault code #{fault.code}, subcode #{fault.subcode}"
58
+ STDERR.puts "\t\treason #{fault.reason}"
59
+ STDERR.puts "\t\tdetail #{fault.detail}"
60
+ return true
61
+ end
62
+ false
63
+ end
44
64
  #
45
65
  # WS-Identify
46
66
  # returns Openwsman::XmlDoc
@@ -161,19 +181,26 @@ public
161
181
  @options.max_elements = 999
162
182
  resource = "#{@prefix}#{ns}/#{cn}"
163
183
  result = @client.enumerate( @options, nil, resource )
164
- return unless result
165
- # STDERR.puts "Result '#{result.to_xml}'"
166
- return if result.fault?
167
- items = result.body.EnumerateResponse.Items rescue nil
168
- items.each do |inst|
169
- yield inst
170
- end if items
184
+ loop do
185
+ if _handle_fault @client, result
186
+ break
187
+ end
188
+ items = result.Items rescue nil
189
+ if items
190
+ items.each do |inst|
191
+ yield inst
192
+ end
193
+ end
194
+ context = result.context
195
+ break unless context
196
+ result = @client.pull( @options, nil, resource, context )
197
+ end
171
198
  end
172
199
 
173
200
  def class_names namespace, deep_inheritance = false
174
201
  @options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
175
202
  @options.max_elements = 999
176
- @options.cim_namespace = namespace
203
+ @options.cim_namespace = namespace if @product == :openwsman
177
204
  case @product
178
205
  when :openwsman
179
206
  unless @product_version >= "2.2"
@@ -196,8 +223,7 @@ public
196
223
  raise "Unsupported for WSMAN product #{@product}"
197
224
  end
198
225
 
199
- if result.fault?
200
- puts "Enumerate class names (#{uri}) failed:\n\tResult code #{@client.response_code}, Fault: #{@client.fault_string}"
226
+ if _handle_fault @client, result
201
227
  return []
202
228
  end
203
229
 
@@ -221,7 +247,7 @@ public
221
247
  break unless context
222
248
  # get the next chunk
223
249
  result = @client.pull( @options, nil, uri, context)
224
- break unless result
250
+ break if _handle_fault
225
251
  end
226
252
  end
227
253
  return classes
@@ -231,18 +257,26 @@ public
231
257
  @options.flags = Openwsman::FLAG_ENUMERATION_ENUM_EPR # get EPRs
232
258
  @options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
233
259
  @options.max_elements = 999
234
- @options.cim_namespace = namespace
260
+ @options.cim_namespace = namespace if @product == :openwsman
261
+ @options.set_dump_request
235
262
  uri = Openwsman::epr_prefix_for(classname, namespace) + "/#{classname}"
263
+ STDERR.puts "instance_names enumerate (#{uri})"
236
264
  result = @client.enumerate( @options, nil, uri )
237
- if result.fault?
238
- puts "Enumerate instances (#{uri}) failed:\n\tResult code #{@client.response_code}, Fault: #{@client.fault_string}"
239
- return []
240
- end
241
-
242
265
  names = []
243
- # expect <n:Item><a:EndpointReference>...
244
- result.Items.each do |epr|
245
- names << Openwsman::EndPointReference.new(epr)
266
+ loop do
267
+ if _handle_fault @client, result
268
+ break
269
+ end
270
+ items = result.Items
271
+ if items
272
+ # expect <n:Item><a:EndpointReference>...
273
+ items.each do |epr|
274
+ names << Openwsman::EndPointReference.new(epr)
275
+ end
276
+ end
277
+ context = result.context
278
+ break unless context
279
+ result = @client.pull( @options, nil, uri, context )
246
280
  end
247
281
  return names
248
282
  end
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.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yard
16
- requirement: &5664600 !ruby/object:Gem::Requirement
16
+ requirement: &5664140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.5'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *5664600
24
+ version_requirements: *5664140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sfcc
27
- requirement: &5663140 !ruby/object:Gem::Requirement
27
+ requirement: &5663580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.4.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *5663140
35
+ version_requirements: *5663580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: openwsman
38
- requirement: &5653060 !ruby/object:Gem::Requirement
38
+ requirement: &5662940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 2.3.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *5653060
46
+ version_requirements: *5662940
47
47
  description: ruby-wbem allows to access a CIMOM transparently through CIM/XML or WS-Management
48
48
  email:
49
49
  - kkaempf@suse.de