cmpi-bindings 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/cmpi-bindings/cmpi_wrap.c +15317 -0
- data/ext/cmpi-bindings/extconf.rb +14 -0
- data/ext/cmpi-bindings/string_array.h +125 -0
- data/ext/src/cmpi_provider.c +1302 -0
- data/ext/src/target_ruby.c +462 -0
- data/lib/cmpi.rb +344 -0
- data/lib/cmpi/provider.rb +213 -0
- metadata +88 -0
data/lib/cmpi.rb
ADDED
@@ -0,0 +1,344 @@
|
|
1
|
+
#
|
2
|
+
# cmpi.rb
|
3
|
+
#
|
4
|
+
# Main entry point for cmpi-bindings-ruby, Ruby based CIM Providers
|
5
|
+
#
|
6
|
+
|
7
|
+
class String
|
8
|
+
#
|
9
|
+
# Convert from CamelCase to under_score
|
10
|
+
#
|
11
|
+
def decamelize
|
12
|
+
self.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
13
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
14
|
+
tr("-", "_").
|
15
|
+
downcase
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# = Cmpi - Common Manageablity Programming Interface
|
21
|
+
#
|
22
|
+
|
23
|
+
# The Common Manageablity Programming Interface (CMPI) defines a
|
24
|
+
# common standard of interfacing Manageability Instrumentation
|
25
|
+
# (providers, instrumentation) to Management Brokers (CIM Object
|
26
|
+
# Manager). The purpose of CMPI is to standardize Manageability
|
27
|
+
# Instrumentation. This allows to write and build instrumentation once
|
28
|
+
# and run it in different CIM environments (on one platform).
|
29
|
+
#
|
30
|
+
# == CIMOM Context
|
31
|
+
#
|
32
|
+
# == Provider Interface
|
33
|
+
#
|
34
|
+
|
35
|
+
module Cmpi
|
36
|
+
|
37
|
+
def self.null
|
38
|
+
0
|
39
|
+
end
|
40
|
+
def self.boolean
|
41
|
+
(2+0)
|
42
|
+
end
|
43
|
+
def self.char16
|
44
|
+
(2+1)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.real32
|
48
|
+
((2+0)<<2)
|
49
|
+
end
|
50
|
+
def self.real64
|
51
|
+
((2+1)<<2)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.uint8
|
55
|
+
((8+0)<<4)
|
56
|
+
end
|
57
|
+
def self.uint16
|
58
|
+
((8+1)<<4)
|
59
|
+
end
|
60
|
+
def self.uint32
|
61
|
+
((8+2)<<4)
|
62
|
+
end
|
63
|
+
def self.uint64
|
64
|
+
((8+3)<<4)
|
65
|
+
end
|
66
|
+
def self.sint8
|
67
|
+
((8+4)<<4)
|
68
|
+
end
|
69
|
+
def self.sint16
|
70
|
+
((8+5)<<4)
|
71
|
+
end
|
72
|
+
def self.sint32
|
73
|
+
((8+6)<<4)
|
74
|
+
end
|
75
|
+
def self.sint64
|
76
|
+
((8+7)<<4)
|
77
|
+
end
|
78
|
+
def self.instance
|
79
|
+
((16+0)<<8)
|
80
|
+
end
|
81
|
+
def self.ref
|
82
|
+
((16+1)<<8)
|
83
|
+
end
|
84
|
+
def self.args
|
85
|
+
((16+2)<<8)
|
86
|
+
end
|
87
|
+
def self.filter
|
88
|
+
((16+4)<<8)
|
89
|
+
end
|
90
|
+
def self.enumeration
|
91
|
+
((16+5)<<8)
|
92
|
+
end
|
93
|
+
def self.string
|
94
|
+
((16+6)<<8)
|
95
|
+
end
|
96
|
+
def self.chars
|
97
|
+
((16+7)<<8)
|
98
|
+
end
|
99
|
+
def self.dateTime
|
100
|
+
((16+8)<<8)
|
101
|
+
end
|
102
|
+
def self.ptr
|
103
|
+
((16+9)<<8)
|
104
|
+
end
|
105
|
+
def self.charsptr
|
106
|
+
((16+10)<<8)
|
107
|
+
end
|
108
|
+
|
109
|
+
unless defined? CMPI_ARRAY
|
110
|
+
CMPI_ARRAY = ((1)<<13)
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.booleanA
|
114
|
+
CMPI_ARRAY | self.boolean
|
115
|
+
end
|
116
|
+
def self.char16A
|
117
|
+
CMPI_ARRAY | self.char16
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.real32A
|
121
|
+
CMPI_ARRAY | self.real32
|
122
|
+
end
|
123
|
+
def self.real64A
|
124
|
+
CMPI_ARRAY | self.real64
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.uint8A
|
128
|
+
CMPI_ARRAY | self.uint8
|
129
|
+
end
|
130
|
+
def self.uint16A
|
131
|
+
CMPI_ARRAY | self.uint16
|
132
|
+
end
|
133
|
+
def self.uint32A
|
134
|
+
CMPI_ARRAY | self.uint32
|
135
|
+
end
|
136
|
+
def self.uint64A
|
137
|
+
CMPI_ARRAY | self.uint64
|
138
|
+
end
|
139
|
+
def self.sint8A
|
140
|
+
CMPI_ARRAY | self.sint8
|
141
|
+
end
|
142
|
+
def self.sint16A
|
143
|
+
CMPI_ARRAY | self.sint16
|
144
|
+
end
|
145
|
+
def self.sint32A
|
146
|
+
CMPI_ARRAY | self.sint32
|
147
|
+
end
|
148
|
+
def self.sint64A
|
149
|
+
CMPI_ARRAY | self.sint64
|
150
|
+
end
|
151
|
+
def self.instanceA
|
152
|
+
CMPI_ARRAY | self.instance
|
153
|
+
end
|
154
|
+
def self.refA
|
155
|
+
CMPI_ARRAY | self.ref
|
156
|
+
end
|
157
|
+
def self.argsA
|
158
|
+
CMPI_ARRAY | self.args
|
159
|
+
end
|
160
|
+
def self.filterA
|
161
|
+
CMPI_ARRAY | self.filter
|
162
|
+
end
|
163
|
+
def self.enumerationA
|
164
|
+
CMPI_ARRAY | self.enumeration
|
165
|
+
end
|
166
|
+
def self.stringA
|
167
|
+
CMPI_ARRAY | self.string
|
168
|
+
end
|
169
|
+
def self.charsA
|
170
|
+
CMPI_ARRAY | self.chars
|
171
|
+
end
|
172
|
+
def self.dateTimeA
|
173
|
+
CMPI_ARRAY | self.dateTime
|
174
|
+
end
|
175
|
+
def self.ptrA
|
176
|
+
CMPI_ARRAY | self.ptr
|
177
|
+
end
|
178
|
+
def self.charsptrA
|
179
|
+
CMPI_ARRAY | self.charsptrA
|
180
|
+
end
|
181
|
+
|
182
|
+
#
|
183
|
+
# Base class for ValueMap/Values classes from genprovider
|
184
|
+
#
|
185
|
+
class ValueMap
|
186
|
+
def self.method_missing name, *args
|
187
|
+
v = self.map[name.to_s]
|
188
|
+
return v if v
|
189
|
+
STDERR.puts "#{self.class}.#{name} ?"
|
190
|
+
nil
|
191
|
+
end
|
192
|
+
end
|
193
|
+
#
|
194
|
+
# CMPIContext gives the context for Provider operation
|
195
|
+
#
|
196
|
+
class CMPIContext
|
197
|
+
def count
|
198
|
+
#can't use alias here because CMPIContext::get_entry_count is only defined after
|
199
|
+
# initializing the provider (swig init code)
|
200
|
+
get_entry_count
|
201
|
+
end
|
202
|
+
def [] at
|
203
|
+
if at.kind_of? Integer
|
204
|
+
get_entry_at( at )
|
205
|
+
else
|
206
|
+
get_entry( at.to_s )
|
207
|
+
end
|
208
|
+
end
|
209
|
+
def each
|
210
|
+
0.upto(self.count-1) do |i|
|
211
|
+
yield get_entry_at(i)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
#
|
217
|
+
# CMPIInstance
|
218
|
+
#
|
219
|
+
class CMPIInstance
|
220
|
+
attr_accessor :typemap
|
221
|
+
def each
|
222
|
+
(0..size-1).each do |i|
|
223
|
+
yield self.get_property_at(i)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
def to_s
|
227
|
+
path = objectpath
|
228
|
+
keys = []
|
229
|
+
path.each { |val,name| keys << name }
|
230
|
+
s = ""
|
231
|
+
self.each do |value,name|
|
232
|
+
next unless value
|
233
|
+
next if keys.include? name
|
234
|
+
s << ", " unless s.empty?
|
235
|
+
s << "\"#{name}\"=>#{value.inspect}"
|
236
|
+
end
|
237
|
+
"#{path} #{s}"
|
238
|
+
end
|
239
|
+
#
|
240
|
+
# Allow Instance.Property and Instance.Property=
|
241
|
+
#
|
242
|
+
def method_missing name, *args
|
243
|
+
s = name.to_s
|
244
|
+
if s =~ /=$/
|
245
|
+
v = args[0]
|
246
|
+
n = s.chop
|
247
|
+
# -> http://blog.sidu.in/2008/02/loading-classes-from-strings-in-ruby.html
|
248
|
+
@typemap ||= Cmpi.const_get(self.objectpath.classname).typemap
|
249
|
+
t = @typemap[n] if @typemap
|
250
|
+
# STDERR.puts "Instance.#{n} = #{v}:#{t}"
|
251
|
+
self[n,v] = t
|
252
|
+
else
|
253
|
+
# STDERR.puts "CMPIInstance.#{name} -> #{self[s].inspect}"
|
254
|
+
self[s]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
#
|
260
|
+
# CMPIObjectPath
|
261
|
+
#
|
262
|
+
class CMPIObjectPath
|
263
|
+
attr_accessor :typemap
|
264
|
+
#
|
265
|
+
# Allow Ref.Property and Ref.Property=
|
266
|
+
#
|
267
|
+
def method_missing name, *args
|
268
|
+
s = name.to_s
|
269
|
+
if s =~ /=$/
|
270
|
+
v = args[0]
|
271
|
+
n = s.chop
|
272
|
+
# -> http://blog.sidu.in/2008/02/loading-classes-from-strings-in-ruby.html
|
273
|
+
@typemap ||= Cmpi.const_get(classname).typemap rescue nil
|
274
|
+
t = @typemap[n] if @typemap
|
275
|
+
# STDERR.puts "ObjectPath.#{n} = #{v}:#{t}"
|
276
|
+
self[n,v] = t
|
277
|
+
else
|
278
|
+
# STDERR.puts "CMPIObjectPath.#{name} -> #{self[s].inspect}"
|
279
|
+
self[s]
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
#
|
285
|
+
# CMPIEnumeration
|
286
|
+
#
|
287
|
+
class CMPIEnumeration
|
288
|
+
def each
|
289
|
+
while has_next
|
290
|
+
yield next_element
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
#
|
296
|
+
# CMPIData
|
297
|
+
#
|
298
|
+
class CMPIData
|
299
|
+
def method_missing name, *args
|
300
|
+
# STDERR.puts "CMPIData.%s? %0x" % [name, type]
|
301
|
+
case type
|
302
|
+
when Cmpi.instance
|
303
|
+
value.inst.send(name,*args)
|
304
|
+
when Cmpi.ref
|
305
|
+
value.ref.send(name,*args)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
#
|
311
|
+
# CMPIStatus
|
312
|
+
#
|
313
|
+
class CMPIStatus
|
314
|
+
def to_s
|
315
|
+
(rc == 0) ? "Ok" : "#{rc}:#{msg}"
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
#
|
320
|
+
# CMPIArgs
|
321
|
+
#
|
322
|
+
class CMPIArgs
|
323
|
+
def each
|
324
|
+
0.upto(size-1) do |i|
|
325
|
+
yield get_arg_at(i)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
def to_hash
|
329
|
+
h = {}
|
330
|
+
each do |name,val|
|
331
|
+
h[name] = val
|
332
|
+
end
|
333
|
+
h
|
334
|
+
end
|
335
|
+
def to_s
|
336
|
+
s = ""
|
337
|
+
each do |name,val|
|
338
|
+
s << ", " unless s.empty?
|
339
|
+
s << "#{name.inspect} => #{val}"
|
340
|
+
end
|
341
|
+
"{ #{s} }"
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
#
|
2
|
+
# provider.rb
|
3
|
+
#
|
4
|
+
# Provider API for cmpi-bindings-ruby, Ruby based CIM Providers
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'cmpi'
|
8
|
+
|
9
|
+
module Cmpi
|
10
|
+
|
11
|
+
#
|
12
|
+
# Accessor for broker value passed at provider initialization
|
13
|
+
# Required internally for callbacks like CMNewString
|
14
|
+
#
|
15
|
+
private
|
16
|
+
def self.broker= broker
|
17
|
+
@@broker = broker
|
18
|
+
end
|
19
|
+
public
|
20
|
+
def self.broker
|
21
|
+
@@broker
|
22
|
+
end
|
23
|
+
def not_implemented klass, name
|
24
|
+
STDERR.puts "#{klass}.#{name}: not implemented"
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# = Generic Provider interface
|
30
|
+
#
|
31
|
+
# Defines the interface common to all specific providers
|
32
|
+
# * InstanceProvider
|
33
|
+
# * MethodProvider
|
34
|
+
# * AssociationProvider
|
35
|
+
# * IndicationProvider
|
36
|
+
#
|
37
|
+
# define MI provider interfaces as modules
|
38
|
+
# so they can be used as mixins
|
39
|
+
#
|
40
|
+
# Typing information about interface function parameters
|
41
|
+
#
|
42
|
+
# context : CMPIContext
|
43
|
+
# result : CMPIResult
|
44
|
+
# reference : CMPIObjectPath
|
45
|
+
# properties : Array of String
|
46
|
+
#
|
47
|
+
module ProviderIF
|
48
|
+
protected
|
49
|
+
#
|
50
|
+
# call-seq:
|
51
|
+
# ProviderIF.new broker
|
52
|
+
#
|
53
|
+
def initialize broker
|
54
|
+
Cmpi::broker = broker
|
55
|
+
end
|
56
|
+
#
|
57
|
+
# Cleanup provider, +terminating+: boolean
|
58
|
+
#
|
59
|
+
def cleanup context, terminating
|
60
|
+
end
|
61
|
+
def self.method_missing method, *args
|
62
|
+
not_implemented self.class, self.method
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# = Instance provider interface
|
68
|
+
#
|
69
|
+
# Defines the CMPI interface for Instance providers
|
70
|
+
#
|
71
|
+
# newinst : CMPIInstance
|
72
|
+
#
|
73
|
+
module InstanceProviderIF
|
74
|
+
protected
|
75
|
+
def create_instance context, result, reference, newinst
|
76
|
+
end
|
77
|
+
def enum_instance_names context, result, reference
|
78
|
+
end
|
79
|
+
def enum_instances context, result, reference, properties
|
80
|
+
end
|
81
|
+
def get_instance context, result, reference, properties
|
82
|
+
end
|
83
|
+
def set_instance context, result, reference, newinst, properties
|
84
|
+
end
|
85
|
+
def delete_instance context, result, reference
|
86
|
+
end
|
87
|
+
# query : String
|
88
|
+
# lang : String
|
89
|
+
def exec_query context, result, reference, query, lang
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# = Method provider interface
|
95
|
+
#
|
96
|
+
# Defines the CMPI interface for Method providers
|
97
|
+
#
|
98
|
+
#
|
99
|
+
module MethodProviderIF
|
100
|
+
protected
|
101
|
+
# method : String
|
102
|
+
# inargs : CMPIArgs
|
103
|
+
# outargs : CMPIArgs
|
104
|
+
def invoke_method context, result, reference, method, inargs, outargs
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# = Association provider interface
|
110
|
+
#
|
111
|
+
# Defines the CMPI interface for Association providers
|
112
|
+
#
|
113
|
+
#
|
114
|
+
# Typing information about interface function parameters
|
115
|
+
#
|
116
|
+
# assoc_class : String
|
117
|
+
# result_class : String
|
118
|
+
# role : String
|
119
|
+
# result_role : String
|
120
|
+
#
|
121
|
+
module AssociationProviderIF
|
122
|
+
protected
|
123
|
+
def associator_names context, result, reference, assoc_class, result_class, role, result_role
|
124
|
+
end
|
125
|
+
def associators context, result, reference, assoc_class, result_class, role, result_role, properties
|
126
|
+
end
|
127
|
+
def reference_names context, result, reference, result_class, role
|
128
|
+
end
|
129
|
+
def references context, result, reference, result_class, role, properties
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# = Indication provider interface
|
135
|
+
#
|
136
|
+
# Defines the CMPI interface for Indication providers
|
137
|
+
#
|
138
|
+
# Typing information about interface function parameters
|
139
|
+
#
|
140
|
+
# filter : CMPISelectExp
|
141
|
+
# class_name : String
|
142
|
+
# owner : String
|
143
|
+
# first_activation : Bool
|
144
|
+
# last_activation : Bool
|
145
|
+
#
|
146
|
+
module IndicationProviderIF
|
147
|
+
protected
|
148
|
+
def authorize_filter context, filter, class_name, reference, owner
|
149
|
+
end
|
150
|
+
def activate_filter context, filter, class_name, reference, first_activation
|
151
|
+
end
|
152
|
+
def deactivate_filter context, filter, class_name, reference, last_activation
|
153
|
+
end
|
154
|
+
def must_poll context, filter, class_name, reference
|
155
|
+
end
|
156
|
+
def enable_indications context
|
157
|
+
end
|
158
|
+
def disable_indications context
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
#
|
163
|
+
# = Instance Provider
|
164
|
+
#
|
165
|
+
# *Abstract* class
|
166
|
+
#
|
167
|
+
# == Synopsis
|
168
|
+
# class MyProvider < Cmpi::InstanceProvider
|
169
|
+
# end
|
170
|
+
#
|
171
|
+
# Handling instances of CIM classes
|
172
|
+
#
|
173
|
+
class InstanceProvider
|
174
|
+
include ProviderIF
|
175
|
+
include InstanceProviderIF
|
176
|
+
end
|
177
|
+
#
|
178
|
+
# = Method Provider
|
179
|
+
#
|
180
|
+
# *Abstract* class
|
181
|
+
#
|
182
|
+
# Implementing methods for classes and instances
|
183
|
+
#
|
184
|
+
#
|
185
|
+
#
|
186
|
+
class MethodProvider
|
187
|
+
include ProviderIF
|
188
|
+
include MethodProviderIF
|
189
|
+
end
|
190
|
+
#
|
191
|
+
# = Association Provider
|
192
|
+
#
|
193
|
+
# *Abstract* class
|
194
|
+
#
|
195
|
+
# Providing (instances of) associations between instances
|
196
|
+
#
|
197
|
+
class AssociationProvider
|
198
|
+
include ProviderIF
|
199
|
+
include AssociationProviderIF
|
200
|
+
end
|
201
|
+
#
|
202
|
+
# = Indication Provider
|
203
|
+
#
|
204
|
+
# *Abstract* class
|
205
|
+
#
|
206
|
+
# Providing asynchronous events
|
207
|
+
#
|
208
|
+
class IndicationProvider
|
209
|
+
include ProviderIF
|
210
|
+
include IndicationProviderIF
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|