diff --git a/cli/lmi/shell/LMIMethod.py b/cli/lmi/shell/LMIMethod.py index a658e8c..f6ea0d 100644 --- a/cli/lmi/shell/LMIMethod.py +++ b/cli/lmi/shell/LMIMethod.py @@ -41,7 +41,7 @@ from LMIJob import JOB_FINISH_EARLY from LMIUtil import LMIPassByRef from LMIUtil import lmi_raise_or_dump_exception -from LMIUtil import lmi_cast_to_cim +from LMIUtil import lmi_transform_to_cim_param from LMIUtil import lmi_transform_to_lmi from LMIExceptions import LMIIndicationListenerError @@ -476,12 +476,9 @@ class LMIMethod(LMIWrapperBaseObject): method_args.update(kwargs) for (param, value) in method_args.iteritems(): if param in self._method.parameters: - if isinstance(value, LMIObjectFactory().LMIInstanceName): - value = value.wrapped_object - elif isinstance(value, LMIObjectFactory().LMIInstance): - value = value.wrapped_object.path + # Cast input parameters into acceptable CIM types t = self._method.parameters[param].type - method_args[param] = lmi_cast_to_cim(t, value) + method_args[param] = lmi_transform_to_cim_param(t, value) else: # NOTE: maybe we could check for pywbem type and not to exit prematurely errorstr = "Unknown parameter '%s' supplied for method '%s'" % (param, self._method.name) diff --git a/cli/lmi/shell/LMIUtil.py b/cli/lmi/shell/LMIUtil.py index c117fcab557e8ee65995cebdec1dcceec1b12f2a..69cbf75fdf73d57d3b6e5067edf72100962b6df7 100644 --- a/cli/lmi/shell/LMIUtil.py +++ b/cli/lmi/shell/LMIUtil.py @@ -276,6 +276,32 @@ def lmi_transform_to_lmi(conn, value): return tuple(map(lambda val: lmi_transform_to_lmi(conn, val), value)) return value +def lmi_transform_to_cim_param(t, value): + """ + Helper function for method calls, which transforms input object into + :py:class:`CIMInstanceName` object. Members if lists, dictionaries and tuples are + transformed as well. The function does not cast numeric types. + + :param string t: string of CIM type + :param value: object to be transformed to :py:mod:`pywbem` type. + :returns: transformed LMIShell's object into :py:mod:`pywbem` one + """ + if isinstance(value, LMIObjectFactory().LMIInstance): + return value.wrapped_object.path + elif isinstance(value, LMIObjectFactory().LMIInstanceName): + return value.wrapped_object + elif isinstance(value, (int, float)): + return lmi_cast_to_cim(t, value) + elif isinstance(value, (dict, pywbem.NocaseDict)): + return pywbem.NocaseDict({ + k: lmi_transform_to_cim_param(t, val) + for k, val in value.iteritems()}) + elif isinstance(value, list): + return map(lambda val: lmi_transform_to_cim_param(t, val), value) + elif isinstance(value, tuple): + return tuple(map(lambda val: lmi_transform_to_cim_param(t, val), value)) + return value + def lmi_isinstance(lmi_obj, lmi_class): """ Function returns True if :samp:`lmi_obj` is an instance of a :samp:`lmi_class`, False