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
|
# Software Management Providers
#
# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Python Provider for LMI_YumFileCheck
Instruments the CIM class LMI_YumFileCheck
"""
import pywbem
from pywbem.cim_provider2 import CIMProvider2
from util.common import *
filecheck2model = YumFileCheck.filecheck_wrapper(
'root/cimv2', 'LMI_YumFileCheck')
class LMI_YumFileCheck(CIMProvider2):
"""Instrument the CIM class LMI_YumFileCheck
Identifies a file contained by RPM package. It's located in directory
identified in FileName. The Invoke methods check for file existence
and whether its attributes match those given by RPM package.
"""
def __init__ (self, env):
logger = env.get_logger()
logger.log_debug('Initializing provider %s from %s' \
% (self.__class__.__name__, __file__))
def get_instance(self, env, model):
"""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.
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__)
vpkg = YumFileCheck.object_path2yumcheck(env, model.path)
pkg = vpkg.po
fi = pkg.hdr.fiFromHeader()
return filecheck2model(vpkg, model['Name'], env, False)
def enum_instances(self, env, model, 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.
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__)
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED) # Remove to implement
def set_instance(self, env, instance, modify_existing):
"""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.
modify_existing -- True if ModifyInstance, False if CreateInstance
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 modify_existing is False, indicating that the operation
was CreateInstance)
CIM_ERR_NOT_FOUND (the CIM Instance does not exist -- only valid
if modify_existing is True, 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
def cim_method_invoke(self, env, object_name):
"""Implements LMI_YumFileCheck.Invoke()
The Invoke method evaluates this Check. The details of the
evaluation are described by the specific subclasses of CIM_Check.
When the SoftwareElement being checked is already installed, the
CIM_InstalledSoftwareElement association identifies the
CIM_ComputerSystem in whose context the Invoke is executed. If
this association is not in place, then the InvokeOnSystem method
should be used - since it identifies the TargetSystem as an input
parameter of the method. \nThe results of the Invoke method are
based on the return value. A zero is returned if the condition is
satisfied. A one is returned if the method is not supported. Any
other value indicates the condition is not satisfied.
Keyword arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
object_name -- A pywbem.CIMInstanceName or pywbem.CIMCLassName
specifying the object on which the method Invoke()
should be invoked.
Returns a two-tuple containing the return value (type pywbem.Uint32)
and a list of CIMParameter objects representing the output parameters
Output parameters: none
Possible Errors:
CIM_ERR_ACCESS_DENIED
CIM_ERR_INVALID_PARAMETER (including missing, duplicate,
unrecognized or otherwise incorrect parameters)
CIM_ERR_NOT_FOUND (the target CIM Class or instance does not
exist in the specified namespace)
CIM_ERR_METHOD_NOT_AVAILABLE (the CIM Server is unable to honor
the invocation request)
CIM_ERR_FAILED (some other unspecified error occurred)
"""
logger = env.get_logger()
logger.log_debug('Entering %s.cim_method_invoke()' \
% self.__class__.__name__)
vpkg = YumFileCheck.object_path2yumcheck(env, object_name)
fc = YumFileCheck.test_file(env,
YumFileCheck.checksumtype_str2pywbem(
vpkg.po.yumdb_info.checksum_type),
vpkg._files[object_name["Name"]])
out_params = []
ret = 0 if YumFileCheck.filecheck_passed(fc) else 2
return (pywbem.Uint32(ret), out_params)
def cim_method_invokeonsystem(self, env, object_name,
param_targetsystem=None):
"""Implements LMI_YumFileCheck.InvokeOnSystem()
The InvokeOnSystem method evaluates this Check. The details of the
evaluation are described by the specific subclasses of CIM_Check.
The method\'s TargetSystem input parameter specifies the
ComputerSystem in whose context the method is invoked. \nThe
results of the InvokeOnSystem method are based on the return
value. A zero is returned if the condition is satisfied. A one is
returned if the method is not supported. Any other value indicates
the condition is not satisfied.
Keyword arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
object_name -- A pywbem.CIMInstanceName or pywbem.CIMCLassName
specifying the object on which the method InvokeOnSystem()
should be invoked.
param_targetsystem -- The input parameter TargetSystem (type REF (pywbem.CIMInstanceName(classname='CIM_ComputerSystem', ...))
Reference to ComputerSystem in whose context the method is to
be invoked.
Returns a two-tuple containing the return value (type pywbem.Uint32)
and a list of CIMParameter objects representing the output parameters
Output parameters: none
Possible Errors:
CIM_ERR_ACCESS_DENIED
CIM_ERR_INVALID_PARAMETER (including missing, duplicate,
unrecognized or otherwise incorrect parameters)
CIM_ERR_NOT_FOUND (the target CIM Class or instance does not
exist in the specified namespace)
CIM_ERR_METHOD_NOT_AVAILABLE (the CIM Server is unable to honor
the invocation request)
CIM_ERR_FAILED (some other unspecified error occurred)
"""
logger = env.get_logger()
logger.log_debug('Entering %s.cim_method_invokeonsystem()' \
% self.__class__.__name__)
# TODO do something
raise pywbem.CIMError(pywbem.CIM_ERR_METHOD_NOT_AVAILABLE) # Remove to implemented
out_params = []
#rval = # TODO (type pywbem.Uint32)
return (rval, out_params)
class Values(object):
class TargetOperatingSystem(object):
Unknown = pywbem.Uint16(0)
Other = pywbem.Uint16(1)
MACOS = pywbem.Uint16(2)
ATTUNIX = pywbem.Uint16(3)
DGUX = pywbem.Uint16(4)
DECNT = pywbem.Uint16(5)
Tru64_UNIX = pywbem.Uint16(6)
OpenVMS = pywbem.Uint16(7)
HPUX = pywbem.Uint16(8)
AIX = pywbem.Uint16(9)
MVS = pywbem.Uint16(10)
OS400 = pywbem.Uint16(11)
OS_2 = pywbem.Uint16(12)
JavaVM = pywbem.Uint16(13)
MSDOS = pywbem.Uint16(14)
WIN3x = pywbem.Uint16(15)
WIN95 = pywbem.Uint16(16)
WIN98 = pywbem.Uint16(17)
WINNT = pywbem.Uint16(18)
WINCE = pywbem.Uint16(19)
NCR3000 = pywbem.Uint16(20)
NetWare = pywbem.Uint16(21)
OSF = pywbem.Uint16(22)
DC_OS = pywbem.Uint16(23)
Reliant_UNIX = pywbem.Uint16(24)
SCO_UnixWare = pywbem.Uint16(25)
SCO_OpenServer = pywbem.Uint16(26)
Sequent = pywbem.Uint16(27)
IRIX = pywbem.Uint16(28)
Solaris = pywbem.Uint16(29)
SunOS = pywbem.Uint16(30)
U6000 = pywbem.Uint16(31)
ASERIES = pywbem.Uint16(32)
HP_NonStop_OS = pywbem.Uint16(33)
HP_NonStop_OSS = pywbem.Uint16(34)
BS2000 = pywbem.Uint16(35)
LINUX = pywbem.Uint16(36)
Lynx = pywbem.Uint16(37)
XENIX = pywbem.Uint16(38)
VM = pywbem.Uint16(39)
Interactive_UNIX = pywbem.Uint16(40)
BSDUNIX = pywbem.Uint16(41)
FreeBSD = pywbem.Uint16(42)
NetBSD = pywbem.Uint16(43)
GNU_Hurd = pywbem.Uint16(44)
OS9 = pywbem.Uint16(45)
MACH_Kernel = pywbem.Uint16(46)
Inferno = pywbem.Uint16(47)
QNX = pywbem.Uint16(48)
EPOC = pywbem.Uint16(49)
IxWorks = pywbem.Uint16(50)
VxWorks = pywbem.Uint16(51)
MiNT = pywbem.Uint16(52)
BeOS = pywbem.Uint16(53)
HP_MPE = pywbem.Uint16(54)
NextStep = pywbem.Uint16(55)
PalmPilot = pywbem.Uint16(56)
Rhapsody = pywbem.Uint16(57)
Windows_2000 = pywbem.Uint16(58)
Dedicated = pywbem.Uint16(59)
OS_390 = pywbem.Uint16(60)
VSE = pywbem.Uint16(61)
TPF = pywbem.Uint16(62)
Windows__R__Me = pywbem.Uint16(63)
Caldera_Open_UNIX = pywbem.Uint16(64)
OpenBSD = pywbem.Uint16(65)
Not_Applicable = pywbem.Uint16(66)
Windows_XP = pywbem.Uint16(67)
z_OS = pywbem.Uint16(68)
Microsoft_Windows_Server_2003 = pywbem.Uint16(69)
Microsoft_Windows_Server_2003_64_Bit = pywbem.Uint16(70)
Windows_XP_64_Bit = pywbem.Uint16(71)
Windows_XP_Embedded = pywbem.Uint16(72)
Windows_Vista = pywbem.Uint16(73)
Windows_Vista_64_Bit = pywbem.Uint16(74)
Windows_Embedded_for_Point_of_Service = pywbem.Uint16(75)
Microsoft_Windows_Server_2008 = pywbem.Uint16(76)
Microsoft_Windows_Server_2008_64_Bit = pywbem.Uint16(77)
FreeBSD_64_Bit = pywbem.Uint16(78)
RedHat_Enterprise_Linux = pywbem.Uint16(79)
RedHat_Enterprise_Linux_64_Bit = pywbem.Uint16(80)
Solaris_64_Bit = pywbem.Uint16(81)
SUSE = pywbem.Uint16(82)
SUSE_64_Bit = pywbem.Uint16(83)
SLES = pywbem.Uint16(84)
SLES_64_Bit = pywbem.Uint16(85)
Novell_OES = pywbem.Uint16(86)
Novell_Linux_Desktop = pywbem.Uint16(87)
Sun_Java_Desktop_System = pywbem.Uint16(88)
Mandriva = pywbem.Uint16(89)
Mandriva_64_Bit = pywbem.Uint16(90)
TurboLinux = pywbem.Uint16(91)
TurboLinux_64_Bit = pywbem.Uint16(92)
Ubuntu = pywbem.Uint16(93)
Ubuntu_64_Bit = pywbem.Uint16(94)
Debian = pywbem.Uint16(95)
Debian_64_Bit = pywbem.Uint16(96)
Linux_2_4_x = pywbem.Uint16(97)
Linux_2_4_x_64_Bit = pywbem.Uint16(98)
Linux_2_6_x = pywbem.Uint16(99)
Linux_2_6_x_64_Bit = pywbem.Uint16(100)
Linux_64_Bit = pywbem.Uint16(101)
Other_64_Bit = pywbem.Uint16(102)
Microsoft_Windows_Server_2008_R2 = pywbem.Uint16(103)
VMware_ESXi = pywbem.Uint16(104)
Microsoft_Windows_7 = pywbem.Uint16(105)
CentOS_32_bit = pywbem.Uint16(106)
CentOS_64_bit = pywbem.Uint16(107)
Oracle_Enterprise_Linux_32_bit = pywbem.Uint16(108)
Oracle_Enterprise_Linux_64_bit = pywbem.Uint16(109)
eComStation_32_bitx = pywbem.Uint16(110)
class SoftwareElementState(object):
Deployable = pywbem.Uint16(0)
Installable = pywbem.Uint16(1)
Executable = pywbem.Uint16(2)
Running = pywbem.Uint16(3)
class FileType(object):
Unknown = pywbem.Uint16(0)
File = pywbem.Uint16(1)
Directory = pywbem.Uint16(2)
Symlink = pywbem.Uint16(3)
FIFO = pywbem.Uint16(4)
Character_Device = pywbem.Uint16(5)
Block_Device = pywbem.Uint16(6)
## end of class LMI_YumFileCheckProvider
## get_providers() for associating CIM Class Name to python provider class name
def get_providers(env):
lmi_yumfilecheck_prov = LMI_YumFileCheck(env)
return {'LMI_YumFileCheck': lmi_yumfilecheck_prov}
|