-
Notifications
You must be signed in to change notification settings - Fork 0
/
internal_providers.py
209 lines (173 loc) · 8.29 KB
/
internal_providers.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
"""Python Provider for CIM_Namespace
Instruments the CIM class CIM_Namespace
"""
import pywbem
from socket import getfqdn
import cimdb
class CIM_NamespaceProvider(pywbem.CIMProvider):
"""Instrument the CIM class CIM_Namespace
Namespace provides a domain (in other words, a container), in which the
instances [of a class] are guaranteed to be unique per the KEY
qualifier definitions. It is named relative to the CIM_ObjectManager
implementation that provides such a domain.
"""
def __init__ (self, env):
logger = env.get_logger()
logger.log_debug('Initializing provider %s from %s' \
% (self.__class__.__name__, __file__))
# If you will be filtering instances yourself according to
# property_list, role, result_role, and result_class_name
# parameters, set self.filter_results to False
# self.filter_results = False
def get_instance(self, env, model, cim_class):
"""Return an instance.
Keyword arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
model -- A template of the pywbem.CIMInstance to be returned. The
key properties are set on this instance to correspond to the
instanceName that was requested. The properties of the model
are already filtered according to the PropertyList from the
request. Only properties present in the model need to be
given values. If you prefer, you can set all of the
values, and the instance will be filtered for you.
cim_class -- The pywbem.CIMClass
Possible Errors:
CIM_ERR_ACCESS_DENIED
CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized
or otherwise incorrect parameters)
CIM_ERR_NOT_FOUND (the CIM Class does exist, but the requested CIM
Instance does not exist in the specified namespace)
CIM_ERR_FAILED (some other unspecified error occurred)
"""
logger = env.get_logger()
logger.log_debug('Entering %s.get_instance()' \
% self.__class__.__name__)
#model['Caption'] = # TODO (type = unicode)
#model['ClassInfo'] = # TODO (type = pywbem.Uint16 self.Values.ClassInfo) (Required)
#model['ClassType'] = # TODO (type = pywbem.Uint16 self.Values.ClassType)
#model['ClassTypeVersion'] = # TODO (type = unicode)
#model['Description'] = # TODO (type = unicode)
#model['DescriptionOfClassInfo'] = # TODO (type = unicode)
#model['DescriptionOfClassType'] = # TODO (type = unicode)
#model['ElementName'] = # TODO (type = unicode)
return model
def enum_instances(self, env, model, cim_class, keys_only):
"""Enumerate instances.
The WBEM operations EnumerateInstances and EnumerateInstanceNames
are both mapped to this method.
This method is a python generator
Keyword arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
model -- A template of the pywbem.CIMInstances to be generated.
The properties of the model are already filtered according to
the PropertyList from the request. Only properties present in
the model need to be given values. If you prefer, you can
always set all of the values, and the instance will be filtered
for you.
cim_class -- The pywbem.CIMClass
keys_only -- A boolean. True if only the key properties should be
set on the generated instances.
Possible Errors:
CIM_ERR_FAILED (some other unspecified error occurred)
"""
logger = env.get_logger()
logger.log_debug('Entering %s.enum_instances()' \
% self.__class__.__name__)
# Key properties
model['ObjectManagerName'] = 'TODO'
model['ObjectManagerCreationClassName'] = 'TODO'
model['SystemName'] = getfqdn()
model['CreationClassName'] = 'CIM_Namespace'
model['SystemCreationClassName'] = 'TODO'
for ns in cimdb.Namespaces():
model['Name'] = ns
if keys_only:
yield model.copy() #TODO remove copy when provifc is fixed.
else:
try:
yield self.get_instance(env, model, cim_class)
except pywbem.CIMError, (num, msg):
if num not in (pywbem.CIM_ERR_NOT_FOUND,
pywbem.CIM_ERR_ACCESS_DENIED):
raise
def set_instance(self, env, instance, previous_instance, cim_class):
"""Return a newly created or modified instance.
Keyword arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
instance -- The new pywbem.CIMInstance. If modifying an existing
instance, the properties on this instance have been filtered by
the PropertyList from the request.
previous_instance -- The previous pywbem.CIMInstance if modifying
an existing instance. None if creating a new instance.
cim_class -- The pywbem.CIMClass
Return the new instance. The keys must be set on the new instance.
Possible Errors:
CIM_ERR_ACCESS_DENIED
CIM_ERR_NOT_SUPPORTED
CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized
or otherwise incorrect parameters)
CIM_ERR_ALREADY_EXISTS (the CIM Instance already exists -- only
valid if previous_instance is None, indicating that the operation
was CreateInstance)
CIM_ERR_NOT_FOUND (the CIM Instance does not exist -- only valid
if previous_instance is not None, indicating that the operation
was ModifyInstance)
CIM_ERR_FAILED (some other unspecified error occurred)
"""
logger = env.get_logger()
logger.log_debug('Entering %s.set_instance()' \
% self.__class__.__name__)
# TODO create or modify the instance
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED) # Remove to implement
return instance
def delete_instance(self, env, instance_name):
"""Delete an instance.
Keyword arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
instance_name -- A pywbem.CIMInstanceName specifying the instance
to delete.
Possible Errors:
CIM_ERR_ACCESS_DENIED
CIM_ERR_NOT_SUPPORTED
CIM_ERR_INVALID_NAMESPACE
CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized
or otherwise incorrect parameters)
CIM_ERR_INVALID_CLASS (the CIM Class does not exist in the specified
namespace)
CIM_ERR_NOT_FOUND (the CIM Class does exist, but the requested CIM
Instance does not exist in the specified namespace)
CIM_ERR_FAILED (some other unspecified error occurred)
"""
logger = env.get_logger()
logger.log_debug('Entering %s.delete_instance()' \
% self.__class__.__name__)
# TODO delete the resource
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED) # Remove to implement
class Values(object):
class ClassType(object):
Unknown = pywbem.Uint16(0)
Other = pywbem.Uint16(1)
CIM = pywbem.Uint16(2)
DMI_Recast = pywbem.Uint16(200)
SNMP_Recast = pywbem.Uint16(201)
CMIP_Recast = pywbem.Uint16(202)
class ClassInfo(object):
Unknown = pywbem.Uint16(0)
Other = pywbem.Uint16(1)
CIM_1_0 = pywbem.Uint16(2)
CIM_2_0 = pywbem.Uint16(3)
CIM_2_1 = pywbem.Uint16(4)
CIM_2_2 = pywbem.Uint16(5)
CIM_2_3 = pywbem.Uint16(6)
CIM_2_4 = pywbem.Uint16(7)
CIM_2_5 = pywbem.Uint16(8)
CIM_2_6 = pywbem.Uint16(9)
CIM_2_7 = pywbem.Uint16(10)
CIM_2_8 = pywbem.Uint16(11)
DMI_Recast = pywbem.Uint16(200)
SNMP_Recast = pywbem.Uint16(201)
CMIP_Recast = pywbem.Uint16(202)
## end of class CIM_NamespaceProvider
def get_providers(env):
cim_namespace_prov = CIM_NamespaceProvider(env)
return {'CIM_Namespace': cim_namespace_prov}