Module: WBEM
- Defined in:
- lib/wbem/cim_obj.rb,
lib/wbem/cim_xml.rb,
lib/wbem/cim_http.rb,
lib/wbem/cim_types.rb,
lib/wbem/tupletree.rb,
lib/wbem/tupleparse.rb,
lib/wbem/cim_constants.rb,
lib/wbem/cim_operations.rb
Overview
“”“CIM-XML/HTTP operations.
The WBEMConnection class opens a connection to a remote WBEM server. Across this you can run various CIM operations. Each method of this object corresponds fairly directly to a single CIM method call. “”“
Defined Under Namespace
Classes: AuthError, Boolean, CIM, CIMClass, CIMClassName, CIMClassPath, CIMElement, CIMError, CIMFloat, CIMHttpError, CIMInstance, CIMInstanceName, CIMInt, CIMLocalClassPath, CIMMethod, CIMNamespacePath, CIMObjectLocation, CIMParameter, CIMProperty, CIMQualifier, CIMType, CLASS, CLASSNAME, CLASSPATH, DECLARATION, DECLGROUP, DECLGROUP_WITHNAME, DECLGROUP_WITHPATH, ERROR, EXPMETHODCALL, EXPMETHODRESPONSE, EXPPARAMVALUE, HOST, IMETHODCALL, IMETHODRESPONSE, INSTANCE, INSTANCENAME, INSTANCEPATH, IPARAMVALUE, IRETURNVALUE, KEYBINDING, KEYVALUE, LOCALCLASSPATH, LOCALINSTANCEPATH, LOCALNAMESPACEPATH, MESSAGE, METHOD, METHODCALL, METHODRESPONSE, MULTIEXPREQ, MULTIEXPRSP, MULTIREQ, MULTIRSP, MethodHelper, NAMESPACE, NAMESPACEPATH, NocaseHash, OBJECTPATH, PARAMETER, PARAMETER_ARRAY, PARAMETER_REFARRAY, PARAMETER_REFERENCE, PARAMVALUE, PROPERTY, PROPERTY_ARRAY, PROPERTY_REFERENCE, ParseError, QUALIFIER, QUALIFIER_DECLARATION, RESPONSEDESTINATION, RETURNVALUE, Real32, Real64, SCOPE, SIMPLEEXPREQ, SIMPLEEXPRSP, SIMPLEREQ, SIMPLEREQACK, SIMPLERSP, Sint16, Sint32, Sint64, Sint8, TABLE, TABLECELL_DECLARATION, TABLECELL_REFERENCE, TABLEROW, TABLEROW_DECLARATION, TimeDelta, Uint16, Uint32, Uint64, Uint8, VALUE, VALUE_ARRAY, VALUE_NAMEDINSTANCE, VALUE_NAMEDOBJECT, VALUE_NULL, VALUE_OBJECT, VALUE_OBJECTWITHLOCALPATH, VALUE_OBJECTWITHPATH, VALUE_REFARRAY, VALUE_REFERENCE, WBEMConnection, XMLObject
Constant Summary
collapse
- CIM_ERR_FAILED =
CIMError error code constants
1
- CIM_ERR_ACCESS_DENIED =
2
- CIM_ERR_INVALID_NAMESPACE =
3
- CIM_ERR_INVALID_PARAMETER =
The target namespace does not exist
4
- CIM_ERR_INVALID_CLASS =
Parameter value(s) invalid
5
- CIM_ERR_NOT_FOUND =
The specified Class does not exist
6
- CIM_ERR_NOT_SUPPORTED =
Requested object could not be found
7
- CIM_ERR_CLASS_HAS_CHILDREN =
8
- CIM_ERR_CLASS_HAS_INSTANCES =
9
- CIM_ERR_INVALID_SUPERCLASS =
10
- CIM_ERR_ALREADY_EXISTS =
Superclass does not exist
11
- CIM_ERR_NO_SUCH_PROPERTY =
12
- CIM_ERR_TYPE_MISMATCH =
13
- CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED =
Value incompatible with type
14
- CIM_ERR_INVALID_QUERY =
Query language not supported
15
- CIM_ERR_METHOD_NOT_AVAILABLE =
16
- CIM_ERR_METHOD_NOT_FOUND =
Extrinsic method not executed
17
- PROVIDERTYPE_CLASS =
1
- PROVIDERTYPE_INSTANCE =
2
- PROVIDERTYPE_ASSOCIATION =
3
- PROVIDERTYPE_INDICATION =
4
- PROVIDERTYPE_METHOD =
5
- PROVIDERTYPE_CONSUMER =
6
- PROVIDERTYPE_QUERY =
7
- DEFAULT_NAMESPACE =
'root/cimv2'
Class Method Summary
collapse
-
._check_classname(val) ⇒ Object
helper functions for validating arguments.
-
.atomic_to_cim_xml(obj) ⇒ Object
-
.attrs(tt) ⇒ Object
-
.byname(nlist) ⇒ Object
-
.check_node(tt, nodename, required_attrs = [], optional_attrs = [], allowed_children = nil, allow_pcdata = false) ⇒ Object
-
.cimtype(obj) ⇒ Object
-
.dom_to_tupletree(node) ⇒ Object
-
.filter_tuples(l) ⇒ Object
-
.get_object_header(obj) ⇒ Object
-
.kids(tt) ⇒ Object
-
.list_of_matching(tt, matched) ⇒ Object
-
.list_of_same(tt, acceptable) ⇒ Object
-
.list_of_various(tt, acceptable) ⇒ Object
-
.name(tt) ⇒ Object
-
.notimplemented(tt) ⇒ Object
-
.one_child(tt, acceptable) ⇒ Object
-
.optional_child(tt, allowed) ⇒ Object
-
.parse_any(tt) ⇒ Object
-
.parse_cim(tt) ⇒ Object
-
.parse_class(tt) ⇒ Object
Object definition elements.
-
.parse_classname(tt) ⇒ Object
-
.parse_classpath(tt) ⇒ Object
-
.parse_error(tt) ⇒ Object
-
.parse_expmethodcall(tt) ⇒ Object
-
.parse_expmethodresponse(tt) ⇒ Object
-
.parse_expparamvalue(tt) ⇒ Object
-
.parse_host(tt) ⇒ Object
-
.parse_imethodcall(tt) ⇒ Object
-
.parse_imethodresponse(tt) ⇒ Object
-
.parse_instance(tt) ⇒ Object
-
.parse_instancename(tt) ⇒ Object
-
.parse_instancepath(tt) ⇒ Object
-
.parse_iparamvalue(tt) ⇒ Object
-
.parse_ireturnvalue(tt) ⇒ Object
-
.parse_keybinding(tt) ⇒ Object
-
.parse_keyvalue(tt) ⇒ Object
-
.parse_localclasspath(tt) ⇒ Object
-
.parse_localinstancepath(tt) ⇒ Object
-
.parse_localnamespacepath(tt) ⇒ Object
-
.parse_message(tt) ⇒ Object
-
.parse_method(tt) ⇒ Object
-
.parse_methodcall(tt) ⇒ Object
-
.parse_methodresponse(tt) ⇒ Object
-
.parse_multiexpreq(tt) ⇒ Object
-
.parse_multiexprsp(tt) ⇒ Object
-
.parse_multireq(tt) ⇒ Object
-
.parse_multirsp(tt) ⇒ Object
-
.parse_namespace(tt) ⇒ Object
-
.parse_namespacepath(tt) ⇒ Object
Object naming and locating elements.
-
.parse_objectpath(tt) ⇒ Object
-
.parse_parameter(tt) ⇒ Object
-
.parse_parameter_array(tt) ⇒ Object
-
.parse_parameter_refarray(tt) ⇒ Object
-
.parse_parameter_reference(tt) ⇒ Object
-
.parse_paramvalue(tt) ⇒ Object
-
.parse_property(tt) ⇒ Object
-
.parse_property_array(tt) ⇒ Object
-
.parse_property_reference(tt) ⇒ Object
-
.parse_qualifier(tt) ⇒ Object
-
.parse_returnvalue(tt) ⇒ Object
-
.parse_simpleexpreq(tt) ⇒ Object
-
.parse_simpleexprsp(tt) ⇒ Object
-
.parse_simplereq(tt) ⇒ Object
-
.parse_simplersp(tt) ⇒ Object
-
.parse_url(url) ⇒ Object
-
.parse_value(tt) ⇒ Object
-
.parse_value_array(tt) ⇒ Object
-
.parse_value_namedinstance(tt) ⇒ Object
-
.parse_value_namedobject(tt) ⇒ Object
-
.parse_value_object(tt) ⇒ Object
-
.parse_value_objectwithlocalpath(tt) ⇒ Object
-
.parse_value_objectwithpath(tt) ⇒ Object
-
.parse_value_refarray(tt) ⇒ Object
-
.parse_value_reference(tt) ⇒ Object
-
.pcdata(tt) ⇒ Object
-
.tocimobj(_type, value) ⇒ Object
-
.tocimxml(value, wrap_references = false) ⇒ Object
-
.tupletree_to_s(tt) ⇒ Object
-
.unpack_boolean(p) ⇒ Object
-
.unpack_value(tt) ⇒ Object
-
.valid_cimtype?(obj) ⇒ Boolean
-
.wbem_request(url, data, creds, headers = [], debug = 0, x509 = nil) ⇒ Object
-
.xml_to_tupletree(xml_string) ⇒ Object
Instance Method Summary
collapse
Class Method Details
._check_classname(val) ⇒ Object
helper functions for validating arguments
38
39
40
41
42
|
# File 'lib/wbem/cim_operations.rb', line 38
def WBEM._check_classname(val)
unless val.is_a?(String)
raise TypeError, "string expected for classname, not #{val}"
end
end
|
.atomic_to_cim_xml(obj) ⇒ Object
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/wbem/cim_types.rb', line 173
def WBEM.atomic_to_cim_xml(obj)
if (obj == true or (obj.is_a?(Boolean) and obj.value==true))
return "TRUE"
elsif (obj == false or (obj.is_a?(Boolean) and obj.value==false))
return "FALSE"
elsif (obj.is_a?(DateTime))
return sprintf("%d%02d%02d%02d%02d%02d.%06d+000",
obj.year, obj.month, obj.day, obj.hour,
obj.min, obj.sec, obj.sec_fraction.to_f)
elsif (obj.is_a?(TimeDelta))
return sprintf("%08d%02d%02d%02d.%06d:000",
obj.days, obj.hours, obj.minutes, obj.seconds, obj.microseconds)
elsif (obj.methods.include?("tocimxml"))
return obj.tocimxml
elsif obj.nil?
return obj
else
return obj.to_s
end
end
|
.attrs(tt) ⇒ Object
108
109
110
|
# File 'lib/wbem/tupleparse.rb', line 108
def WBEM.attrs(tt)
tt[1]
end
|
.byname(nlist) ⇒ Object
1131
1132
1133
1134
1135
1136
|
# File 'lib/wbem/cim_obj.rb', line 1131
def WBEM.byname(nlist)
hash = Hash.new
nlist.each { |x| hash[x.name] = x }
return hash
end
|
.check_node(tt, nodename, required_attrs = [], optional_attrs = [], allowed_children = nil, allow_pcdata = false) ⇒ Object
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
|
# File 'lib/wbem/tupleparse.rb', line 116
def WBEM.check_node(tt, nodename, required_attrs = [], optional_attrs = [],
allowed_children = nil,
allow_pcdata = false)
unless WBEM.name(tt) == nodename
raise ParseError, "expected node type #{nodename}, not #{WBEM.name(tt)} \n #{tt}"
end
tt_attrs = {}
tt_attrs = WBEM.attrs(tt).clone unless WBEM.attrs(tt).nil?
required_attrs.each do |attr|
unless tt_attrs.has_key?(attr)
raise ParseError, "expected #{attr} attribute on #{WBEM.name(tt)} node, but only have #{WBEM.attrs(tt).keys()}"
end
tt_attrs.delete(attr)
end
optional_attrs.each { |attr| tt_attrs.delete(attr) }
unless tt_attrs.empty?
raise ParseError, "invalid extra attributes #{tt_attrs.keys()}"
end
unless allowed_children.nil?
WBEM.kids(tt).each do |c|
unless allowed_children.include?(WBEM.name(c))
raise ParseError, "unexpected node #{WBEM.name(c)} under #{WBEM.name(tt)}; wanted #{allowed_children}"
end
end
end
unless allow_pcdata
tt[2].each do |c|
if (c.is_a? String and c.delete(" \t\n").length > 0)
raise ParseError, "unexpected non-blank pcdata node #{c} under #{WBEM.name(tt)}"
end
end
end
end
|
.cimtype(obj) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/wbem/cim_types.rb', line 142
def WBEM.cimtype(obj)
if (obj.is_a?(CIMType))
return obj.cimtype
elsif (obj == true or obj == false)
return 'boolean'
elsif (obj.is_a?(String))
return 'string'
elsif (obj.is_a?(CIMClassName) || obj.is_a?(CIMLocalClassPath) || obj.is_a?(CIMInstanceName))
return 'reference'
elsif (obj.is_a?(DateTime) or obj.is_a?(TimeDelta))
return 'datetime'
elsif (obj.is_a?(Array))
return WBEM.cimtype(obj[0])
else
raise TypeError, "Invalid CIM type for #{obj} (#{obj.class})"
end
end
|
.dom_to_tupletree(node) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
|
# File 'lib/wbem/tupletree.rb', line 70
def WBEM.dom_to_tupletree(node)
if node.node_type == :document
return dom_to_tupletree(node.elements[1])
end
unless node.node_type == :element
raise TypeError, "node must be an element"
end
name = node.name
attrs = {}
contents = []
node.elements.each do |child|
if child.node_type == :element
contents << dom_to_tupletree(child)
elsif child.node_type == :text
unless child.value.kind_of?(String)
raise TypeError, "text node #{child} must be a string"
end
contents << child.value
else
raise RuntimeError, "can't handle #{child}"
end
end
node.texts.each do |child|
if child.node_type == :text
unless child.value.kind_of?(String)
raise TypeError, "text node #{child} must be a string"
end
contents << child.value
else
raise RuntimeError, "can't handle #{child}"
end
end
node.attributes.each { |nodename, nodevalue| attrs[nodename] = nodevalue }
return [name, attrs, contents]
end
|
.filter_tuples(l) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/wbem/tupleparse.rb', line 80
def WBEM.filter_tuples(l)
if l.nil?
[]
else
l.find_all { |x| x.is_a? Array }
end
end
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/wbem/cim_http.rb', line 114
def WBEM.(obj)
if obj.kind_of?(String)
return "CIMObject: #{obj}"
end
if obj.kind_of?(CIMLocalClassPath)
return "CIMObject: #{obj.localnamespacepath}:#{obj.classname}"
end
if obj.kind_of?(CIMInstanceName) && !obj.namespace.nil?
return 'CIMObject: %s' % obj
end
raise CIMHttpError, "Don\'t know how to generate HTTP headers for #{obj}"
end
|
.kids(tt) ⇒ Object
112
113
114
|
# File 'lib/wbem/tupleparse.rb', line 112
def WBEM.kids(tt)
WBEM.filter_tuples(tt[2])
end
|
.list_of_matching(tt, matched) ⇒ Object
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/wbem/tupleparse.rb', line 222
def WBEM.list_of_matching(tt, matched)
r = []
WBEM.kids(tt).each do |child|
r << WBEM.parse_any(child) if matched.include?(WBEM.name(child))
end
return r
end
|
.list_of_same(tt, acceptable) ⇒ Object
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
# File 'lib/wbem/tupleparse.rb', line 235
def WBEM.list_of_same(tt, acceptable)
unless (k = WBEM.kids(tt))
return []
end
w = WBEM.name(k[0])
unless acceptable.include?(w)
raise ParseError, "expected one of #{acceptable} under #{WBEM.name(tt)}, got #{WBEM.name(child)}"
end
r = []
k.each do |child|
unless WBEM.name(child) == w
raise ParseError, "expected list of #{w} under #{WBEM.name(child)}, but found #{WBEM.name(tt)}"
end
r << WBEM.parse_any(child)
end
return r
end
|
.list_of_various(tt, acceptable) ⇒ Object
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'lib/wbem/tupleparse.rb', line 205
def WBEM.list_of_various(tt, acceptable)
r = []
WBEM.kids(tt).each do |child|
unless acceptable.include?(WBEM.name(child))
raise ParseError, "expected one of #{acceptable} under #{WBEM.name(tt)}, got #{WBEM.name(child)}"
end
r << WBEM.parse_any(child)
end
return r
end
|
.name(tt) ⇒ Object
104
105
106
|
# File 'lib/wbem/tupleparse.rb', line 104
def WBEM.name(tt)
tt[0]
end
|
.notimplemented(tt) ⇒ Object
260
261
262
|
# File 'lib/wbem/tupleparse.rb', line 260
def WBEM.notimplemented(tt)
raise ParseError, "parser for #{WBEM.name(tt)} not implemented"
end
|
.one_child(tt, acceptable) ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/wbem/tupleparse.rb', line 171
def WBEM.one_child(tt, acceptable)
k = WBEM.kids(tt)
unless k.length == 1
raise ParseError, "expecting just one #{acceptable}, got #{k.each {|t| t[0] }}"
end
child = k[0]
unless acceptable.include?(WBEM.name(child))
raise ParseError, "expecting one of #{acceptable}, got #{WBEM.name(child)} under #{WBEM.name(tt)}"
end
return WBEM.parse_any(child)
end
|
.optional_child(tt, allowed) ⇒ Object
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/wbem/tupleparse.rb', line 191
def WBEM.optional_child(tt, allowed)
k = WBEM.kids(tt)
if k.length > 1
raise ParseError, "expecting zero or one of #{allowed} under #{tt}"
elsif k.length == 1
return WBEM.one_child(tt, allowed)
else
return nil
end
end
|
.parse_any(tt) ⇒ Object
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
|
# File 'lib/wbem/tupleparse.rb', line 1122
def WBEM.parse_any(tt)
h = MethodHelper.new
nodename = WBEM.name(tt).downcase().tr(".", "_")
fn_name = "parse_" + nodename
method = self.method(fn_name)
unless method
raise ParseError, "no parser #{fn_name} for node type #{WBEM.name(tt)}"
end
return method.call(tt)
end
|
.parse_cim(tt) ⇒ Object
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
# File 'lib/wbem/tupleparse.rb', line 267
def WBEM.parse_cim(tt)
WBEM.check_node(tt, "CIM", ["CIMVERSION", "DTDVERSION"])
unless WBEM.attrs(tt)["CIMVERSION"] == "2.0"
raise ParseError, "CIMVERSION is #{WBEM.attrs(tt)[CIMVERSION]}, expected 2.0"
end
child = WBEM.one_child(tt, ["MESSAGE", "DECLARATION"])
return [WBEM.name(tt), WBEM.attrs(tt), child]
end
|
.parse_class(tt) ⇒ Object
Object definition elements
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
|
# File 'lib/wbem/tupleparse.rb', line 619
def WBEM.parse_class(tt)
WBEM.check_node(tt, "CLASS", ["NAME"], ["SUPERCLASS"],
["QUALIFIER", "PROPERTY", "PROPERTY.REFERENCE",
"PROPERTY.ARRAY", "METHOD"])
obj = CIMClass.new(WBEM.attrs(tt)["NAME"])
obj.superclass = WBEM.attrs(tt)["SUPERCLASS"]
obj.properties = WBEM.byname(WBEM.list_of_matching(tt, ["PROPERTY", "PROPERTY.REFERENCE",
"PROPERTY.ARRAY"]))
obj.qualifiers = WBEM.byname(WBEM.list_of_matching(tt, ["QUALIFIER"]))
obj.cim_methods = list_of_matching(tt, ["METHOD"])
return obj
end
|
.parse_classname(tt) ⇒ Object
496
497
498
499
500
501
502
503
504
|
# File 'lib/wbem/tupleparse.rb', line 496
def WBEM.parse_classname(tt)
WBEM.check_node(tt, "CLASSNAME", ["NAME"], [], [])
return CIMClassName.new(WBEM.attrs(tt)["NAME"])
end
|
.parse_classpath(tt) ⇒ Object
469
470
471
472
473
474
475
476
477
478
479
480
481
|
# File 'lib/wbem/tupleparse.rb', line 469
def WBEM.parse_classpath(tt)
WBEM.check_node(tt, "CLASSPATH")
unless ((k = WBEM.kids(tt)).length == 2)
raise ParseError, "Expecting (NAMESPACEPATH, CLASSNAME) got #{k.keys()}"
end
nspath = WBEM.parse_namespacepath(k[0])
classname = WBEM.parse_classname(k[1])
return CIMClassPath.new(nspath.host, nspath.localnamespacepath,
classname.classname)
end
|
.parse_error(tt) ⇒ Object
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
|
# File 'lib/wbem/tupleparse.rb', line 1063
def WBEM.parse_error(tt)
WBEM.check_node(tt, "ERROR", ["CODE"], ["DESCRIPTION"])
return [WBEM.name(tt), WBEM.attrs(tt), nil]
end
|
.parse_expmethodcall(tt) ⇒ Object
970
971
972
|
# File 'lib/wbem/tupleparse.rb', line 970
def WBEM.parse_expmethodcall(tt)
raise ParseError, "EXPMETHODCALL parser not implemented"
end
|
.parse_expmethodresponse(tt) ⇒ Object
1052
1053
1054
|
# File 'lib/wbem/tupleparse.rb', line 1052
def WBEM.parse_expmethodresponse(tt)
raise ParseError, "EXPMETHODRESPONSE parser not implemented"
end
|
.parse_expparamvalue(tt) ⇒ Object
1018
1019
1020
|
# File 'lib/wbem/tupleparse.rb', line 1018
def WBEM.parse_expparamvalue(tt)
raise ParseError, "EXPPARAMVALUE parser not implemented"
end
|
.parse_host(tt) ⇒ Object
450
451
452
453
454
455
456
|
# File 'lib/wbem/tupleparse.rb', line 450
def WBEM.parse_host(tt)
WBEM.check_node(tt, "HOST", [], [], nil , true)
return WBEM.pcdata(tt)
end
|
.parse_imethodcall(tt) ⇒ Object
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
|
# File 'lib/wbem/tupleparse.rb', line 950
def WBEM.parse_imethodcall(tt)
WBEM.check_node(tt, "IMETHODCALL", ["NAME"])
if ((k = WBEM.kids(tt)).length < 1)
raise ParseError, "Expecting LOCALNAMESPACEPATH, got nothing"
end
localnspath = WBEM.parse_localnamespacepath(k[0])
params = k[1..-1].collect { |x| WBEM.parse_iparamvalue(x) }
return [WBEM.name(tt), WBEM.attrs(tt), localnspath, params]
end
|
.parse_imethodresponse(tt) ⇒ Object
1056
1057
1058
1059
1060
1061
|
# File 'lib/wbem/tupleparse.rb', line 1056
def WBEM.parse_imethodresponse(tt)
WBEM.check_node(tt, "IMETHODRESPONSE", ["NAME"], [])
return [WBEM.name(tt), WBEM.attrs(tt), WBEM.optional_child(tt, ["ERROR", "IRETURNVALUE"])]
end
|
.parse_instance(tt) ⇒ Object
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
|
# File 'lib/wbem/tupleparse.rb', line 643
def WBEM.parse_instance(tt)
WBEM.check_node(tt, "INSTANCE", ["CLASSNAME"],
["QUALIFIER", "PROPERTY", "PROPERTY.ARRAY",
"PROPERTY.REFERENCE"])
qualifiers = {}
props = WBEM.list_of_matching(tt, ["PROPERTY.REFERENCE", "PROPERTY", "PROPERTY.ARRAY"])
obj = CIMInstance.new(WBEM.attrs(tt)["CLASSNAME"])
obj.qualifiers = qualifiers
props.each { |p| obj[p.name] = p }
return obj
end
|
.parse_instancename(tt) ⇒ Object
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
|
# File 'lib/wbem/tupleparse.rb', line 540
def WBEM.parse_instancename(tt)
WBEM.check_node(tt, "INSTANCENAME", ["CLASSNAME"])
if ((k = WBEM.kids(tt)).length == 0)
return CIMInstanceName.new(WBEM.attrs(tt)["CLASSNAME"], {})
end
classname = WBEM.attrs(tt)["CLASSNAME"]
w = WBEM.name(k[0])
if w == "KEYVALUE" or w == "VALUE.REFERENCE"
unless ((k = WBEM.kids(tt)).length == 1)
raise ParseError, "expected only one #{w} under #{WBEM.name(tt)}"
end
return CIMInstanceName(classname, {nil => WBEM.parse_any(k[0])})
elsif w == "KEYBINDING"
kbs = {}
WBEM.list_of_various(tt, ["KEYBINDING"]).each { |kb| kbs.update(kb)}
return CIMInstanceName.new(classname, kbs)
else
raise ParseError, "unexpected node #{w} under #{WBEM.name(tt)}"
end
end
|
.parse_instancepath(tt) ⇒ Object
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
# File 'lib/wbem/tupleparse.rb', line 506
def WBEM.parse_instancepath(tt)
WBEM.check_node(tt, "INSTANCEPATH")
unless ((k = WBEM.kids(tt)).length == 2)
raise ParseError, "Expecting (NAMESPACEPATH, INSTANCENAME) got #{k}"
end
nspath = WBEM.parse_namespacepath(k[0])
instancename = WBEM.parse_instancename(k[1])
instancename.host = nspath.host
instancename.namespace = nspath.localnamespacepath
return instancename
end
|
.parse_iparamvalue(tt) ⇒ Object
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
|
# File 'lib/wbem/tupleparse.rb', line 999
def WBEM.parse_iparamvalue(tt)
WBEM.check_node(tt, "IPARAMVALUE", ["NAME"], [])
child = WBEM.optional_child(tt,
["VALUE", "VALUE.ARRAY", "VALUE.REFERENCE",
"INSTANCENAME", "CLASSNAME",
"QUALIFIER.DECLARATION", "CLASS", "INSTANCE",
"VALUE.NAMEDINSTANCE"])
return [WBEM.attrs(tt)["NAME"], child ]
end
|
.parse_ireturnvalue(tt) ⇒ Object
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
|
# File 'lib/wbem/tupleparse.rb', line 1091
def WBEM.parse_ireturnvalue(tt)
WBEM.check_node(tt, "IRETURNVALUE", [], [])
values = WBEM.list_of_same(tt, ["CLASSNAME", "INSTANCENAME",
"VALUE", "VALUE.OBJECTWITHPATH", "VALUE.OBJECT",
"OBJECTPATH", "QUALIFIER.DECLARATION",
"VALUE.ARRAY", "VALUE.REFERENCE",
"CLASS", "INSTANCE",
"VALUE.NAMEDINSTANCE",])
return [WBEM.name(tt), WBEM.attrs(tt), values]
end
|
.parse_keybinding(tt) ⇒ Object
583
584
585
586
587
588
589
590
591
592
593
|
# File 'lib/wbem/tupleparse.rb', line 583
def WBEM.parse_keybinding(tt)
WBEM.check_node(tt, "KEYBINDING", ["NAME"])
child = WBEM.one_child(tt, ["KEYVALUE", "VALUE.REFERENCE"])
return {WBEM.attrs(tt)["NAME"] => child}
end
|
.parse_keyvalue(tt) ⇒ Object
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
|
# File 'lib/wbem/tupleparse.rb', line 595
def WBEM.parse_keyvalue(tt)
WBEM.check_node(tt, "KEYVALUE", [], ["VALUETYPE"], [], true)
vt = WBEM.attrs(tt).fetch("VALUETYPE", "string")
p = WBEM.pcdata(tt)
if vt == "string"
return p
elsif vt == "boolean"
return WBEM.unpack_boolean(p)
elsif vt == "numeric"
return p.strip().to_i
else
raise ParseError, "invalid VALUETYPE #{vt} in #{WBEM.name(tt)}"
end
end
|
.parse_localclasspath(tt) ⇒ Object
483
484
485
486
487
488
489
490
491
492
493
494
|
# File 'lib/wbem/tupleparse.rb', line 483
def WBEM.parse_localclasspath(tt)
WBEM.check_node(tt, "LOCALCLASSPATH")
unless ((k = WBEM.kids(tt)).length == 2)
raise ParseError, "Expecting (LOCALNAMESPACEPATH, CLASSNAME) got #{k.keys()}"
end
localnspath = WBEM.parse_localnamespacepath(k[0])
classname = WBEM.parse_classname(k[1])
return CIMLocalClassPath.new(localnspath, classname.classname)
end
|
.parse_localinstancepath(tt) ⇒ Object
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
|
# File 'lib/wbem/tupleparse.rb', line 524
def WBEM.parse_localinstancepath(tt)
WBEM.check_node(tt, "LOCALINSTANCEPATH")
unless ((k = WBEM.kids(tt)).length == 2)
raise ParseError, "Expecting (LOCALNAMESPACEPATH, INSTANCENAME) got #{k.keys()}"
end
localnspath = WBEM.parse_localnamespacepath(k[0])
instancename = WBEM.parse_instancename(k[1])
instancename.namespace = localnspath
return instancename
end
|
.parse_localnamespacepath(tt) ⇒ Object
439
440
441
442
443
444
445
446
447
448
|
# File 'lib/wbem/tupleparse.rb', line 439
def WBEM.parse_localnamespacepath(tt)
WBEM.check_node(tt, "LOCALNAMESPACEPATH", [], [], ["NAMESPACE"])
if WBEM.kids(tt).length == 0
raise ParseError, "Expecting one or more of NAMESPACE, got nothing"
end
WBEM.list_of_various(tt, ["NAMESPACE"]).join("/")
end
|
.parse_message(tt) ⇒ Object
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
|
# File 'lib/wbem/tupleparse.rb', line 911
def WBEM.parse_message(tt)
WBEM.check_node(tt, "MESSAGE", ["ID", "PROTOCOLVERSION"])
messages = WBEM.one_child(
tt, ["SIMPLEREQ", "MULTIREQ", "SIMPLERSP", "MULTIRSP"])
unless messages[0].is_a?(Array)
messages = [messages]
end
return [WBEM.name(tt), WBEM.attrs(tt), messages]
end
|
.parse_method(tt) ⇒ Object
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
|
# File 'lib/wbem/tupleparse.rb', line 799
def WBEM.parse_method(tt)
WBEM.check_node(tt, "METHOD", ["NAME"],
["TYPE", "CLASSORIGIN", "PROPAGATED"],
["QUALIFIER", "PARAMETER", "PARAMETER.REFERENCE",
"PARAMETER.ARRAY", "PARAMETER.REFARRAY"])
qualifiers = WBEM.byname(WBEM.list_of_matching(tt, ["QUALIFIER"]))
parameters = WBEM.byname(WBEM.list_of_matching(tt, ["PARAMETER",
"PARAMETER.REFERENCE",
"PARAMETER.ARRAY",
"PARAMETER.REFARRAY",]))
a = WBEM.attrs(tt)
return CIMMethod.new(a["NAME"],
a["TYPE"],
parameters,
a["CLASSORIGIN"],
unpack_boolean(a["PROPAGATED"]),
qualifiers)
end
|
.parse_methodcall(tt) ⇒ Object
966
967
968
|
# File 'lib/wbem/tupleparse.rb', line 966
def WBEM.parse_methodcall(tt)
raise ParseError, "METHODCALL parser not implemented"
end
|
.parse_methodresponse(tt) ⇒ Object
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
|
# File 'lib/wbem/tupleparse.rb', line 1041
def WBEM.parse_methodresponse(tt)
WBEM.check_node(tt, "METHODRESPONSE", ["NAME"], [])
return [WBEM.name(tt), WBEM.attrs(tt), WBEM.list_of_various(tt, ["ERROR", "RETURNVALUE",
"PARAMVALUE"])]
end
|
.parse_multiexpreq(tt) ⇒ Object
932
933
934
|
# File 'lib/wbem/tupleparse.rb', line 932
def WBEM.parse_multiexpreq(tt)
raise ParseError, "MULTIEXPREQ parser not implemented"
end
|
.parse_multiexprsp(tt) ⇒ Object
1026
1027
1028
|
# File 'lib/wbem/tupleparse.rb', line 1026
def WBEM.parse_multiexprsp(tt)
raise ParseError, "MULTIEXPRSP parser not implemented"
end
|
.parse_multireq(tt) ⇒ Object
928
929
930
|
# File 'lib/wbem/tupleparse.rb', line 928
def WBEM.parse_multireq(tt)
raise ParseError, "MULTIREQ parser not implemented"
end
|
.parse_multirsp(tt) ⇒ Object
1022
1023
1024
|
# File 'lib/wbem/tupleparse.rb', line 1022
def WBEM.parse_multirsp(tt)
raise ParseError, "MULTIRSP parser not implemented"
end
|
.parse_namespace(tt) ⇒ Object
458
459
460
461
462
463
464
465
466
467
|
# File 'lib/wbem/tupleparse.rb', line 458
def WBEM.parse_namespace(tt)
WBEM.check_node(tt, "NAMESPACE", ["NAME"], [], [])
return WBEM.attrs(tt)["NAME"]
end
|
.parse_namespacepath(tt) ⇒ Object
Object naming and locating elements
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
# File 'lib/wbem/tupleparse.rb', line 424
def WBEM.parse_namespacepath(tt)
WBEM.check_node(tt, "NAMESPACEPATH")
unless ((k = WBEM.kids(tt)).length == 2)
raise ParseError, "Expecting (HOST, LOCALNAMESPACEPATH) got #{WBEM.kids(tt).keys()}"
end
host = WBEM.parse_host(k[0])
localnspath = WBEM.parse_localnamespacepath(k[1])
return CIMNamespacePath.new(host, localnspath)
end
|
.parse_objectpath(tt) ⇒ Object
571
572
573
574
575
576
577
578
579
580
581
|
# File 'lib/wbem/tupleparse.rb', line 571
def WBEM.parse_objectpath(tt)
WBEM.check_node(tt, "OBJECTPATH")
child = WBEM.one_child(tt, ["INSTANCEPATH", "CLASSPATH"])
return [WBEM.name(tt), WBEM.attrs(tt), child]
end
|
.parse_parameter(tt) ⇒ Object
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
|
# File 'lib/wbem/tupleparse.rb', line 829
def WBEM.parse_parameter(tt)
WBEM.check_node(tt, "PARAMETER", ["NAME", "TYPE"], [])
quals = {}
list_of_matching(tt, ['QUALIFIER']).each {|q| quals[q.name] = q }
a = WBEM.attrs(tt)
return CIMParameter.new(a["NAME"], a["TYPE"], nil, nil, nil, quals)
end
|
.parse_parameter_array(tt) ⇒ Object
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
|
# File 'lib/wbem/tupleparse.rb', line 865
def WBEM.parse_parameter_array(tt)
WBEM.check_node(tt, "PARAMETER.ARRAY", ["NAME", "TYPE"], ["ARRAYSIZE"])
quals = {}
list_of_matching(tt, ['QUALIFIER']).each {|q| quals[q.name] = q }
a = WBEM.attrs(tt)
array_size = a["ARRAYSIZE"]
array_size = array_size.to_i unless array_size.nil?
return CIMParameter.new(a["NAME"], a["TYPE"], nil, true, array_size, quals)
end
|
.parse_parameter_refarray(tt) ⇒ Object
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
|
# File 'lib/wbem/tupleparse.rb', line 886
def WBEM.parse_parameter_refarray(tt)
WBEM.check_node(tt, "PARAMETER.REFARRAY", ["NAME"], ["REFERENCECLASS", "ARRAYSIZE"])
quals = {}
list_of_matching(tt, ['QUALIFIER']).each {|q| quals[q.name] = q }
a = WBEM.attrs(tt)
array_size = a["ARRAYSIZE"]
array_size = array_size.to_i unless array_size.nil?
return CIMParameter.new(a["NAME"], "reference", a["REFERENCECLASS"],
true, array_size, quals)
end
|
.parse_parameter_reference(tt) ⇒ Object
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
|
# File 'lib/wbem/tupleparse.rb', line 847
def WBEM.parse_parameter_reference(tt)
WBEM.check_node(tt, "PARAMETER.REFERENCE", ["NAME"], ["REFERENCECLASS"])
quals = {}
list_of_matching(tt, ['QUALIFIER']).each {|q| quals[q.name] = q }
a = WBEM.attrs(tt)
return CIMParameter.new(a["NAME"], "reference", a['REFERENCECLASS'], nil, nil, quals)
end
|
.parse_paramvalue(tt) ⇒ Object
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
|
# File 'lib/wbem/tupleparse.rb', line 974
def WBEM.parse_paramvalue(tt)
WBEM.check_node(tt, "PARAMVALUE", ["NAME"], ["PARAMTYPE"])
child = WBEM.optional_child(tt,
["VALUE", "VALUE.REFERENCE", "VALUE.ARRAY",
"VALUE.REFARRAY",])
if WBEM.attrs(tt).has_key?("PARAMTYPE")
paramtype = WBEM.attrs(tt)["PARAMTYPE"]
else
paramtype = nil
end
return [WBEM.attrs(tt)["NAME"], paramtype, child]
end
|
.parse_property(tt) ⇒ Object
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
|
# File 'lib/wbem/tupleparse.rb', line 705
def WBEM.parse_property(tt)
WBEM.check_node(tt, "PROPERTY", ["TYPE", "NAME"],
["NAME", "CLASSORIGIN", "PROPAGATED"],
["QUALIFIER", "VALUE"])
quals = {}
WBEM.list_of_matching(tt, ["QUALIFIER"]).each { |q| quals[q.name] = q }
val = WBEM.unpack_value(tt)
a = WBEM.attrs(tt)
return CIMProperty.new(a["NAME"], val, a["TYPE"],
a["CLASSORIGIN"],
WBEM.unpack_boolean(a["PROPAGATED"]),
nil,
quals)
end
|
.parse_property_array(tt) ⇒ Object
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
|
# File 'lib/wbem/tupleparse.rb', line 736
def WBEM.parse_property_array(tt)
WBEM.check_node(tt, "PROPERTY.ARRAY", ["NAME", "TYPE"],
["REFERENCECLASS", "CLASSORIGIN", "PROPAGATED",
"ARRAYSIZE"],
["QUALIFIER", "VALUE.ARRAY"])
qualifiers = WBEM.byname(WBEM.list_of_matching(tt, ["QUALIFIER"]))
values = WBEM.unpack_value(tt)
a = WBEM.attrs(tt)
return CIMProperty.new(a["NAME"], values, a["TYPE"],
a["CLASSORIGIN"],
nil, true, qualifiers)
end
|
.parse_property_reference(tt) ⇒ Object
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
|
# File 'lib/wbem/tupleparse.rb', line 760
def WBEM.parse_property_reference(tt)
WBEM.check_node(tt, "PROPERTY.REFERENCE", ["NAME"],
["REFERENCECLASS", "CLASSORIGIN", "PROPAGATED"])
value = WBEM.list_of_matching(tt, ["VALUE.REFERENCE"])
if value.nil? or value.length == 0
value = nil
elsif value.length == 1
value = value[0]
else
raise ParseError, "Too many VALUE.REFERENCE elements."
end
attributes = WBEM.attrs(tt)
pref = CIMProperty.new(attributes["NAME"], value, "reference")
WBEM.list_of_matching(tt, ["QUALIFIER"]).each { |q| pref.qualifiers[q.name] = q}
if attributes.has_key?("REFERENCECLASS")
pref.reference_class = attributes["REFERENCECLASS"]
end
if attributes.has_key?("CLASSORIGIN")
pref.class_origin = attributes["CLASSORIGIN"]
end
if attributes.has_key?("PROPAGATED")
pref.propagated = attributes["PROPAGATED"]
end
return pref
end
|
.parse_qualifier(tt) ⇒ Object
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
|
# File 'lib/wbem/tupleparse.rb', line 673
def WBEM.parse_qualifier(tt)
WBEM.check_node(tt, "QUALIFIER", ["NAME", "TYPE"],
["OVERRIDABLE", "TOSUBCLASS", "TOINSTANCE",
"TRANSLATABLE", "PROPAGATED"],
["VALUE", "VALUE.ARRAY"])
a = WBEM.attrs(tt)
q = CIMQualifier.new(a["NAME"], WBEM.unpack_value(tt))
["OVERRIDABLE", "TOSUBCLASS", "TOINSTANCE", "TRANSLATABLE", "PROPAGATED"].each do |i|
rv = a[i]
unless ["true", "false", nil].include?(rv)
raise ParseError, "invalid value #{rv} for #{i} on #{WBEM.name(tt)}"
end
if rv == "true"
rv = true
elsif rv == "false"
rv = false
end
q.method("#{i.downcase()}=").call(rv)
end
return q
end
|
.parse_returnvalue(tt) ⇒ Object
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
|
# File 'lib/wbem/tupleparse.rb', line 1076
def WBEM.parse_returnvalue(tt)
WBEM.check_node(tt, "RETURNVALUE", [], ["PARAMTYPE"])
return name[(tt), WBEM.attrs(tt), WBEM.one_child(tt, ["VALUE", "VALUE.ARRAY",
"VALUE.REFERENCE",
"VALUE.REFARRAY"])]
end
|
.parse_simpleexpreq(tt) ⇒ Object
946
947
948
|
# File 'lib/wbem/tupleparse.rb', line 946
def WBEM.parse_simpleexpreq(tt)
raise ParseError, "SIMPLEEXPREQ parser not implemented"
end
|
.parse_simpleexprsp(tt) ⇒ Object
1037
1038
1039
|
# File 'lib/wbem/tupleparse.rb', line 1037
def WBEM.parse_simpleexprsp(tt)
raise ParseError, "SIMPLEEXPRSP parser not implemented"
end
|
.parse_simplereq(tt) ⇒ Object
936
937
938
939
940
941
942
943
944
|
# File 'lib/wbem/tupleparse.rb', line 936
def WBEM.parse_simplereq(tt)
WBEM.check_node(tt, "SIMPLEREQ")
child = WBEM.one_child(tt, ["IMETHODCALL", "METHODCALL"])
return [WBEM.kids(tt)[0][0], child]
end
|
.parse_simplersp(tt) ⇒ Object
1030
1031
1032
1033
1034
1035
|
# File 'lib/wbem/tupleparse.rb', line 1030
def WBEM.parse_simplersp(tt)
WBEM.check_node(tt, "SIMPLERSP", [], [])
child = WBEM.one_child(tt, ["METHODRESPONSE", "IMETHODRESPONSE"])
return [WBEM.name(tt), WBEM.attrs(tt), child]
end
|
.parse_url(url) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/wbem/cim_http.rb', line 36
def WBEM.parse_url(url)
host = url.sub(%r{^https?://}, "")
port = 5988
ssl = false
if /^https/.match(url)
ssl = true
port = 5989
end
s = host.split("@")
if (s.length > 1 )
creds = s[0].split(":")
host = s[1]
end
s = host.split(":")
if (s.length > 1 )
host = s[0]
port = s[1].to_i
end
return host, port, ssl, creds
end
|
.parse_value(tt) ⇒ Object
288
289
290
291
292
293
|
# File 'lib/wbem/tupleparse.rb', line 288
def WBEM.parse_value(tt)
WBEM.check_node(tt, "VALUE", [], [], [], true)
return WBEM.pcdata(tt)
end
|
.parse_value_array(tt) ⇒ Object
295
296
297
298
299
300
|
# File 'lib/wbem/tupleparse.rb', line 295
def WBEM.parse_value_array(tt)
WBEM.check_node(tt, "VALUE.ARRAY", [], [], ["VALUE"])
return WBEM.list_of_same(tt, ["VALUE"])
end
|
.parse_value_namedinstance(tt) ⇒ Object
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
# File 'lib/wbem/tupleparse.rb', line 340
def WBEM.parse_value_namedinstance(tt)
WBEM.check_node(tt, "VALUE.NAMEDINSTANCE")
k = WBEM.kids(tt)
unless k.length == 2
raise ParseError, "expecting (INSTANCENAME, INSTANCE), got #{k}"
end
instancename = WBEM.parse_instancename(k[0])
instance = WBEM.parse_instance(k[1])
instance.path = instancename
return instance
end
|
.parse_value_namedobject(tt) ⇒ Object
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
# File 'lib/wbem/tupleparse.rb', line 356
def WBEM.parse_value_namedobject(tt)
WBEM.check_node(tt, "VALUE.NAMEDOBJECT")
k = WBEM.kids(tt)
if k.length == 1
object = WBEM.parse_class(k[0])
elsif k.length == 2
path = WBEM.parse_instancename(k[0])
object = WBEM.parse_instance(k[1])
object.path = path
else
raise ParseError, "Expecting one or two elements, got #{k}"
end
return [WBEM.name(tt), WBEM.attrs(tt), object]
end
|
.parse_value_object(tt) ⇒ Object
330
331
332
333
334
335
336
337
338
|
# File 'lib/wbem/tupleparse.rb', line 330
def WBEM.parse_value_object(tt)
WBEM.check_node(tt, "VALUE.OBJECT")
child = WBEM.one_child(tt, ["CLASS", "INSTANCE"])
return [WBEM.name(tt), WBEM.attrs(tt), child]
end
|
.parse_value_objectwithlocalpath(tt) ⇒ Object
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
# File 'lib/wbem/tupleparse.rb', line 375
def WBEM.parse_value_objectwithlocalpath(tt)
WBEM.check_node(tt, "VALUE.OBJECTWITHLOCALPATH")
k = WBEM.kids(tt)
unless k.length == 2
raise ParseError, "Expecting two elements, got #{k.length}"
end
if k[0][0] == "LOCALCLASSPATH"
object = [WBEM.parse_localclasspath(k[0]),
WBEM.parse_class(k[1])]
else
path = WBEM.parse_localinstancepath(k[0])
object = WBEM.parse_instance(k[1])
object.path = path
end
return [WBEM.name(tt), WBEM.attrs(tt), object]
end
|
.parse_value_objectwithpath(tt) ⇒ Object
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
# File 'lib/wbem/tupleparse.rb', line 397
def WBEM.parse_value_objectwithpath(tt)
WBEM.check_node(tt, "VALUE.OBJECTWITHPATH")
k = WBEM.kids(tt)
unless k.length == 2
raise ParseError, "Expecting two elements, got #{k.length}"
end
if WBEM.name(k[0]) == "CLASSPATH"
object = [WBEM.parse_classpath(k[0]),
WBEM.parse_class(k[1])]
else
path = WBEM.parse_instancepath(k[0])
object = WBEM.parse_instance(k[1])
object.path = path
end
return [WBEM.name(tt), WBEM.attrs(tt), object]
end
|
.parse_value_refarray(tt) ⇒ Object
320
321
322
323
324
325
326
327
328
|
# File 'lib/wbem/tupleparse.rb', line 320
def WBEM.parse_value_refarray(tt)
WBEM.check_node(tt, "VALUE.REFARRAY")
children = WBEM.list_of_various(tt, ["VALUE.REFERENCE"])
return [WBEM.name(tt), WBEM.attrs(tt), children]
end
|
.parse_value_reference(tt) ⇒ Object
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
# File 'lib/wbem/tupleparse.rb', line 302
def WBEM.parse_value_reference(tt)
WBEM.check_node(tt, "VALUE.REFERENCE", [])
child = WBEM.one_child(tt,
["CLASSPATH", "LOCALCLASSPATH", "CLASSNAME",
"INSTANCEPATH", "LOCALINSTANCEPATH",
"INSTANCENAME"])
return child
end
|
.pcdata(tt) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/wbem/tupleparse.rb', line 92
def WBEM.pcdata(tt)
tt[2].each do |x|
unless x.is_a? String
raise ParseError, "unexpected node #{x} under #{tt}"
end
end
tt[2].join
end
|
.tocimobj(_type, value) ⇒ Object
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
|
# File 'lib/wbem/cim_obj.rb', line 1066
def WBEM.tocimobj(_type, value)
if value.is_a?(Array)
return value.collect { |val| WBEM.tocimobj(_type, val) }
end
case _type
when "boolean"
return Boolean.new(value)
when "string"
return value
when "uint8"
return Uint8.new(value)
when "sint8"
return Sint8.new(value)
when "uint16"
return Uint16.new(value)
when "sint16"
return Sint16.new(value)
when "uint32"
return Uint32.new(value)
when "sint32"
return Sint32.new(value)
when "uint64"
return Uint64.new(value)
when "sint64"
return Sint64.new(value)
when "real32"
return Real32.new(value)
when "real64"
return Real64.new(value)
when "char16"
raise TypeError, "CIMType char16 not handled"
when "datetime"
if (value.nil?)
return nil
end
tv_pattern = /^(\d{8})(\d{2})(\d{2})(\d{2})\.(\d{6})(:)(\d{3})/
date_pattern = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\.(\d{6})([+|-])(\d{3})/
s = tv_pattern.match(value)
if (s.nil?)
if ((s = date_pattern.match(value)).nil?)
raise TypeError, "Invalid Datetime format #{value}"
end
return DateTime.new(s[1].to_i,s[2].to_i,s[3].to_i,s[4].to_i,s[5].to_i,s[6].to_i+Rational(s[7].to_i,1000000))
else
return TimeDelta.new(s[1].to_i, s[2].to_i, s[3].to_i, s[4].to_i, s[5].to_i)
end
return value
else
return nil if _type.nil?
raise TypeError, "Invalid CIM type #{_type}"
end
end
|
.tocimxml(value, wrap_references = false) ⇒ Object
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
|
# File 'lib/wbem/cim_obj.rb', line 1035
def WBEM.tocimxml(value, wrap_references = false)
if ([CIMType, String, Integer, DateTime, TimeDelta, TrueClass, FalseClass].any? do |item|
value.is_a?(item)
end)
return VALUE.new(WBEM.atomic_to_cim_xml(value))
elsif (wrap_references and (value.is_a?(CIMInstanceName) or
value.is_a?(CIMClassName) or
value.is_a?(CIMLocalClassPath)))
return VALUE_REFERENCE.new(WBEM.atomic_to_cim_xml(value))
elsif (value.methods.include?("tocimxml"))
return value.tocimxml()
elsif (value.is_a?(Array))
if (wrap_references and (value[0].is_a?(CIMInstanceName) or
value[0].is_a?(CIMClassName) or
value.is_a?(CIMLocalClassPath)))
return VALUE_REFARRAY.new(value.collect {|val| WBEM.tocimxml(val, wrap_references)})
else
return VALUE_ARRAY.new(value.collect {|val| WBEM.tocimxml(val, wrap_references)})
end
elsif (value.nil?)
return value
end
raise TypeError, "Can't convert #{value} (#{value.class}) to CIM XML"
end
|
.tupletree_to_s(tt) ⇒ Object
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/wbem/tupletree.rb', line 127
def WBEM.tupletree_to_s(tt)
"name: #{tt[0]}\nattributes: #{tt[1].to_a.collect {|a| "(#{a[0]} => #{a[1]})"}.join(", ") unless tt[1].nil?}\n tree: #{unless tt[2].nil?
if tt[2][0].is_a?(Array)
tt[2].collect { |t| WBEM.tupletree_to_s(t) }.join
else
WBEM.tupletree_to_s(tt[2])
end
end
}"
end
|
.unpack_boolean(p) ⇒ Object
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
|
# File 'lib/wbem/tupleparse.rb', line 1162
def WBEM.unpack_boolean(p)
if p.nil?
return nil
end
p = p.strip().downcase()
if p == "true"
return true
elsif p == "false"
return false
elsif p == ""
return nil
else
raise ParseError, "invalid boolean #{p}"
end
end
|
.unpack_value(tt) ⇒ Object
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
|
# File 'lib/wbem/tupleparse.rb', line 1134
def WBEM.unpack_value(tt)
val = WBEM.list_of_matching(tt, ["VALUE", "VALUE.ARRAY"])
valtype = WBEM.attrs(tt)["TYPE"]
raw_val = WBEM.list_of_matching(tt, ["VALUE", "VALUE.ARRAY"])
if raw_val.empty?
return nil
elsif raw_val.length > 1
raise ParseError, "more than one VALUE or VALUE.ARRAY under #{WBEM.name(tt)}"
end
raw_val = raw_val[0]
if raw_val.is_a?(Array)
return raw_val.collect { |x| tocimobj(valtype, x) }
elif raw_val.empty?
return nil
else
return WBEM.tocimobj(valtype, raw_val)
end
end
|
.valid_cimtype?(obj) ⇒ Boolean
163
164
165
166
167
168
169
170
171
|
# File 'lib/wbem/cim_types.rb', line 163
def WBEM.valid_cimtype?(obj)
begin
WBEM.cimtype(obj)
rescue TypeError
false
else
true
end
end
|
.wbem_request(url, data, creds, headers = [], debug = 0, x509 = nil) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
|
# File 'lib/wbem/cim_http.rb', line 66
def WBEM.wbem_request(url, data, creds, = [], debug = 0, x509 = nil)
host, port, ssl, urlcreds = WBEM.parse_url(url)
creds = urlcreds unless creds
h = Net::HTTP.new(host, port)
if (ssl)
if x509
cert_file = x509.get("cert_file")
key_file = x509.get("key_file", cert_file)
else
cert_file = nil
key_file = nil
end
h.use_ssl = true
end
data = "<?xml version='1.0' encoding='utf-8' ?>\n" + data
response = nil
h.start do |http|
request = Net::HTTP::Post.new("/cimom")
request.basic_auth creds[0], creds[1]
request.content_type = "application/xml"
request.content_length = data.length
.each do ||
s = .split(":", 2).collect { |x| x.strip }
request.add_field(URI.escape(s[0]), URI.escape(s[1]))
end
response = http.request(request, data)
end
unless response.kind_of?(Net::HTTPSuccess)
if (response.kind_of?(NET::HTTPUnauthorized))
raise AuthError, response.reason
elsif (response.fetch("CIMError", []) or response.fetch("PGErrorDetail", []))
raise CIMHttpError, "CIMError: #{response.fetch('CIMError',[])}: #{response.fetch('PGErrorDetail',[])}"
end
raise CIMHttpError, "HTTP error: #{response.reason}"
end
response.body
end
|
.xml_to_tupletree(xml_string) ⇒ Object
122
123
124
125
|
# File 'lib/wbem/tupletree.rb', line 122
def WBEM.xml_to_tupletree(xml_string)
return dom_to_tupletree(REXML::Document.new(xml_string))
end
|
Instance Method Details
#tupletree_to_dom(document, tree, parent = nil) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/wbem/tupletree.rb', line 50
def tupletree_to_dom(document, tree, parent=nil)
name, attrs, contents, junk = tree
parent = document if parent.nil?
elt = Element.new(name, parent)
attrs.each { |key, val| elt.add_attribute(key, val) }
contents.each do |child|
if child.is_a? Array
tupletree_to_dom(document, child, elt)
else
elt.add_text(child)
end
end
return elt
end
|