diff options
Diffstat (limited to 'src/software/openlmi/software/core/MethodResult.py')
-rw-r--r-- | src/software/openlmi/software/core/MethodResult.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/software/openlmi/software/core/MethodResult.py b/src/software/openlmi/software/core/MethodResult.py new file mode 100644 index 0000000..7bfdac5 --- /dev/null +++ b/src/software/openlmi/software/core/MethodResult.py @@ -0,0 +1,84 @@ +# -*- 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 class LMI_SoftwareMethodResult. +""" + +import pywbem + +from openlmi.common import cmpi_logging +from openlmi.software.yumdb import jobs, errors, YumDB + +@cmpi_logging.trace_function +def object_path2jobid(op): + """ + @param op must contain precise InstanceID of job + """ + if not isinstance(op, pywbem.CIMInstanceName): + raise TypeError("op must be a CIMInstanceName") + if not op["InstanceID"].lower().startswith('lmi:softwaremethodresult:'): + raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, + "Missing 'LMI:SoftwareMethodResult:' prefix in InstanceID.") + instid = op['InstanceID'][len('LMI:SoftwareMethodResult:'):] + try: + instid = int(instid) + except ValueError: + raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, + "Failed to parse InstanceID.") + return instid + +@cmpi_logging.trace_function +def object_path2job(op): + """ + @param op must contain precise InstanceID of job + """ + instid = object_path2jobid(op) + try: + return YumDB.get_instance().get_job(instid) + except errors.JobNotFound: + raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, "No such job.") + +@cmpi_logging.trace_function +def job2model(job, keys_only=True, model=None): + """ + This accepts job's id and produces corresponding result model. + """ + if not isinstance(job, jobs.YumJob): + raise TypeError("job must be an instance of YumJob") + if model is None: + model = pywbem.CIMInstanceName("LMI_SoftwareMethodResult", + namespace="root/cimv2") + if not keys_only: + model = pywbem.CIMInstance("LMI_SoftwareMethodResult", path=model) + model['InstanceID'] = "LMI:SoftwareMethodResult:"+str(job.jobid) + if not keys_only: + model.path['InstanceID'] = model['InstanceID'] #pylint: disable=E1103 + model['Caption'] = 'Result of method %s' % job.metadata['method_name'] + model['Description'] = ( + 'Result of asynchronous job number %d created upon invocation' + " of %s's %s method." % (job.jobid, + "LMI_SoftwareInstallationService", + job.metadata['method_name'])) + model['ElementName'] = 'MethodResult-%d' % job.jobid + #model['PostCallIndication'] = \ # TODO + #pywbem.CIMInstance(classname='CIM_InstMethodCall', ...) + #model['PreCallIndication'] = \ # TODO + #pywbem.CIMInstance(classname='CIM_InstMethodCall', ...) + return model + |