summaryrefslogtreecommitdiffstats
path: root/src/software/openlmi/software/core/SystemCollection.py
blob: d07ecdd19cf58eb91c3fadc73f20a5a5ff870d6b (plain)
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
# 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/>.

"""
Common utilities concerning SystemSoftwareCollection provider.
"""

import pywbem

from openlmi.common import cmpi_logging

def get_path():
    """@return instance name with prefilled properties"""
    op = pywbem.CIMInstanceName(
            classname="LMI_SystemSoftwareCollection",
            namespace="root/cimv2")
    op['InstanceID'] = "LMI:LMI_SystemSoftwareCollection"
    return op

@cmpi_logging.trace_function
def check_path(env, collection, prop_name):
    """
    Checks instance name of SystemSoftwareCollection.
    @param prop_name name of object name; used for error descriptions
    """
    if not isinstance(collection, pywbem.CIMInstanceName):
        raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
                "\"%s\" must be a CIMInstanceName" % prop_name)
    our_collection = get_path()
    ch = env.get_cimom_handle()
    if collection.namespace != our_collection.namespace:
        raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
                'Namespace of "%s" does not match "%s"' % (
                    prop_name, our_collection.namespace))
    if not ch.is_subclass(our_collection.namespace,
            sub=collection.classname,
            super=our_collection.classname):
        raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
                "Class of \"%s\" must be a sublass of %s" % (
                    prop_name, our_collection.classname))
    if not 'InstanceID' in collection:
        raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
                "\"%s\" is missing InstanceID key property", prop_name)
    if collection['InstanceID'] != our_collection['InstanceID']:
        raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
                "InstanceID of \"%s\" does not match \"%s\"" %
                prop_name, our_collection['InstanceID'])
    return True

@cmpi_logging.trace_function
def check_path_property(env, op, prop_name):
    """
    Checks, whether prop_name property of op object path is correct.
    If not, an exception will be risen.
    """
    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)