summaryrefslogtreecommitdiffstats
path: root/src/software
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2013-02-13 19:51:27 +0100
committerMichal Minar <miminar@redhat.com>2013-02-13 20:02:50 +0100
commit4ce8cb5509f24b950f93acab900bc9af774c7afb (patch)
treeac7a5e14fe70bde2eb2e05ca83fa01e15eaecbb1 /src/software
parent73125fe7a43b560ec230004199ecd60690f9d063 (diff)
downloadopenlmi-providers-4ce8cb5509f24b950f93acab900bc9af774c7afb.tar.gz
openlmi-providers-4ce8cb5509f24b950f93acab900bc9af774c7afb.tar.xz
openlmi-providers-4ce8cb5509f24b950f93acab900bc9af774c7afb.zip
more code shared thanks to path checking partitioning
Diffstat (limited to 'src/software')
-rw-r--r--src/software/openlmi/software/LMI_MemberOfSoftwareCollection.py11
-rw-r--r--src/software/openlmi/software/core/ComputerSystem.py23
-rw-r--r--src/software/openlmi/software/core/SystemSoftwareCollection.py20
3 files changed, 35 insertions, 19 deletions
diff --git a/src/software/openlmi/software/LMI_MemberOfSoftwareCollection.py b/src/software/openlmi/software/LMI_MemberOfSoftwareCollection.py
index ae79bf7..6fa6ea4 100644
--- a/src/software/openlmi/software/LMI_MemberOfSoftwareCollection.py
+++ b/src/software/openlmi/software/LMI_MemberOfSoftwareCollection.py
@@ -240,10 +240,10 @@ class LMI_MemberOfSoftwareCollection(CIMProvider2):
if ( (not role or role.lower() == 'collection')
and cimhandle.is_subclass(object_name.namespace,
sub=object_name.classname,
- super='LMI_SystemSoftwareCollection')
- and "InstanceID" in object_name):
- if object_name["InstanceID"] == \
- SystemSoftwareCollection.get_path()["InstanceID"]:
+ super='LMI_SystemSoftwareCollection')):
+ try:
+ SystemSoftwareCollection.check_path(env, object_name,
+ "collection")
pkg_model = pywbem.CIMInstanceName(
classname='LMI_SoftwareIdentity',
namespace="root/cimv2",
@@ -254,6 +254,9 @@ class LMI_MemberOfSoftwareCollection(CIMProvider2):
model["Member"] = SoftwareIdentity.pkg2model(
pkg_info, model=pkg_model)
yield model
+ except pywbem.CIMError as exc:
+ if exc.args[0] != pywbem.CIM_ERR_NOT_FOUND:
+ raise
if ( (not role or role.lower() == 'member')
and cimhandle.is_subclass(object_name.namespace,
diff --git a/src/software/openlmi/software/core/ComputerSystem.py b/src/software/openlmi/software/core/ComputerSystem.py
index 4f99ee3..fcb89c6 100644
--- a/src/software/openlmi/software/core/ComputerSystem.py
+++ b/src/software/openlmi/software/core/ComputerSystem.py
@@ -34,16 +34,12 @@ def get_path(prefix='Linux'):
op["Name"] = socket.gethostname()
return op
-def check_path_property(env, op, prop_name):
+def check_path(env, system, prop_name):
"""
- Checks, whether object path contains correct instance name of
- Linux_ComputerSystem corresponding to this system.
- If not, an exception is raised.
+ Checks instance name of ComputerSystem.
+ @param system instance name
+ @param prop_name name of object path
"""
- if not prop_name in op:
- raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
- "Missing %s key property!" % prop_name)
- system = op[prop_name]
if not isinstance(system, pywbem.CIMInstanceName):
raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
"\"%s\" must be a CIMInstanceName" % prop_name)
@@ -74,3 +70,14 @@ def check_path_property(env, op, prop_name):
prop_name, our_system['Name'])
return True
+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)
+
diff --git a/src/software/openlmi/software/core/SystemSoftwareCollection.py b/src/software/openlmi/software/core/SystemSoftwareCollection.py
index b7a320b..0f59f3b 100644
--- a/src/software/openlmi/software/core/SystemSoftwareCollection.py
+++ b/src/software/openlmi/software/core/SystemSoftwareCollection.py
@@ -29,15 +29,11 @@ def get_path():
op['InstanceID'] = "LMI:SystemSoftwareCollection"
return op
-def check_path_property(env, op, prop_name):
+def check_path(env, collection, prop_name):
"""
- Checks, whether prop_name property of op object path is correct.
- If not, an exception will be risen.
+ Checks instance name of SystemSoftwareCollection.
+ @param prop_name name of object name; used for error descriptions
"""
- if not prop_name in op:
- raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
- "Missing %s key property!" % prop_name)
- collection = op[prop_name]
if not isinstance(collection, pywbem.CIMInstanceName):
raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
"\"%s\" must be a CIMInstanceName" % prop_name)
@@ -61,3 +57,13 @@ def check_path_property(env, op, prop_name):
"InstanceID of \"%s\" does not match \"%s\"" %
prop_name, our_collection['InstanceID'])
return True
+
+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)