wbem 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.1.1
2
+
3
+ * Unify 'identify'
4
+ * Add Client#product
5
+
1
6
  == 0.1.0
2
7
 
3
8
  * First public version
data/lib/wbem.rb CHANGED
@@ -1,3 +1,13 @@
1
+ #
2
+ # wbem.rb
3
+ #
4
+ # A CIM client abstraction layer on top of sfcc (cim/xml) and openwsman (WS-Management)
5
+ #
6
+ # Copyright (c) 2011, SUSE Linux Products GmbH
7
+ # Written by Klaus Kaempf <kkaempf@suse.de>
8
+ #
9
+ # Licensed under the MIT license
10
+ #
1
11
  module Wbem
2
12
  @@debug = nil
3
13
  def Wbem.debug
@@ -11,8 +21,6 @@ module Wbem
11
21
  require 'wbem/wsman'
12
22
  require 'wbem/cimxml'
13
23
 
14
- attr_reader :url, :response
15
-
16
24
  #
17
25
  # Wbem::Client.connect uri, protocol = nil
18
26
  #
@@ -23,15 +31,26 @@ module Wbem
23
31
  # else - probe connection (cim/xml first)
24
32
  #
25
33
  def self.connect uri, protocol = nil
26
- STDERR.puts "Wbem::Client.connect(#{uri},#{protocol})" if Wbem.debug
27
- u = uri.is_a?(URI) ? uri : URI.parse(uri)
34
+ STDERR.puts "Wbem::Client.connect(#{uri},#{protocol})"
35
+ unless uri.is_a?(URI)
36
+ u = URI.parse(uri)
37
+ protocol_given = uri.match(/:\d/)
38
+ else
39
+ u = uri
40
+ protocol_given = uri.port
41
+ end
28
42
  case protocol
29
43
  when :wsman
44
+ unless protocol_given
45
+ u.port = (u.scheme == "http") ? 5985 : 5986
46
+ end
30
47
  return WsmanClient.new u
31
48
  when :cimxml
49
+ unless protocol_given
50
+ u.port = (u.scheme == "http") ? 5988 : 5989
51
+ end
32
52
  return CimxmlClient.new u
33
53
  end
34
- STDERR.puts "no connect, check known ports"
35
54
  # no connect, check known ports
36
55
  case u.port
37
56
  when 8888, 8889, 5985, 5986
@@ -39,7 +58,7 @@ module Wbem
39
58
  when 5988, 5989
40
59
  return CimxmlClient.new u
41
60
  end
42
- STDERR.puts "no known ports"
61
+ # STDERR.puts "no known ports"
43
62
  port = u.port # keep orig port as we change u.port below
44
63
  [:wsman, :cimxml].each do |protocol|
45
64
  # enforce port if uri provides scheme and host only
@@ -51,7 +70,7 @@ module Wbem
51
70
  end
52
71
  c = Wbem::Client.connect u, protocol
53
72
  if c
54
- STDERR.puts "Connect #{u} as #{c}"
73
+ # STDERR.puts "Connect #{u} as #{c}"
55
74
  return c
56
75
  end
57
76
  end
data/lib/wbem/cimxml.rb CHANGED
@@ -12,30 +12,44 @@ require "wbem/wbem"
12
12
  module Wbem
13
13
  class CimxmlClient < WbemClient
14
14
  require "sfcc"
15
+ private
16
+ #
17
+ # identify client
18
+ # return identification string
19
+ # on error return nil and set @response to http response code
20
+ #
21
+ def _identify
22
+ # sfcb has /root/interop:CIM_ObjectManager
23
+ sfcb_op = objectpath "root/interop", "CIM_ObjectManager"
24
+ STDERR.puts "Looking for #{sfcb_op}"
25
+ begin
26
+ @client.instances(sfcb_op).each do |inst|
27
+ @product = inst.Description
28
+ break
29
+ end
30
+ rescue Sfcc::Cim::ErrorInvalidClass, Sfcc::Cim::ErrorInvalidNamespace
31
+ # not sfcb
32
+ raise "Unknown CIMOM"
33
+ end
34
+ end
35
+ public
15
36
 
16
37
  def initialize url
17
38
  super url
18
39
  @client = Sfcc::Cim::Client.connect url
40
+ STDERR.puts "CIMXML.connect #{url} -> #{@client}" if Wbem.debug
41
+ _identify
19
42
  end
20
43
 
21
44
  def objectpath namespace, classname = nil
