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
|
# -*- encoding: utf-8 -*-
# Software Management Providers
#
# Copyright (C) 2012-2013 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/>.
"""
Just a common functionality related to associated class CIM_ComputerSystem.
"""
import pywbem
from lmi.common import cmpi_logging
from lmi.software import util
def get_path(prefix=None):
"""
@return object path of CIM_ComputerSystem
"""
if prefix is None:
classname = util.Configuration.get_instance().system_class_name
else:
classname = '%s_ComputerSystem' % prefix
op = util.new_instance_name(classname,
CreationClassName=classname,
Name=util.Configuration.get_instance().system_name)
return op
@cmpi_logging.trace_function
def check_path(env, system, prop_name):
"""
Checks instance name of ComputerSystem.
@param system instance name
@param prop_name name of object path
"""
if not isinstance(system, pywbem.CIMInstanceName):
raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
"\"%s\" must be a CIMInstanceName" % prop_name)
our_system = get_path(prefix='CIM')
ch = env.get_cimom_handle()
if system.namespace != our_system.namespace:
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
'Namespace of "%s" does not match "%s"' % (
prop_name, our_system.namespace))
if not ch.is_subclass(our_system.namespace,
sub=system.classname,
super=our_system.classname):
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
"Class of \"%s\" must be a sublass of %s" % (
prop_name, our_system.classname))
if not 'CreationClassName' in system or not 'Name' in system:
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
"\"%s\" is missing one of keys", prop_name)
if not ch.is_subclass(our_system.namespace,
sub=system['CreationClassName'],
super=our_system.classname):
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
"CreationClassName of \"%s\" must be a sublass of %s" % (
prop_name, our_system.classname))
if system['Name'] != our_system['Name']:
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
"Name of \"%s\" does not match \"%s\"" %
prop_name, our_system['Name'])
return True
@cmpi_logging.trace_function
def check_path_property(env, op, prop_name):
"""
Checks, whether object path contains correct instance name of
CIM_ComputerSystem corresponding to this system.
If not, an exception is raised.
"""
if not prop_name in op:
raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
"Missing %s key property!" % prop_name)
return check_path(env, op[prop_name], prop_name)
|