summaryrefslogtreecommitdiffstats
path: root/src/software/openlmi/software/core/ComputerSystem.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/software/openlmi/software/core/ComputerSystem.py')
-rw-r--r--src/software/openlmi/software/core/ComputerSystem.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/software/openlmi/software/core/ComputerSystem.py b/src/software/openlmi/software/core/ComputerSystem.py
new file mode 100644
index 0000000..90699a0
--- /dev/null
+++ b/src/software/openlmi/software/core/ComputerSystem.py
@@ -0,0 +1,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
+