-
Notifications
You must be signed in to change notification settings - Fork 26
/
_cim_xml.py
1746 lines (1331 loc) · 54.8 KB
/
_cim_xml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
65
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
113
114
115
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
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
672
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
704
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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
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
798
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
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# (C) Copyright 2003-2006 Hewlett-Packard Development Company, L.P.
# (C) Copyright 2006-2007 Novell, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Author: Tim Potter <tpot@hp.com>
# Author: Bart Whiteley <bwhiteley@suse.de>
#
"""
Functions to create XML documents and elements conforming to the DMTF
standard DSP0201, Representation of CIM in XML, v2.2.
https://www.dmtf.org/standards/wbem/DSP201.html
https://www.dmtf.org/standards/published_documents/DSP201.pdf
Elements generated by this module should conform to version 2.2 of the
DTD:
https://www.dmtf.org/standards/wbem/CIM_DTD_V22.dtd
There should be one class for each element described in the DTD. Their
init methods take builtin Python types, or other _cim_xml classes where
child elements are required.
Every class is a subclass of the Element class and so shares the same
attributes and methods, and can be used with the built-in Python XML
handling routines. In particular you can call the toxml() and
toprettyxml() methods to generate XML.
Note that converting using toprettyxml() inserts whitespace which may
corrupt the data in the XML (!!) so you should only do this when
displaying to humans who can ignore it, and never for computers. XML
always passes through all non-markup whitespace.
"""
from __future__ import absolute_import
from xml.dom.minidom import Element, Text, CDATASection
import six
__all__ = []
def _text(data):
"""Return a minidom text node with the specified data string.
When converting that node to an XML string using ``toxml()``, XML-escaping
will be applied if needed (for example, ``_text('&').toxml() = '&'``).
Note: The API for the minidom text node function has changed in
Python 2.3. The code for older Python versions has been removed from this
function in pywbem 0.8; the Python version check is now done in
__init__.py.
"""
# The following initialization approach requires Python 2.3 or higher.
t = Text()
t.data = data
return t
# Switch controlling whether the escaping of special XML characters in any
# request messages sent to the WBEM server will be done using CDATA
# sections (if True), or using XML entity references (e.g. &) (if
# False).
# Using XML-based escaping generates a simpler CIM-XML payload.
# Standards-conforming WBEM servers need to support both ways.
# You only need to set this to True if the WBEM server has no support for
# XML-based escaping, but does have support for CDATA-based escaping.
_CDATA_ESCAPING = False
def _pcdata_nodes(pcdata):
"""Return a list of minidom nodes with the properly escaped ``pcdata``
inside.
The following special XML characters are escaped:
* left angle bracket (<)
* Right angle bracket (>)
* Ampersand (&)
By default, XML-based escaping is used for these characters. XML-based
escaping will cause the corresponding XML entity references to be used
(for example, the ampersand character ``&`` will be represented as
``&``, and the returned list contains one text node with the escaped
pcdata string.
Nesting of escaped pcdata is naturally supported with XML-based escaping.
For example, if the pcdata string is ``a&b``, the XML-escaped string
will be ``a&amp;b``.
If the ``_cim_xml._CDATA_ESCAPING`` switch is set to True, CDATA-based
escaping is used instead. CDATA-based escaping will cause a CDATA section
to be used for the entire string, or consecutive CDATA sequences (see
discussion of nesting, below). The returned node list contains only CDATA
section nodes. Example: The pcdata string ``a<b>c`` will become
``<![CDATA[a<b>]]>``, allowing the special XML characters to be used
unchanged inside of the CDATA section.
Nesting of escaped pcdata is supported with CDATA-based escaping, by using
the following approach: If the input pcdata string already contains CDATA
sections, they are split into separate strings, splitting the CDATA end
token string in the middle, and these part strings are CDATA-escaped
separately. See https://en.wikipedia.org/wiki/CDATA#Nesting for details.
Escaping of already escaped pcdata is needed in support of nested embedded
instances. That requires that each level of escaping can lateron be
unescaped, one at a time.
"""
nodelist = []
if _CDATA_ESCAPING and isinstance(pcdata, six.string_types) and \
(pcdata.find("<") >= 0 or
pcdata.find(">") >= 0 or
pcdata.find("&") >= 0): # noqa: E129
# In order to support nesting of CDATA sections, we represent pcdata
# that already contains CDATA sections by multiple new CDATA sections
# whose boundaries split the end marker of the already existing CDATA
# sections.
pcdata_part_list = pcdata.split("]]>")
# ']]>' is the complete CDATA section end marker
i = 0
for pcdata_part in pcdata_part_list:
i += 1
left = "" if i == 1 else "]>"
# ']>' is right part of CDATA section end marker
right = "" if i == len(pcdata_part_list) else "]"
# "]" is left part of CDATA section end marker
# The following initialization approach requires Python 2.3 or
# higher.
node = CDATASection()
node.data = left + pcdata_part + right
nodelist.append(node)
else:
# The following automatically uses XML entity references
# for escaping.
node = _text(pcdata)
nodelist.append(node)
return nodelist
class CIMElement(Element):
"""A base class that has a few bonus helper methods."""
ownerDocument = None
def __init__(self, name):
# We use call by class name because it is an old-style class.
Element.__init__(self, name)
def setName(self, name):
"""Set the NAME attribute of the element."""
self.setAttribute('NAME', name)
def setOptionalAttribute(self, name, value):
"""Set an attribute if the value parameter is not None."""
if value is not None:
self.setAttribute(name, value)
def appendOptionalChild(self, child):
"""Append a child element which can be None."""
if child is not None:
self.appendChild(child)
def appendChildren(self, children):
"""Append a list or tuple of children."""
for child in children:
self.appendChild(child)
# Root element
class CIM(CIMElement):
"""
The CIM element is the root element of every XML Document that is
valid with respect to this schema.
Each document takes one of two forms; it either contains a single
MESSAGE element defining a CIM message (to be used in the HTTP
mapping), or it contains a DECLARATION element used to declare a
set of CIM objects.
::
<!ELEMENT CIM (MESSAGE | DECLARATION)>
<!ATTLIST CIM
CIMVERSION CDATA #REQUIRED
DTDVERSION CDATA #REQUIRED>
"""
def __init__(self, data, cim_version, dtd_version):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'CIM')
self.setAttribute('CIMVERSION', cim_version)
self.setAttribute('DTDVERSION', dtd_version)
self.appendChild(data)
# Object declaration elements
class DECLARATION(CIMElement):
"""
The DECLARATION element defines a set of one or more declarations
of CIM objects. These are partitioned into logical declaration
subsets.
::
<!ELEMENT DECLARATION (DECLGROUP | DECLGROUP.WITHNAME |
DECLGROUP.WITHPATH)+>
"""
def __init__(self, data):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'DECLARATION')
self.appendChildren(data)
class DECLGROUP(CIMElement):
"""
The DECLGROUP element defines a logical set of CIM Class, Instance
and Qualifier declarations. It MAY optionally include a
NAMESPACEPATH or LOCALNAMESPACEPATH element which, if present,
defines the common namespace in which all objects within the group
are declared.
::
<!ELEMENT DECLGROUP ((LOCALNAMESPACEPATH | NAMESPACEPATH)?,
QUALIFIER.DECLARATION*, VALUE.OBJECT*)>
"""
def __init__(self, data):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'DECLGROUP')
self.appendChildren(data)
class DECLGROUP_WITHNAME(CIMElement):
# pylint: disable=invalid-name
"""
The DECLGROUP.WITHNAME element defines a logical set of CIM Class,
Instance and Qualifier declarations. It MAY optionally include a
NAMESPACEPATH or LOCALNAMESPACEPATH element which, if present,
defines the common namespace in which all objects within the group
are declared.
::
<!ELEMENT DECLGROUP.WITHNAME ((LOCALNAMESPACEPATH | NAMESPACEPATH)?,
QUALIFIER.DECLARATION*, VALUE.NAMEDOBJECT*)>
"""
def __init__(self, data):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'DECLGROUP.WITHNAME')
self.appendChildren(data)
class DECLGROUP_WITHPATH(CIMElement):
# pylint: disable=invalid-name
"""
The DECLGROUP.WITHPATH element defines a logical set of CIM Class
and Instance declarations. Each object is declared with its own
independent naming and location information.
::
<!ELEMENT DECLGROUP.WITHPATH (VALUE.OBJECTWITHPATH |
VALUE.OBJECTWITHLOCALPATH)*>
"""
def __init__(self, data):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'DECLGROUP.WITHPATH')
self.appendChildren(data)
class QUALIFIER_DECLARATION(CIMElement):
# pylint: disable=invalid-name
"""
The QUALIFIER.DECLARATION element defines a single CIM Qualifier
declaration.
::
<!ELEMENT QUALIFIER.DECLARATION (SCOPE?, (VALUE | VALUE.ARRAY)?)>
<!ATTLIST QUALIFIER.DECLARATION
%CIMName;
%CIMType; #REQUIRED
ISARRAY (true|false) #IMPLIED
%ArraySize;
%QualifierFlavor;>
"""
def __init__(self, name, type_, value=None, is_array=None,
array_size=None, qualifier_scopes=None,
overridable=None, tosubclass=None,
toinstance=None, translatable=None):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'QUALIFIER.DECLARATION')
self.setName(name)
self.setAttribute('TYPE', type_)
if is_array is not None:
self.setOptionalAttribute('ISARRAY', str(is_array).lower())
if array_size is not None:
self.setAttribute('ARRAYSIZE', str(array_size))
if overridable is not None:
self.setAttribute('OVERRIDABLE', str(overridable).lower())
if tosubclass is not None:
self.setAttribute('TOSUBCLASS', str(tosubclass).lower())
if toinstance is not None:
self.setAttribute('TOINSTANCE', str(toinstance).lower())
if translatable is not None:
self.setAttribute('TRANSLATABLE', str(translatable).lower())
if qualifier_scopes:
scope = SCOPE(qualifier_scopes)
self.appendOptionalChild(scope)
self.appendOptionalChild(value)
class SCOPE(CIMElement):
"""
The SCOPE element defines the scope of a QUALIFIER.DECLARATION in
the case that there are restrictions on the scope of the Qualifier
declaration.
::
<!ELEMENT SCOPE EMPTY>
<!ATTLIST SCOPE
CLASS (true|false) 'false'
ASSOCIATION (true|false) 'false'
REFERENCE (true|false) 'false'
PROPERTY (true|false) 'false'
METHOD (true|false) 'false'
PARAMETER (true|false) 'false'
INDICATION (true|false) 'false'>
"""
def __init__(self, scopes=None):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'SCOPE')
if not scopes:
scopes = {}
elif 'any' in scopes and scopes['any']:
# scopes is a NocaseDict
scopes = {'CLASS': True,
'ASSOCIATION': True,
'REFERENCE': True,
'PROPERTY': True,
'METHOD': True,
'PARAMETER': True,
'INDICATION': True}
for k in sorted(scopes.keys(), key=lambda k: k.upper()):
v = scopes[k]
self.setOptionalAttribute(k.upper(), str(v).lower())
# Object value elements
class VALUE(CIMElement):
"""
The VALUE element is used to define a single (non-array and
non-reference) CIM Property value, CIM Qualifier value, or a CIM
Method Parameter value.
::
<!ELEMENT VALUE (#PCDATA)>
"""
def __init__(self, pcdata):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'VALUE')
if pcdata is not None:
self.appendChildren(_pcdata_nodes(pcdata))
class VALUE_ARRAY(CIMElement):
# pylint: disable=invalid-name
"""
The VALUE.ARRAY element is used to represent the value of a CIM
Property or Qualifier that has an array type.
::
<!ELEMENT VALUE.ARRAY (VALUE*)>
"""
def __init__(self, values):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'VALUE.ARRAY')
self.appendChildren(values)
class VALUE_REFERENCE(CIMElement):
# pylint: disable=invalid-name
"""
The VALUE.REFERENCE element is used to define a single CIM
reference Property value.
::
<!ELEMENT VALUE.REFERENCE (CLASSPATH | LOCALCLASSPATH | CLASSNAME |
INSTANCEPATH | LOCALINSTANCEPATH |
INSTANCENAME)>
"""
def __init__(self, data):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'VALUE.REFERENCE')
self.appendChild(data)
class VALUE_REFARRAY(CIMElement):
# pylint: disable=invalid-name
"""
The VALUE.REFARRAY element is used to represent the value of an
array of CIM references.
::
<!ELEMENT VALUE.REFARRAY (VALUE.REFERENCE*)>
"""
def __init__(self, data):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'VALUE.REFARRAY')
self.appendChildren(data)
class VALUE_OBJECT(CIMElement):
# pylint: disable=invalid-name
"""
The VALUE.OBJECT element is used to define a value which is
comprised of a single CIM Class or Instance definition.
::
<!ELEMENT VALUE.OBJECT (CLASS | INSTANCE)>
"""
def __init__(self, data):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'VALUE.OBJECT')
self.appendChild(data)
class VALUE_NAMEDINSTANCE(CIMElement):
# pylint: disable=invalid-name
"""
The VALUE.NAMEDINSTANCE element is used to define a value which
is comprised of a single named CIM Instance definition.
::
<!ELEMENT VALUE.NAMEDINSTANCE (INSTANCENAME, INSTANCE)>
"""
def __init__(self, instancename, instance):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'VALUE.NAMEDINSTANCE')
self.appendChild(instancename)
self.appendChild(instance)
class VALUE_NAMEDOBJECT(CIMElement):
# pylint: disable=invalid-name
"""
The VALUE.NAMEDOBJECT element is used to define a value which
is comprised of a single named CIM Class or Instance definition.
::
<!ELEMENT VALUE.NAMEDOBJECT (CLASS | (INSTANCENAME, INSTANCE))>
"""
def __init__(self, data):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'VALUE.NAMEDOBJECT')
if isinstance(data, (tuple, list)):
self.appendChildren(data)
else:
self.appendChild(data)
class VALUE_OBJECTWITHLOCALPATH(CIMElement):
# pylint: disable=invalid-name
"""
The VALUE.OBJECTWITHLOCALPATH element is used to define a value
which is comprised of a single CIM Object (Class or Instance)
definition with additional information that defines the local path
to that Object.
::
<!ELEMENT VALUE.OBJECTWITHLOCALPATH ((LOCALCLASSPATH, CLASS) |
(LOCALINSTANCEPATH, INSTANCE))>
"""
def __init__(self, data1, data2):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'VALUE.OBJECTWITHLOCALPATH')
self.appendChild(data1)
self.appendChild(data2)
class VALUE_OBJECTWITHPATH(CIMElement):
# pylint: disable=invalid-name
"""
The VALUE.OBJECTWITHPATH element is used to define a value
which is comprised of a single CIM Object (Class or Instance)
definition with additional information that defines the absolute
path to that Object.
::
<!ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH, CLASS) |
(INSTANCEPATH, INSTANCE))>
"""
def __init__(self, data1, data2):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'VALUE.OBJECTWITHPATH')
self.appendChild(data1)
self.appendChild(data2)
class VALUE_NULL(CIMElement):
# pylint: disable=invalid-name
"""
The VALUE.NULL element is used to represent an array item that has
no assigned value (i.e. is NULL).
::
<!ELEMENT VALUE.NULL EMPTY>
"""
def __init__(self):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'VALUE.NULL')
class VALUE_INSTANCEWITHPATH(CIMElement):
# pylint: disable=invalid-name
"""
The VALUE.INSTANCEWITHPATH element is used to define a value
a value that comprises a single CIM instance definition with additional
information that defines the absolute path to that object.
::
<!ELEMENT VALUE.INSTANCEWITHPATH (INSTANCEPATH, INSTANCE)>
"""
def __init__(self, data1, data2):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'VALUE.INSTANCEWITHPATH')
self.appendChild(data1)
self.appendChild(data2)
# Object naming and location elements
class NAMESPACEPATH(CIMElement):
# pylint: disable=invalid-name
"""
The NAMESPACEPATH element is used to define a Namespace Path. It
consists of a HOST element and a LOCALNAMESPACE element.
::
<!ELEMENT NAMESPACEPATH (HOST, LOCALNAMESPACEPATH)>
"""
def __init__(self, host, localnamespacepath):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'NAMESPACEPATH')
self.appendChild(host)
self.appendChild(localnamespacepath)
class LOCALNAMESPACEPATH(CIMElement):
# pylint: disable=invalid-name
"""
The LOCALNAMESPACEPATH element is used to define a local Namespace
path (one without a Host component). It consists of one or more
NAMESPACE elements (one for each namespace in the path).
::
<!ELEMENT LOCALNAMESPACEPATH (NAMESPACE+)>
"""
def __init__(self, namespaces):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'LOCALNAMESPACEPATH')
self.appendChildren(namespaces)
class HOST(CIMElement):
# pylint: disable=invalid-name
"""
The HOST element is used to define a single Host. The element
content MUST specify a legal value for a hostname in accordance
with the CIM specification.
::
<!ELEMENT HOST (#PCDATA)>
"""
def __init__(self, pcdata):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'HOST')
self.appendChild(_text(pcdata))
class NAMESPACE(CIMElement):
# pylint: disable=invalid-name
"""
The NAMESPACE element is used to define a single Namespace
component of a Namespace path.
::
<!ELEMENT NAMESPACE EMPTY>
<!ATTLIST NAMESPACE
%CIMName;>
"""
def __init__(self, name):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'NAMESPACE')
self.setName(name)
class CLASSPATH(CIMElement):
# pylint: disable=invalid-name
"""
The CLASSPATH element defines the absolute path to a CIM Class. It
is formed from a namespace path and Class name.
::
<!ELEMENT CLASSPATH (NAMESPACEPATH, CLASSNAME)>
"""
def __init__(self, namespacepath, classname):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'CLASSPATH')
self.appendChild(namespacepath)
self.appendChild(classname)
class LOCALCLASSPATH(CIMElement):
# pylint: disable=invalid-name
"""
The LOCALCLASSPATH element defines the a local path to a CIM
Class. It is formed from a local namespace path and Class name.
::
<!ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME)>
"""
def __init__(self, localnamespacepath, classname):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'LOCALCLASSPATH')
self.appendChild(localnamespacepath)
self.appendChild(classname)
class CLASSNAME(CIMElement):
# pylint: disable=invalid-name
"""
The CLASSNAME element defines the qualifying name of a CIM Class.
::
<!ELEMENT CLASSNAME EMPTY>
<!ATTLIST CLASSNAME
%CIMName;>
"""
def __init__(self, classname):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'CLASSNAME')
self.setName(classname)
class INSTANCEPATH(CIMElement):
# pylint: disable=invalid-name
"""
The INSTANCEPATH element defines the absolute path to a CIM
Instance. It is comprised of a Namespace path and an Instance Name
(model path).
::
<!ELEMENT INSTANCEPATH (NAMESPACEPATH, INSTANCENAME)>
"""
def __init__(self, namespacepath, instancename):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'INSTANCEPATH')
self.appendChild(namespacepath)
self.appendChild(instancename)
class LOCALINSTANCEPATH(CIMElement):
# pylint: disable=invalid-name
"""
The LOCALINSTANCEPATH element defines the local path to a CIM
Instance. It is comprised of a local Namespace path and an
Instance Name (model path).
::
<!ELEMENT LOCALINSTANCEPATH (LOCALNAMESPACEPATH, INSTANCENAME)>
"""
def __init__(self, localpath, instancename):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'LOCALINSTANCEPATH')
self.appendChild(localpath)
self.appendChild(instancename)
class INSTANCENAME(CIMElement):
# pylint: disable=invalid-name
"""
The INSTANCENAME element defines the location of a CIM Instance
within a Namespace (it is referred to in the CIM Specification
as a Model Path). It is comprised of a class name and a key
binding information.
If the Class has a single key property, then a single KEYVALUE or
VALUE.REFERENCE subelement may be used to describe the
(necessarily) unique key value without a key name. Alternatively a
single KEYBINDING subelement may be used instead.
If the Class has more than one key property, then a KEYBINDING
subelement MUST appear for each key.
If there are no key-bindings specified, the instance is assumed to
be a singleton instance of a keyless Class.
::
<!ELEMENT INSTANCENAME (KEYBINDING* | KEYVALUE? | VALUE.REFERENCE?)>
<!ATTLIST INSTANCENAME
%ClassName;>
"""
def __init__(self, classname, data):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'INSTANCENAME')
self.setAttribute('CLASSNAME', classname)
if data is not None:
if isinstance(data, list):
self.appendChildren(data)
else:
self.appendChild(data)
class OBJECTPATH(CIMElement):
# pylint: disable=invalid-name
"""
The OBJECTPATH element is used to define a full path to a single
CIM Object (Class or Instance).
::
<!ELEMENT OBJECTPATH (INSTANCEPATH | CLASSPATH)>
"""
def __init__(self, data):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'OBJECTPATH')
self.appendChild(data)
class KEYBINDING(CIMElement):
# pylint: disable=invalid-name
"""
The KEYBINDING element defines a single key property value binding.
::
<!ELEMENT KEYBINDING (KEYVALUE | VALUE.REFERENCE)>
<!ATTLIST KEYBINDING
%CIMName;>
"""
def __init__(self, name, data):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'KEYBINDING')
self.setName(name)
self.appendChild(data)
class KEYVALUE(CIMElement):
# pylint: disable=invalid-name
"""
The KEYVALUE element defines a single property key value when the
key property is a non-reference type.
::
<!ELEMENT KEYVALUE (#PCDATA)>
<!ATTLIST KEYVALUE
VALUETYPE (string|boolean|numeric) 'string'
%CIMType; #IMPLIED> # DTD <2.4
%CIMType; #REQUIRED> # DTD >=2.4
"""
def __init__(self, data, value_type=None, cim_type=None):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'KEYVALUE')
if value_type is None:
self.setAttribute('VALUETYPE', 'string')
else:
self.setAttribute('VALUETYPE', value_type)
# Even though the goal is to always set the TYPE attribute in order
# to conform with DTD >=2.4, the data structures in CIMInstanceName
# do not have the required information currently. Therefore, we
# leave it to the caller to supply the TYPE attribute, where possible,
# but we do not currently require the caller to provide it.
self.setOptionalAttribute('TYPE', cim_type)
if data is not None:
self.appendChild(_text(data))
# Object definition elements
class CLASS(CIMElement):
# pylint: disable=invalid-name
"""
The CLASS element defines a single CIM Class.
::
<!ELEMENT CLASS (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY |
PROPERTY.REFERENCE)*, METHOD*)>
<!ATTLIST CLASS
%CIMName;
%SuperClass;>
"""
def __init__(self, classname, properties=None, methods=None,
qualifiers=None, superclass=None):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'CLASS')
self.setName(classname)
self.setOptionalAttribute('SUPERCLASS', superclass)
children = []
if qualifiers:
children.extend(qualifiers)
if properties:
children.extend(properties)
if methods:
children.extend(methods)
self.appendChildren(children)
class INSTANCE(CIMElement):
# pylint: disable=invalid-name
"""
The INSTANCE element defines a single CIM Instance of a CIM Class.
::
<!ELEMENT INSTANCE (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY |
PROPERTY.REFERENCE)*)>
<!ATTLIST INSTANCE
%ClassName;
xml:lang NMTOKEN #IMPLIED>
"""
def __init__(self, classname, properties=None, qualifiers=None,
xml_lang=None):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'INSTANCE')
self.setAttribute('CLASSNAME', classname)
self.setOptionalAttribute('xml:lang', xml_lang)
children = []
if qualifiers:
children.extend(qualifiers)
if properties:
children.extend(properties)
self.appendChildren(children)
class QUALIFIER(CIMElement):
# pylint: disable=invalid-name
"""
The QUALIFIER element defines a single CIM Qualifier. If the
Qualifier has a non-array type, it contains a single VALUE element
representing the value of the Qualifier. If the Qualifier has an
array type, it contains a single VALUE.ARRAY element to represent
the value.
If the Qualifier has no assigned value then the VALUE element MUST
be absent.
::
<!ELEMENT QUALIFIER ((VALUE | VALUE.ARRAY)?)>
<!ATTLIST QUALIFIER
%CIMName;
%CIMType; #REQUIRED
%Propagated;
%QualifierFlavor;
xml:lang NMTOKEN #IMPLIED>
"""
def __init__(self, name, type_, value=None, propagated=None,
overridable=None, tosubclass=None, toinstance=None,
translatable=None, xml_lang=None):
# We use call by class name because it is an old-style class.
CIMElement.__init__(self, 'QUALIFIER')
self.setName(name)
self.setAttribute('TYPE', type_)
if propagated is not None:
self.setAttribute('PROPAGATED', str(propagated).lower())
if overridable is not None:
self.setAttribute('OVERRIDABLE', str(overridable).lower())
if tosubclass is not None:
self.setAttribute('TOSUBCLASS', str(tosubclass).lower())
if toinstance is not None:
self.setAttribute('TOINSTANCE', str(toinstance).lower())
if translatable is not None:
self.setAttribute('TRANSLATABLE', str(translatable).lower())
self.setOptionalAttribute('xml:lang', xml_lang)
self.appendOptionalChild(value)
class PROPERTY(CIMElement):
# pylint: disable=invalid-name
"""
The PROPERTY element defines a single (non-array) CIM Property
that is not a reference. It contains a single VALUE element
representing the value of the Property.
If the Property has no assigned value then the VALUE element MUST be
absent.
CIM Reference Properties are described using the
PROPERTY.REFERENCE element.
::
<!ELEMENT PROPERTY (QUALIFIER*, VALUE?)>
<!ATTLIST PROPERTY
%CIMName;
%CIMType; #REQUIRED
%ClassOrigin;