Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
commit d67315cf3452c110ec49aca079641a9af8bb30a9 Author: Peter Hatina phatina@redhat.com Date: Tue Feb 5 13:41:17 2013 +0100
move _LmiInstanceMethod out of _LmiInstance namespace
cli-tools/lmi/lmi_client_shell.py | 190 ++++++++++++++++++------------------ 1 files changed, 95 insertions(+), 95 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index b043a5f..012fc5b 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -442,104 +442,104 @@ def possibly_deleted(fn): errorstr = errorstr) return wrapped
-class _LmiInstance(BaseObject): - class _LmiInstanceMethod(BaseObject): - def __init__(self, client, lmi_instance, method): - super(self.__class__, self).__init__() - self._client = client - self._lmi_instance = lmi_instance - self._method = lmi_instance._lmi_class._cim_class.methods[method] - - def __transform_return_values(self, rparams): - lmi_rparams = pywbem.NocaseDict() - for (key, value) in rparams.iteritems(): - if isinstance(value, pywbem.cim_obj.CIMInstance): - (lmi_class, _, errorstr) = self._client._get_class(value.classname, - value.namespace, LocalOnly = False) - if not lmi_class: - return None - lmi_rparams[key] = _LmiInstance(self._client, lmi_class, value) - elif isinstance(value, pywbem.cim_obj.CIMInstanceName): - lmi_rparams[key] = _LmiInstanceName(self._client, value) - elif isinstance(value, pywbem.CIMInt): - lmi_rparams[key] = int(value) - elif isinstance(value, pywbem.CIMFloat): - lmi_rparams[key] = float(value) - elif type(value) == list: - result = [] - for m in value: - if isinstance(m, pywbem.cim_obj.CIMInstance): - (lmi_class, _, errorstr) = self._client._get_class(m.classname, - m.namespace, LocalOnly = False) - if not lmi_class: - return None - lmi_rparams[key] = _LmiInstance(self._client, lmi_class, m) - elif isinstance(m, pywbem.cim_obj.CIMInstanceName): - result.append(_LmiInstanceName(self._client, m)) - lmi_rparams[key] = result - else: - lmi_rparams[key] = value - return lmi_rparams - - def __call__(self, *args, **kwargs): - cast = { - "sint8" : lambda x: pywbem.Sint8(x), - "uint8" : lambda x: pywbem.Uint8(x), - "sint16" : lambda x: pywbem.Sint16(x), - "uint16" : lambda x: pywbem.Uint16(x), - "sint32" : lambda x: pywbem.Sint32(x), - "uint32" : lambda x: pywbem.Uint32(x), - "sint64" : lambda x: pywbem.Sint64(x), - "uint64" : lambda x: pywbem.Uint64(x), - "reference": lambda x: x._cim_instance.path if isinstance(x, _LmiInstance) else x - } - for (param, value) in kwargs.iteritems(): - if param in self._method.parameters: - t = self._method.parameters[param].type.lower() - if t in cast: - cast_func = cast[t] - kwargs[param] = cast_func(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) - if LmiBaseClient._get_use_exceptions(): - raise LmiUnknownParameterError(errorstr) - return LmiReturnValue(rval = -1, rparams = {}, - errorstr = errorstr, hostname = self._client.hostname, - use_display_hook = True) - (rval, rparams, errorstr) = self._client._call_method_raw(self._lmi_instance, - self._method.name, **kwargs) - if isinstance(rval, pywbem.CIMInt): - rval = int(rval) - elif isinstance(rval, pywbem.CIMFloat): - rval = float(rval) - if rparams: - rparams = self.__transform_return_values(rparams) - if not rparams: - # NOTE: this is wrong! What should we do? - if LmiBaseClient._get_use_exceptions(): - raise LmiMethodCallError("Could not perform CIM -> LMI object transformation") - return LmiReturnValue(rval = rval, rparams = {}, errorstr = errorstr) - (new_inst, _, errorstr) = self._client._get_instance( - self._lmi_instance.path, LocalOnly = False) - if not new_inst: +class _LmiInstanceMethod(BaseObject): + def __init__(self, client, lmi_instance, method): + super(self.__class__, self).__init__() + self._client = client + self._lmi_instance = lmi_instance + self._method = lmi_instance._lmi_class._cim_class.methods[method] + + def __transform_return_values(self, rparams): + lmi_rparams = pywbem.NocaseDict() + for (key, value) in rparams.iteritems(): + if isinstance(value, pywbem.cim_obj.CIMInstance): + (lmi_class, _, errorstr) = self._client._get_class(value.classname, + value.namespace, LocalOnly = False) + if not lmi_class: + return None + lmi_rparams[key] = _LmiInstance(self._client, lmi_class, value) + elif isinstance(value, pywbem.cim_obj.CIMInstanceName): + lmi_rparams[key] = _LmiInstanceName(self._client, value) + elif isinstance(value, pywbem.CIMInt): + lmi_rparams[key] = int(value) + elif isinstance(value, pywbem.CIMFloat): + lmi_rparams[key] = float(value) + elif type(value) == list: + result = [] + for m in value: + if isinstance(m, pywbem.cim_obj.CIMInstance): + (lmi_class, _, errorstr) = self._client._get_class(m.classname, + m.namespace, LocalOnly = False) + if not lmi_class: + return None + lmi_rparams[key] = _LmiInstance(self._client, lmi_class, m) + elif isinstance(m, pywbem.cim_obj.CIMInstanceName): + result.append(_LmiInstanceName(self._client, m)) + lmi_rparams[key] = result + else: + lmi_rparams[key] = value + return lmi_rparams + + def __call__(self, *args, **kwargs): + cast = { + "sint8" : lambda x: pywbem.Sint8(x), + "uint8" : lambda x: pywbem.Uint8(x), + "sint16" : lambda x: pywbem.Sint16(x), + "uint16" : lambda x: pywbem.Uint16(x), + "sint32" : lambda x: pywbem.Sint32(x), + "uint32" : lambda x: pywbem.Uint32(x), + "sint64" : lambda x: pywbem.Sint64(x), + "uint64" : lambda x: pywbem.Uint64(x), + "reference": lambda x: x._cim_instance.path if isinstance(x, _LmiInstance) else x + } + for (param, value) in kwargs.iteritems(): + if param in self._method.parameters: + t = self._method.parameters[param].type.lower() + if t in cast: + cast_func = cast[t] + kwargs[param] = cast_func(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) + if LmiBaseClient._get_use_exceptions(): + raise LmiUnknownParameterError(errorstr) + return LmiReturnValue(rval = -1, rparams = {}, + errorstr = errorstr, hostname = self._client.hostname, + use_display_hook = True) + (rval, rparams, errorstr) = self._client._call_method_raw(self._lmi_instance, + self._method.name, **kwargs) + if isinstance(rval, pywbem.CIMInt): + rval = int(rval) + elif isinstance(rval, pywbem.CIMFloat): + rval = float(rval) + if rparams: + rparams = self.__transform_return_values(rparams) + if not rparams: # NOTE: this is wrong! What should we do? if LmiBaseClient._get_use_exceptions(): - raise LmiMethodCallError("Could not update an LMI object after a method call") + raise LmiMethodCallError("Could not perform CIM -> LMI object transformation") return LmiReturnValue(rval = rval, rparams = {}, errorstr = errorstr) - self._lmi_instance._cim_instance = new_inst - return LmiReturnValue( - hostname = self._client.hostname, - instance = self._lmi_instance, - use_display_hook = True, - rval = rval, - rparams = rparams, - errorstr = errorstr) - - def tomof(self): - _LmiMofFormatter(self._method.tomof()).fancy_format(self._client.interactive) + (new_inst, _, errorstr) = self._client._get_instance( + self._lmi_instance.path, LocalOnly = False) + if not new_inst: + # NOTE: this is wrong! What should we do? + if LmiBaseClient._get_use_exceptions(): + raise LmiMethodCallError("Could not update an LMI object after a method call") + return LmiReturnValue(rval = rval, rparams = {}, errorstr = errorstr) + self._lmi_instance._cim_instance = new_inst + return LmiReturnValue( + hostname = self._client.hostname, + instance = self._lmi_instance, + use_display_hook = True, + rval = rval, + rparams = rparams, + errorstr = errorstr)
+ def tomof(self): + _LmiMofFormatter(self._method.tomof()).fancy_format(self._client.interactive) + +class _LmiInstance(BaseObject): def __init__(self, client, lmi_class, cim_instance): super(self.__class__, self).__init__() # We use __dict__ to avoid recursion potentially caused by @@ -555,7 +555,7 @@ class _LmiInstance(BaseObject): return self.__dict__[name] methods = self.methods() if methods and name in methods: - return _LmiInstance._LmiInstanceMethod(self._client, self, name) + return _LmiInstanceMethod(self._client, self, name) elif name in self._cim_instance: return self._cim_instance[name] raise AttributeError(name)
cura-tools-devel@lists.fedorahosted.org