[cura-tools] master: fix _LmiClass::first_instance() return value when no instance found (2d446aa)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 2d446aaf0e301ff88a03e2591f3495f76bca4435
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Feb 5 14:40:09 2013 +0100
fix _LmiClass::first_instance() return value when no instance found
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index b0a2fa2..5834d30 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -372,7 +372,7 @@ class _LmiClass(BaseObject):
def first_instance(self, **kwargs):
instance_list = self.instances(**kwargs)
if not instance_list:
- return []
+ return None
return instance_list[0]
def properties(self):
11 years, 3 months
[cura-tools] master: introduce _LmiInstanceMethod::return_type (395f6e9)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 395f6e976bd349863a487b27cb5709a8fb150dd7
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Feb 5 13:46:32 2013 +0100
introduce _LmiInstanceMethod::return_type
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index c3aba45..b0a2fa2 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -536,6 +536,10 @@ class _LmiInstanceMethod(BaseObject):
rparams = rparams,
errorstr = errorstr)
+ @property
+ def return_type(self):
+ return self._method.return_type
+
def tomof(self):
_LmiMofFormatter(self._method.tomof()).fancy_format(self._client.interactive)
11 years, 3 months
[cura-tools] master: introduce _LmiInstanceMethod::parameters(), ::print_parameters() (a85c770)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit a85c7707652aba11a0391449953af9126c70e313
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Feb 5 13:43:00 2013 +0100
introduce _LmiInstanceMethod::parameters(), ::print_parameters()
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index 012fc5b..c3aba45 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -539,6 +539,13 @@ class _LmiInstanceMethod(BaseObject):
def tomof(self):
_LmiMofFormatter(self._method.tomof()).fancy_format(self._client.interactive)
+ def parameters(self):
+ return self._method.parameters
+
+ def print_parameters(self):
+ for (param, value) in self._method.parameters.iteritems():
+ sys.stdout.write("%s %s%s\n" % (value.type, param, "[]" if value.is_array else ""))
+
class _LmiInstance(BaseObject):
def __init__(self, client, lmi_class, cim_instance):
super(self.__class__, self).__init__()
11 years, 3 months
[cura-tools] master: move _LmiInstanceMethod out of _LmiInstance namespace (d67315c)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit d67315cf3452c110ec49aca079641a9af8bb30a9
Author: Peter Hatina <phatina(a)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)
11 years, 3 months