Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
commit dc480bc5786abb9c87bdd422b1d7008c6a8c7279 Author: Peter Hatina phatina@redhat.com Date: Wed Sep 11 10:30:45 2013 +0200
introduce passing arguments to method call by dictionary
cli/lmi/shell/LMIMethod.py | 19 +++++++++++++------ 1 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/cli/lmi/shell/LMIMethod.py b/cli/lmi/shell/LMIMethod.py index 8168ca4..80f422e 100644 --- a/cli/lmi/shell/LMIMethod.py +++ b/cli/lmi/shell/LMIMethod.py @@ -328,10 +328,14 @@ class LMIMethod(LMIWrapperBaseObject): # have a "fresh" one. return self.__return_synchro_method_call(job_inst, False)
- def __call__(self, *args, **kwargs): + def __call__(self, method_args=None, **kwargs): """ Perform a method call.
+ Method arguments are preferrably passed by dictionary (parameter : value). Using + former means of passing arguments, by keyword arguments, to a method call works + too. + If performing a synchronous method call, passing PreferPolling can be used to select which method should be used -- either subscribing to an indication or polling method. Returns LMIReturnValue object with rval set to remote method @@ -345,21 +349,24 @@ class LMIMethod(LMIWrapperBaseObject): LMISynchroMethodCallError
Arguments: - args -- CIMMethod arguments - kwargs -- CIMMethod keyword arguments + method_args -- dictionary containing CIMMethod arguments + kwargs -- CIMMethod keyword arguments (method_args preffered) """ synchro_method_polling = kwargs.pop("PreferPolling", False) - for (param, value) in kwargs.iteritems(): + if method_args is None: + method_args = {} + method_args.update(kwargs) + for (param, value) in method_args.iteritems(): if param in self._method.parameters: t = self._method.parameters[param].type - kwargs[param] = lmi_cast_to_cim(t, value) + method_args[param] = lmi_cast_to_cim(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) lmi_raise_or_dump_exception(LMIUnknownParameterError(errorstr)) return LMIReturnValue(rval=-1, errorstr=errorstr) (rval, call_rparams, call_errorstr) = self._conn._client._call_method_raw(self._lmi_instance, - self._method.name, **kwargs) + self._method.name, **method_args) rval = lmi_transform_to_lmi(self._conn, rval) if call_rparams: call_rparams = lmi_transform_to_lmi(self._conn, call_rparams)
cura-tools-devel@lists.fedorahosted.org