summaryrefslogtreecommitdiffstats
path: root/src/software/openlmi/software/core/ComputerSystem.py
blob: 90699a039fedb6139cf1b0be7a13269c6871b545 (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
# -*- encoding: utf-8 -*-
# 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/>.

"""
Just a common functionality related to associated class Linux_ComputerSystem.
"""

import pywbem
import socket

def get_path(prefix='Linux'):
    """
    @return object path of Linux_ComputerSystem
    """
    op = pywbem.CIMInstanceName(
            classname='%s_ComputerSystem' % prefix,
            namespace="root/cimv2")
    op["CreationClassName"] = "Linux_ComputerSystem"
    op["Name"] = socket.gethostname()
    return op

def check_path_property(env, op, prop_name):
    """
    Checks, whether object path contains correct instance name of
    Linux_ComputerSystem corresponding to this system.
    If not, an exception is raised.
    """
    system = op[prop_name]
    if not isinstance(system, pywbem.CIMInstanceName):
        raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
                "\"%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