22
45
  Sfcc::Cim::ObjectPath.new(namespace, classname)
23
46
  end
24
47
 
25
- #
26
- # identify client
27
- # return identification string
28
- # on error return nil and set @response to http response code
29
- #
30
- def identify
31
- "CIM/XML client at #{@url.host}:#{@url.port}"
32
- end
33
-
34
48
  #
35
49
  # Return instances for namespace and classname
36
50
  #
37
51
  def each_instance( ns, cn )
38
- op = Sfcc::Cim::ObjectPath.new(ns, cn)
52
+ op = objectpath ns, cn
39
53
  begin
40
54
  @client.instances(op).each do |inst|
41
55
  yield inst
@@ -76,4 +90,4 @@ class CimxmlClient < WbemClient
76
90
  ret
77
91
  end
78
92
  end # class
79
- end # module
93
+ end # module
data/lib/wbem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wbem
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/wbem/wbem.rb CHANGED
@@ -15,6 +15,7 @@ module Wbem
15
15
  require 'uri'
16
16
 
17
17
  attr_reader :url, :response
18
+ attr_reader :product
18
19
 
19
20
  def initialize url
20
21
  @url = (url.is_a? URI) ? url : URI.parse(url)
data/lib/wbem/wsman.rb CHANGED
@@ -31,6 +31,27 @@ end
31
31
 
32
32
  module Wbem
33
33
  class WsmanClient < WbemClient
34
+ private
35
+ #
36
+ # WS-Identify
37
+ # returns Openwsman::XmlDoc
38
+ #
39
+ def _identify
40
+ STDERR.puts "Identify client #{@client} with #{@options}" if Wbem.debug
41
+ doc = @client.identify( @options )
42
+ unless doc
43
+ raise RuntimeError.new "Identify failed: HTTP #{@client.response_code}, Err #{@client.last_error}:#{@client.fault_string}"
44
+ end
45
+ if doc.fault?
46
+ fault = doc.fault
47
+ STDERR.puts "Fault: #{fault.to_xml}"
48
+ raise fault.to_s
49
+ end
50
+ # STDERR.puts "Return #{doc.to_xml}"
51
+ doc
52
+ end
53
+ public
54
+
34
55
  def initialize uri
35
56
  super uri
36
57
  @url.path = "/wsman" if @url.path.nil? || @url.path.empty?
@@ -47,7 +68,7 @@ class WsmanClient < WbemClient
47
68
  @client.transport.auth_method = Openwsman::BASIC_AUTH_STR
48
69
  @options = Openwsman::ClientOptions.new
49
70
 
50
- doc = identify
71
+ doc = _identify
51
72
  # STDERR.puts doc.to_xml
52
73
  @protocol_version = doc.ProtocolVersion.text
53
74
  @product_vendor = doc.ProductVendor.text
@@ -103,25 +124,6 @@ class WsmanClient < WbemClient
103
124
  Openwsman::ObjectPath.new classname, namespace
104
125
  end
105
126
 
106
- #
107
- # WS-Identify
108
- # returns Openwsman::XmlDoc
109
- #
110
- def identify
111
- STDERR.puts "Identify client #{@client} with #{@options}" if Wbem.debug
112
- doc = @client.identify( @options )
113
- unless doc
114
- raise RuntimeError.new "Identify failed: HTTP #{@client.response_code}, Err #{@client.last_error}:#{@client.fault_string}"
115
- end
116
- if doc.fault?
117
- fault = doc.fault
118
- STDERR.puts "Fault: #{fault.to_xml}"
119
- raise fault.to_s
120
- end
121
- # STDERR.puts "Return #{doc.to_xml}"
122
- doc
123
- end
124
-
125
127
  def each_instance( ns, cn )
126
128
  @options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
127
129
  @options.max_elements = 999
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wbem
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Klaus K\xC3\xA4mpf"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-17 00:00:00 +01:00
18
+ date: 2012-01-18 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -33,6 +33,22 @@ dependencies:
33
33
  version: "0.5"
34
34
  type: :development
35
35
  version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: sfcc
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 17
45
+ segments:
46
+ - 0
47
+ - 3
48
+ - 1
49
+ version: 0.3.1
50
+ type: :runtime
51
+ version_requirements: *id002
36
52
  description: ruby-wbem allows to access a CIMOM transparently through CIM/XML or WS-Management
37
53
  email:
38
54
  - kkaempf@suse.de