summaryrefslogtreecommitdiffstats
path: root/src/software/lmi/software/core/ComputerSystem.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/software/lmi/software/core/ComputerSystem.py')
-rw-r--r--src/software/lmi/software/core/ComputerSystem.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/software/lmi/software/core/ComputerSystem.py b/src/software/lmi/software/core/ComputerSystem.py
new file mode 100644
index 0000000..53c0738
--- /dev/null
+++ b/src/software/lmi/software/core/ComputerSystem.py
@@ -0,0 +1,87 @@
+# -*- 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 Linux_ComputerSystem.
+"""
+
+import pywbem
+import socket
+
+from lmi.common import cmpi_logging
+
+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
+
+@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
+ Linux_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)
+