wbem 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +10 -0
- data/lib/wbem.rb +7 -6
- data/lib/wbem/cimxml.rb +9 -5
- data/lib/wbem/version.rb +1 -1
- data/lib/wbem/wbem.rb +18 -3
- data/lib/wbem/wsman.rb +41 -21
- metadata +37 -70
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 0.2.3
|
2
|
+
|
3
|
+
* Make #instance_names return generic result
|
4
|
+
* Implement #systems, #services, #processes, #networks and #storages
|
5
|
+
|
6
|
+
== 0.2.1
|
7
|
+
|
8
|
+
* add 'auth_scheme' to client connection
|
9
|
+
* support Intel AMT
|
10
|
+
|
1
11
|
== 0.2.0
|
2
12
|
|
3
13
|
* add 'class_names', supporting WINRM
|
data/lib/wbem.rb
CHANGED
@@ -16,6 +16,7 @@ module Wbem
|
|
16
16
|
def Wbem.debug= level
|
17
17
|
@@debug = (level == 0) ? nil : level
|
18
18
|
end
|
19
|
+
|
19
20
|
class Client
|
20
21
|
require 'uri'
|
21
22
|
require 'wbem/wsman'
|
@@ -30,8 +31,8 @@ module Wbem
|
|
30
31
|
# :wsman - connect via WS-Management
|
31
32
|
# else - probe connection (cim/xml first)
|
32
33
|
#
|
33
|
-
def self.connect uri, protocol = nil
|
34
|
-
STDERR.puts "Wbem::Client.connect(#{uri},#{protocol})"
|
34
|
+
def self.connect uri, protocol = nil, auth_scheme = nil
|
35
|
+
STDERR.puts "Wbem::Client.connect(#{uri},#{protocol},#{auth_scheme})"
|
35
36
|
unless uri.is_a?(URI)
|
36
37
|
u = URI.parse(uri)
|
37
38
|
protocol_given = uri.match(/:\d/)
|
@@ -39,12 +40,12 @@ module Wbem
|
|
39
40
|
u = uri
|
40
41
|
protocol_given = uri.port
|
41
42
|
end
|
42
|
-
case protocol
|
43
|
+
case protocol.to_sym
|
43
44
|
when :wsman
|
44
45
|
unless protocol_given
|
45
46
|
u.port = (u.scheme == "http") ? 5985 : 5986
|
46
47
|
end
|
47
|
-
return WsmanClient.new u
|
48
|
+
return WsmanClient.new u, auth_scheme
|
48
49
|
when :cimxml
|
49
50
|
unless protocol_given
|
50
51
|
u.port = (u.scheme == "http") ? 5988 : 5989
|
@@ -54,7 +55,7 @@ module Wbem
|
|
54
55
|
# no connect, check known ports
|
55
56
|
case u.port
|
56
57
|
when 8888, 8889, 5985, 5986
|
57
|
-
return WsmanClient.new u
|
58
|
+
return WsmanClient.new u, auth_scheme
|
58
59
|
when 5988, 5989
|
59
60
|
return CimxmlClient.new u
|
60
61
|
end
|
@@ -68,7 +69,7 @@ module Wbem
|
|
68
69
|
if port == 443 && u.scheme == 'https' # https://hostname
|
69
70
|
u.port = (protocol == :cimxml) ? 5989: 5986
|
70
71
|
end
|
71
|
-
c = Wbem::Client.connect u, protocol
|
72
|
+
c = Wbem::Client.connect u, protocol, auth_scheme
|
72
73
|
if c
|
73
74
|
# STDERR.puts "Connect #{u} as #{c}"
|
74
75
|
return c
|
data/lib/wbem/cimxml.rb
CHANGED
@@ -34,9 +34,10 @@ private
|
|
34
34
|
end
|
35
35
|
public
|
36
36
|
|
37
|
-
def initialize url
|
38
|
-
super url
|
39
|
-
|
37
|
+
def initialize url, auth_scheme = nil
|
38
|
+
super url, auth_scheme
|
39
|
+
STDERR.puts "CIMXML.connect >#{url}<"
|
40
|
+
@client = Sfcc::Cim::Client.connect( { :uri => url, :verify => false } )
|
40
41
|
STDERR.puts "CIMXML.connect #{url} -> #{@client}" if Wbem.debug
|
41
42
|
_identify
|
42
43
|
end
|
@@ -76,13 +77,16 @@ public
|
|
76
77
|
end
|
77
78
|
|
78
79
|
#
|
79
|
-
# Return list of
|
80
|
+
# Return list of Wbem::EndpointReference (object pathes) for instances
|
81
|
+
# of namespace, classname
|
80
82
|
#
|
81
|
-
def instance_names
|
83
|
+
def instance_names namespace, classname
|
84
|
+
objectpath = Sfcc::Cim::ObjectPath.new(namespace,classname)
|
82
85
|
STDERR.puts "#{@client}.instance_names(#{objectpath})"
|
83
86
|
ret = []
|
84
87
|
begin
|
85
88
|
@client.instance_names(objectpath).each do |path|
|
89
|
+
path.namespace = namespace # add missing data
|
86
90
|
ret << path
|
87
91
|
end
|
88
92
|
rescue Sfcc::Cim::ErrorInvalidClass, Sfcc::Cim::ErrorInvalidNamespace
|
data/lib/wbem/version.rb
CHANGED
data/lib/wbem/wbem.rb
CHANGED
@@ -16,9 +16,11 @@ module Wbem
|
|
16
16
|
|
17
17
|
attr_reader :url, :response
|
18
18
|
attr_reader :product
|
19
|
+
attr_accessor :auth_scheme
|
19
20
|
|
20
|
-
def initialize url
|
21
|
+
def initialize url, auth_scheme = :basic
|
21
22
|
@url = (url.is_a? URI) ? url : URI.parse(url)
|
23
|
+
@auth_scheme = auth_scheme.to_s.to_sym
|
22
24
|
end
|
23
25
|
|
24
26
|
def response_code
|
@@ -66,8 +68,21 @@ public
|
|
66
68
|
raise "#{self.class}.class_names not implemented"
|
67
69
|
end
|
68
70
|
|
69
|
-
def
|
70
|
-
|
71
|
+
def systems ns="root/cimv2"
|
72
|
+
instance_names ns, (@product == :winrm) ? "Win32_ComputerSystem" : "CIM_ComputerSystem"
|
71
73
|
end
|
74
|
+
def services ns="root/cimv2"
|
75
|
+
instance_names ns, (@product == :winrm) ? "Win32_Service" : "CIM_Service"
|
76
|
+
end
|
77
|
+
def processes ns="root/cimv2"
|
78
|
+
instance_names ns, (@product == :winrm) ? "Win32_Process" : "CIM_Process"
|
79
|
+
end
|
80
|
+
def networks ns="root/cimv2"
|
81
|
+
instance_names ns, (@product == :winrm) ? "Win32_NetworkAdapter" : "CIM_NetworkAdapter"
|
82
|
+
end
|
83
|
+
def storages ns="root/cimv2"
|
84
|
+
instance_names ns, (@product == :winrm) ? "Win32_DiskDrive" : "CIM_DiskDrive"
|
85
|
+
end
|
86
|
+
|
72
87
|
end # Class
|
73
88
|
end # Module
|
data/lib/wbem/wsman.rb
CHANGED
@@ -52,21 +52,38 @@ private
|
|
52
52
|
end
|
53
53
|
public
|
54
54
|
|
55
|
-
def initialize uri
|
56
|
-
super uri
|
55
|
+
def initialize uri, auth_scheme = nil
|
56
|
+
super uri, auth_scheme
|
57
57
|
@url.path = "/wsman" if @url.path.nil? || @url.path.empty?
|
58
58
|
# Openwsman::debug = -1
|
59
|
-
STDERR.puts "WsmanClient connecting to #{uri}" if Wbem.debug
|
59
|
+
STDERR.puts "WsmanClient connecting to #{uri}, auth #{@auth_scheme.inspect}" if Wbem.debug
|
60
60
|
|
61
61
|
@client = Openwsman::Client.new @url.to_s
|
62
62
|
raise "Cannot create Openwsman client" unless @client
|
63
63
|
@client.transport.timeout = 5
|
64
64
|
@client.transport.verify_peer = 0
|
65
65
|
@client.transport.verify_host = 0
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
case @auth_scheme
|
67
|
+
when nil, ""
|
68
|
+
@client.transport.auth_method = nil # negotiate
|
69
|
+
when /none/i
|
70
|
+
@client.transport.auth_method = Openwsman::NO_AUTH_STR
|
71
|
+
when /basic/i
|
72
|
+
@client.transport.auth_method = Openwsman::BASIC_AUTH_STR
|
73
|
+
when /digest/i
|
74
|
+
@client.transport.auth_method = Openwsman::DIGEST_AUTH_STR
|
75
|
+
when /pass/i
|
76
|
+
@client.transport.auth_method = Openwsman::PASS_AUTH_STR
|
77
|
+
when /ntlm/i
|
78
|
+
@client.transport.auth_method = Openwsman::NTLM_AUTH_STR
|
79
|
+
when /gss/i
|
80
|
+
@client.transport.auth_method = Openwsman::GSSNEGOTIATE_AUTH_STR
|
81
|
+
else
|
82
|
+
raise "Unknown auth_scheme #{@auth_scheme.inspect}"
|
83
|
+
end
|
69
84
|
@options = Openwsman::ClientOptions.new
|
85
|
+
|
86
|
+
# STDERR.puts "auth #{@auth_scheme.inspect} -> #{@client.transport.auth_method}"
|
70
87
|
|
71
88
|
doc = _identify
|
72
89
|
# STDERR.puts doc.to_xml
|
@@ -76,7 +93,7 @@ public
|
|
76
93
|
if Wbem.debug
|
77
94
|
STDERR.puts "Protocol_version '#{@protocol_version}'"
|
78
95
|
STDERR.puts "Product vendor '#{@product_vendor}'"
|
79
|
-
STDERR.puts
|
96
|
+
STDERR.puts "Product version '#{@product_version}'"
|
80
97
|
end
|
81
98
|
#
|
82
99
|
# Windows winrm 2.0
|
@@ -100,7 +117,7 @@ public
|
|
100
117
|
end
|
101
118
|
|
102
119
|
case @product_vendor
|
103
|
-
when
|
120
|
+
when /Microsoft/i
|
104
121
|
@prefix = "http://schemas.microsoft.com/wbem/wsman/1/wmi/"
|
105
122
|
if @product_version =~ /^OS:\s([\d\.]+)\sSP:\s([\d\.]+)\sStack:\s([\d\.]+)$/
|
106
123
|
@product_version = $3
|
@@ -108,9 +125,15 @@ public
|
|
108
125
|
STDERR.puts "Unrecognized product version #{@product_version}"
|
109
126
|
end
|
110
127
|
@product = :winrm
|
111
|
-
when
|
128
|
+
when /Openwsman/i
|
112
129
|
@prefix = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"
|
113
130
|
@product = :openwsman
|
131
|
+
when /Intel/i
|
132
|
+
@prefix = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"
|
133
|
+
@product = :iamt
|
134
|
+
if @product_version =~ /^AMT\s(\d\.\d)$/
|
135
|
+
@product_version = $1
|
136
|
+
end
|
114
137
|
else
|
115
138
|
STDERR.puts "Unsupported WS-Management vendor #{@product_vendor}"
|
116
139
|
@prefix = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"
|
@@ -195,28 +218,25 @@ public
|
|
195
218
|
return classes
|
196
219
|
end
|
197
220
|
|
198
|
-
def instance_names
|
221
|
+
def instance_names namespace, classname
|
199
222
|
@options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
|
200
223
|
@options.max_elements = 999
|
201
|
-
@options.cim_namespace =
|
202
|
-
|
203
|
-
# CIM=http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2
|
204
|
-
# OpenWBEM=http://schema.openwbem.org/wbem/wscim/1/cim-schema/2
|
205
|
-
# Linux=http://sblim.sf.net/wbem/wscim/1/cim-schema/2
|
206
|
-
# OMC=http://schema.omc-project.org/wbem/wscim/1/cim-schema/2
|
207
|
-
# PG=http://schema.openpegasus.org/wbem/wscim/1/cim-schema/2
|
208
|
-
uri = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"+object_path.classname
|
224
|
+
@options.cim_namespace = namespace
|
225
|
+
uri = Openwsman::epr_prefix_for(classname, namespace) + "/#{classname}"
|
209
226
|
result = @client.enumerate( @options, nil, uri )
|
210
227
|
if result.fault?
|
211
228
|
puts "Enumerate instances (#{uri}) failed:\n\tResult code #{@client.response_code}, Fault: #{@client.fault_string}"
|
212
229
|
return []
|
213
230
|
end
|
214
|
-
|
231
|
+
|
215
232
|
instances = []
|
216
|
-
|
217
|
-
|
233
|
+
result.Items.each do |item|
|
234
|
+
item.add(nil, "namespace", namespace)
|
235
|
+
item.add(nil, "classname", classname)
|
236
|
+
instances << item
|
218
237
|
end
|
219
238
|
return instances
|
220
239
|
end
|
240
|
+
|
221
241
|
end
|
222
242
|
end # module
|
metadata
CHANGED
@@ -1,64 +1,45 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: wbem
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
7
|
+
authors:
|
8
|
+
- Klaus Kämpf
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-03-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: yard
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &3187880 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 5
|
33
|
-
version: "0.5"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.5'
|
34
22
|
type: :development
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: sfcc
|
38
23
|
prerelease: false
|
39
|
-
|
24
|
+
version_requirements: *3187880
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sfcc
|
27
|
+
requirement: &3187220 !ruby/object:Gem::Requirement
|
40
28
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 17
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
- 3
|
48
|
-
- 1
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
49
32
|
version: 0.3.1
|
50
33
|
type: :runtime
|
51
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *3187220
|
52
36
|
description: ruby-wbem allows to access a CIMOM transparently through CIM/XML or WS-Management
|
53
|
-
email:
|
37
|
+
email:
|
54
38
|
- kkaempf@suse.de
|
55
39
|
executables: []
|
56
|
-
|
57
40
|
extensions: []
|
58
|
-
|
59
41
|
extra_rdoc_files: []
|
60
|
-
|
61
|
-
files:
|
42
|
+
files:
|
62
43
|
- lib/wbem.rb
|
63
44
|
- lib/wbem/wbem.rb
|
64
45
|
- lib/wbem/cimxml.rb
|
@@ -66,43 +47,29 @@ files:
|
|
66
47
|
- lib/wbem/wsman.rb
|
67
48
|
- CHANGELOG.rdoc
|
68
49
|
- README.rdoc
|
69
|
-
has_rdoc: true
|
70
50
|
homepage: http://www.github.com/kkaempf/ruby-wbem
|
71
51
|
licenses: []
|
72
|
-
|
73
|
-
|
74
|
-
/@ ~-.\n\
|
75
|
-
/ __ .- | remember to have fun! \n // // @ \n\n"
|
52
|
+
post_install_message: ! " ____\n/@ ~-.\n/ __ .- | remember to have fun! \n //
|
53
|
+
// @ \n\n"
|
76
54
|
rdoc_options: []
|
77
|
-
|
78
|
-
require_paths:
|
55
|
+
require_paths:
|
79
56
|
- lib
|
80
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
58
|
none: false
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
|
87
|
-
- 0
|
88
|
-
version: "0"
|
89
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
64
|
none: false
|
91
|
-
requirements:
|
92
|
-
- -
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
hash: 23
|
95
|
-
segments:
|
96
|
-
- 1
|
97
|
-
- 3
|
98
|
-
- 6
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
99
68
|
version: 1.3.6
|
100
69
|
requirements: []
|
101
|
-
|
102
70
|
rubyforge_project:
|
103
|
-
rubygems_version: 1.
|
71
|
+
rubygems_version: 1.8.15
|
104
72
|
signing_key:
|
105
73
|
specification_version: 3
|
106
74
|
summary: WBEM client for Ruby based on ruby-sfcc and openwsman
|
107
75
|
test_files: []
|
108
|
-
|