[cura-tools] master: replace wrong check in _LmiInstance::push() with lmi_return_val_if_fail decorator (2be055d)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 2be055dbbac25124193066d5896eceff50144b48
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Jul 19 12:22:40 2013 +0200
replace wrong check in _LmiInstance::push() with lmi_return_val_if_fail decorator
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 23 ++++++++++++-----------
1 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index cff35f2..a611d11 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -2456,6 +2456,14 @@ class _LmiInstance(BaseObject):
rval = False, \
errorstr = "This instance has been deleted from a CIM broker") \
)
+ @lmi_return_val_if_fail(lambda obj: obj._cim_instance.path, \
+ LmiReturnValue( \
+ rval = False, \
+ errorstr = "Can't push this instance", \
+ use_display_hook = True, \
+ hostname = lambda obj: obj._client.hostname \
+ ) \
+ )
def push(self):
"""
Pushes the modified object to the CIMOM. Returns LmiReturnValue with rval set to
@@ -2465,21 +2473,14 @@ class _LmiInstance(BaseObject):
Note: If the method _LmiInstance.delete() was called, this method will not execute
its code and will return LmiReturnValue containing None as a return value.
"""
- if not self._lmi_class._namespace:
- return LmiReturnValue(
- hostname = self._client.hostname,
- use_display_hook = True,
- rval = False,
- errorstr = "Can't push this instance"
- )
- return_value = self._client._modify_instance(self._cim_instance)
+ (rval, rparams, errorstr) = self._client._modify_instance(self._cim_instance)
return LmiReturnValue(
hostname = self._client.hostname,
instance = self._cim_instance,
use_display_hook = True,
- rval = return_value.rval,
- rparams = return_value.rparams,
- errorstr = return_value.errorstr)
+ rval = rval,
+ rparams = rparams,
+ errorstr = errorstr)
@lmi_possibly_deleted(None)
@lmi_return_if_fail(lambda obj: obj._lmi_class._namespace)
10 years, 10 months
[cura-tools] master: lmi decorators, code cleanup (d69f4aa)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit d69f4aa4fda9f39021fad4940bf3b1d1f6e1a50e
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Jul 19 12:04:19 2013 +0200
lmi decorators, code cleanup
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 277 ++++++++++++++++++++++++-------------
1 files changed, 183 insertions(+), 94 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index 84fa854..cff35f2 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -624,17 +624,26 @@ class _LmiSubscription(BaseObject):
if self._cim_handler_tpl[1]:
self._client._delete_instance(self._cim_handler_tpl[0].path)
-class lmi_return_val_if_fail(object):
+class lmi_return_expr_if_fail(object):
"""
- Decorator, which returns a specified value, if a object member is of expression False.
+ Decorator, which calls a specified expression and returns its return value instead of
+ calling the decorated method, if provided test expression is False; otherwise a method
+ is called.
Example of usage:
class Foo:
def __init__(self, member):
self._member = member
- @lmi_return_val_if_fail("_member", False)
+ def failed(self):
+ print "expression failed"
+ return False
+
+ # NOTE: the self parameter to the method call needs to be passed via expr_ret_args,
+ # therefore, there is a dummy lambda obj: obj, which is basically self variable.
+ @lmi_return_expr_if_fail(lambda obj: obj._member, failed, lambda obj: obj)
def some_method(self):
+ print "some_method called"
return True
f = Foo(None)
@@ -643,19 +652,21 @@ class lmi_return_val_if_fail(object):
f = Foo(True)
f.some_method() == True
"""
- def __init__(self, attr, rval):
+ def __init__(self, expr_test, expr_ret, *expr_ret_args, **expr_ret_kwargs):
"""
- Constructs a lmi_return_val_if_fail decorator object.
+ Constructs a lmi_return_expr_if_fail decorator object.
Arguments:
- attr -- the object attribute, which will be tested before the call to be
- of expression True
- rval -- return value of the method, if the object attribute as expression
- failed
+ expr_test -- expression which determines, if to execute a return
+ value expression
+ expr_ret -- expression, which is called, if the expr_test returns False
+ expr_ret_args -- expr_ret position arguments
+ expr_ret_kwargs -- expr_ret keyword arguments
"""
- self._attr = attr
- self._rval = rval
- self._ret = True
+ self._expr_test = expr_test
+ self._expr_ret = expr_ret
+ self._expr_ret_args = expr_ret_args
+ self._expr_ret_kwargs = expr_ret_kwargs
def __call__(self, fn):
"""
@@ -665,35 +676,128 @@ class lmi_return_val_if_fail(object):
fn -- decorated method
"""
def wrapper(self_wr, *args, **kwargs):
- attrs = self._attr.split(".")
- obj = self_wr
- for a in attrs:
- try:
- obj = getattr(obj, a)
- except AttributeError, e:
- obj = None
- if not obj:
- if self._ret:
- return self._rval
- else:
- return
+ failed = False
+ try:
+ if not self._expr_test(self_wr):
+ failed = True
+ except AttributeError, e:
+ failed = True
+ if failed:
+ return self._expr_ret(*self._expr_ret_args, **self._expr_ret_kwargs)
return fn(self_wr, *args, **kwargs)
return wrapper
+class lmi_return_val_if_fail(lmi_return_expr_if_fail):
+ """
+ Decorator, which returns a specified value and no method call is performed, if
+ provided test expression is False; otherwise a method is called.
+
+ Example of usage:
+ class Foo:
+ def __init__(self, member):
+ self._member = member
+
+ @lmi_return_val_if_fail(lambda obj: obj._member, False)
+ def some_method(self):
+ print "some_method called"
+ return True
+
+ f = Foo(None)
+ f.some_method() == False
+
+ f = Foo(True)
+ f.some_method() == True
+ """
+ def __init__(self, expr_test, rval):
+ """
+ Constructs a lmi_return_val_if_fail object.
+
+ Arguments:
+ expr_test -- if the expression returns False, a method call is called
+ rval -- return value of the method, if the object attribute as expression
+ failed
+ """
+ lmi_return_expr_if_fail.__init__(self, expr_test, lambda: rval)
+
class lmi_return_if_fail(lmi_return_val_if_fail):
"""
- Decorator, which returns, if a object member is False.
+ Decorator, which returns None and no method call is performed, if provided test
+ expression is False; otherwise a method is called.
+
+ Example of usage:
+ class Foo:
+ def __init__(self, member):
+ self._member = member
+
+ @lmi_return_if_fail(lambda obj: obj._member)
+ def some_method(self):
+ print "some_method called"
+ return True
+
+ f = Foo(None)
+ f.some_method() == None
+
+ f = Foo(True)
+ f.some_method() == True
"""
- def __init__(self, attr):
+ def __init__(self, expr_test):
"""
Constructs a lmi_return_if_fail decorator object.
Arguments:
- attr -- the object attribute, which will be tested before the call to be
- of expression True
+ expr_test -- if the expression returns True, a method call is called
"""
- super(self.__class__, self).__init__(attr, None)
- self._ret = False
+ lmi_return_val_if_fail.__init__(self, expr_test, None)
+
+class lmi_possibly_deleted(lmi_return_val_if_fail):
+ """
+ Decorator, which returns None, if provided test expression is True.
+
+ Example of usage:
+ class Foo:
+ def __init__(self, deleted):
+ self._deleted = deleted
+
+ @lmi_possibly_deleted(lambda obj: obj._member, lambda: False)
+ def some_method(self):
+ print "some_method called"
+ return True
+
+ f = Foo(None)
+ f.some_method() == False
+
+ f = Foo(True)
+ f.some_method() == True
+ """
+ def __init__(self, rval):
+ """
+ Constructs a lmi_possibly_deleted object."
+
+ Arguments:
+ rval -- return value, if expr_test fails
+ """
+ lmi_return_val_if_fail.__init__(self, lambda obj: obj._deleted, rval)
+
+ def __call__(self, fn):
+ """
+ Executes a method call, if the test passed. If the test expression
+ returns False, specified return value in the constructor is returned.
+ If the shell does not dump exceptions, an appropriate exception is raised.
+
+ Raised exceptions:
+ LmiDeletedObjectError
+
+ Arguments:
+ fn -- decorated method
+ """
+ def wrapper(self_wr, *args, **kwargs):
+ if self._expr_test(self_wr):
+ errorstr = "This instance has been deleted from a CIM broker"
+ if LmiBaseClient._get_use_exceptions():
+ raise LmiDeletedObjectError(errorstr)
+ return self._expr_ret()
+ return fn(self_wr, *args, **kwargs)
+ return wrapper
class _LmiNamespace(BaseObject):
"""
@@ -1044,7 +1148,7 @@ class _LmiClass(BaseObject):
raise AttributeError(name)
@lmi_class_fetch_lazy
- @lmi_return_val_if_fail("_namespace", None)
+ @lmi_return_val_if_fail(lambda obj: obj._namespace, None)
def create_instance(self, properties = None, qualifiers = None, property_list = None):
"""
Creates a new CIMInstance at the server side and returns LmiReturn value
@@ -1074,7 +1178,7 @@ class _LmiClass(BaseObject):
return _LmiInstance(self._client, self, cim_instance)
@lmi_class_fetch_lazy
- @lmi_return_if_fail("_namespace")
+ @lmi_return_if_fail(lambda obj: obj._namespace)
def doc(self):
"""
Prints out pretty verbose message with documentation for the class. If the shell
@@ -1100,7 +1204,7 @@ class _LmiClass(BaseObject):
# NOTE: usage with Key=something, Value=something is deprecated
# NOTE: inst_filter is either None or dict
- @lmi_return_val_if_fail("_namespace", [])
+ @lmi_return_val_if_fail(lambda obj: obj._namespace, [])
def instance_names(self, inst_filter = None, **kwargs):
"""
Returns a LmiReturnValue containing a list of _LmiInstanceNames.
@@ -1156,7 +1260,7 @@ class _LmiClass(BaseObject):
# NOTE: usage with Key=something, Value=something is deprecated
# NOTE: inst_filter is either None or dict
- @lmi_return_val_if_fail("_namespace", [])
+ @lmi_return_val_if_fail(lambda obj: obj._namespace, [])
def instances(self, inst_filter = None, **kwargs):
"""
Returns a list of objects of _LmiInstance.
@@ -1202,7 +1306,7 @@ class _LmiClass(BaseObject):
return result
@lmi_class_fetch_lazy
- @lmi_return_val_if_fail("_namespace", [])
+ @lmi_return_val_if_fail(lambda obj: obj._namespace, [])
def valuemap_properties(self):
"""
Returns a list of strings of the constant names.
@@ -1210,7 +1314,7 @@ class _LmiClass(BaseObject):
return self._valuemap_properties_list
@lmi_class_fetch_lazy
- @lmi_return_val_if_fail("_namespace", [])
+ @lmi_return_val_if_fail(lambda obj: obj._namespace, [])
def properties(self):
"""
Returns a list of strings of the CIMClass properties.
@@ -1218,7 +1322,7 @@ class _LmiClass(BaseObject):
return self._cim_class.properties.keys()
@lmi_class_fetch_lazy
- @lmi_return_if_fail("_namespace")
+ @lmi_return_if_fail(lambda obj: obj._namespace)
def print_properties(self):
"""
Prints out the list of CIMClass properties.
@@ -1227,7 +1331,7 @@ class _LmiClass(BaseObject):
sys.stdout.write("%s\n" % prop)
@lmi_class_fetch_lazy
- @lmi_return_val_if_fail("_namespace", [])
+ @lmi_return_val_if_fail(lambda obj: obj._namespace, [])
def methods(self):
"""
Returns a list of strings of CIMClass methods.
@@ -1235,7 +1339,7 @@ class _LmiClass(BaseObject):
return self._cim_class.methods.keys()
@lmi_class_fetch_lazy
- @lmi_return_if_fail("_namespace")
+ @lmi_return_if_fail(lambda obj: obj._namespace)
def print_methods(self):
"""
Prints out the list of CIMClass methods.
@@ -1251,7 +1355,7 @@ class _LmiClass(BaseObject):
return self._cim_classname
@property
- @lmi_return_val_if_fail("_namespace", "Unknown")
+ @lmi_return_val_if_fail(lambda obj: obj._namespace, "Unknown")
def namespace(self):
"""
Property returning a string of the namespace name.
@@ -1353,29 +1457,6 @@ class _LmiInstanceName(BaseObject):
"""
return self._cim_instance_name
-def possibly_deleted(fn):
- """
- Decorator, which disables a method call, if a CIMInstance was deleted from
- the server side. The decorator is applied, when a _LmiInstance.delete() was
- issued.
-
- Arguments:
- fn -- wrapped method
- """
- def wrapped(self, *args, **kwargs):
- if not self._deleted:
- return fn(self, *args, **kwargs)
- errorstr = "This instance has been deleted from a CIM broker"
- if LmiBaseClient._get_use_exceptions():
- raise LmiDeletedObjectError(errorstr)
- return LmiReturnValue(
- hostname = self._client.hostname,
- instance = self,
- use_display_hook = True,
- rval = None,
- errorstr = errorstr)
- return wrapped
-
class _LmiInstanceMethod(BaseObject):
"""
LMI wrapper class representing CIMMethod.
@@ -1844,7 +1925,7 @@ class _LmiInstance(BaseObject):
self.__dict__["_client"] = client
self.__dict__["_lmi_class"] = lmi_class
- @possibly_deleted
+ @lmi_possibly_deleted(None)
def __getattr__(self, name):
"""
Returns either a class member, _LmiInstanceMethod object, or a CIMInstance object
@@ -1872,7 +1953,7 @@ class _LmiInstance(BaseObject):
return member
raise AttributeError(name)
- @possibly_deleted
+ @lmi_possibly_deleted(None)
def __setattr__(self, name, value):
"""
Modifies a CIMInstance property.
@@ -1890,7 +1971,7 @@ class _LmiInstance(BaseObject):
else:
self.__dict__[name] = value
- @possibly_deleted
+ @lmi_possibly_deleted("")
def __repr__(self):
"""
Returns a pretty string for the object.
@@ -1901,7 +1982,7 @@ class _LmiInstance(BaseObject):
return "%s(classname='%s', ...)" % (self.__class__.__name__, self.classname)
@property
- @possibly_deleted
+ @lmi_possibly_deleted("")
def classname(self):
"""
Property returning a string of a class name.
@@ -1912,7 +1993,7 @@ class _LmiInstance(BaseObject):
return self._lmi_class.classname
@property
- @possibly_deleted
+ @lmi_possibly_deleted("")
def namespace(self):
"""
Property retuning a string of a namespace name.
@@ -1923,7 +2004,7 @@ class _LmiInstance(BaseObject):
return self._lmi_class.namespace
@property
- @possibly_deleted
+ @lmi_possibly_deleted(None)
def path(self):
"""
Property returning a string of a CIMInstance path.
@@ -1933,8 +2014,8 @@ class _LmiInstance(BaseObject):
"""
return self._cim_instance.path
- @possibly_deleted
- @lmi_return_if_fail("_cim_instance.path")
+ @lmi_possibly_deleted(None)
+ @lmi_return_if_fail(lambda obj: obj._cim_instance.path)
def doc(self):
"""
Prints out pretty verbose message with documentation for the instance. If the shell
@@ -1947,7 +2028,7 @@ class _LmiInstance(BaseObject):
"""
_LmiXmlFormatter(self._cim_instance.tocimxml()).fancy_format(self._client.interactive)
- @possibly_deleted
+ @lmi_possibly_deleted(None)
def tomof(self):
"""
Prints out a message with MOF representation of CIMMethod. If the shell
@@ -1960,7 +2041,11 @@ class _LmiInstance(BaseObject):
"""
_LmiMofFormatter(self._cim_instance.tomof()).fancy_format(self._client.interactive)
- @possibly_deleted
+ @lmi_possibly_deleted( \
+ LmiReturnValue( \
+ rval = False, \
+ errorstr = "This instance has been deleted from a CIM broker") \
+ )
def refresh(self):
"""
Retreives a new CIMInstance object. Basically refreshes the object properties.
@@ -1976,8 +2061,8 @@ class _LmiInstance(BaseObject):
self._cim_instance = new_cim_instance
return LmiReturnValue(rval = True)
- @possibly_deleted
- @lmi_return_val_if_fail("_cim_instance.path", [])
+ @lmi_possibly_deleted([])
+ @lmi_return_val_if_fail(lambda obj: obj._cim_instance.path, [])
def associator_names(self, AssocClass = None, ResultClass = None, Role = None,\
ResultRole = None):
"""
@@ -2024,7 +2109,7 @@ class _LmiInstance(BaseObject):
result.append(_LmiInstanceName(self._client, i))
return result
- @possibly_deleted
+ @lmi_possibly_deleted(None)
def first_associator_name(self, AssocClass = None, ResultClass = None, Role = None,
ResultRole = None):
"""
@@ -2061,8 +2146,8 @@ class _LmiInstance(BaseObject):
return None
return result[0]
- @possibly_deleted
- @lmi_return_val_if_fail("_cim_instance.path", [])
+ @lmi_possibly_deleted([])
+ @lmi_return_val_if_fail(lambda obj: obj._cim_instance.path, [])
def associators(self, AssocClass = None, ResultClass = None, Role = None,\
ResultRole = None, Props = None):
"""
@@ -2125,7 +2210,7 @@ class _LmiInstance(BaseObject):
result.append(lmi_assoc_inst)
return result
- @possibly_deleted
+ @lmi_possibly_deleted(None)
def first_associator(self, AssocClass = None, ResultClass = None, Role = None, \
ResultRole = None, Props = None):
"""
@@ -2174,8 +2259,8 @@ class _LmiInstance(BaseObject):
return None
return result[0]
- @possibly_deleted
- @lmi_return_val_if_fail("_cim_instance.path", [])
+ @lmi_possibly_deleted([])
+ @lmi_return_val_if_fail(lambda obj: obj._cim_instance.path, [])
def reference_names(self, ResultClass = None, Role = None):
"""
Returns a list of association _LmiInstanceName objects with this object.
@@ -2205,7 +2290,7 @@ class _LmiInstance(BaseObject):
result.append(_LmiInstanceName(self._client, i))
return result
- @possibly_deleted
+ @lmi_possibly_deleted(None)
def first_reference_name(self, ResultClass = None, Role = None):
"""
Returns the first association _LmiInstanceName with this object.
@@ -2228,8 +2313,8 @@ class _LmiInstance(BaseObject):
return None
return result[0]
- @possibly_deleted
- @lmi_return_val_if_fail("_cim_instance.path", [])
+ @lmi_possibly_deleted([])
+ @lmi_return_val_if_fail(lambda obj: obj._cim_instance.path, [])
def references(self, ResultClass = None, Role = None, Props = None):
"""
Returns a list of association _LmiInstance objects with this object.
@@ -2274,7 +2359,7 @@ class _LmiInstance(BaseObject):
result.append(lmi_references_inst)
return result
- @possibly_deleted
+ @lmi_possibly_deleted(None)
def first_reference(self, ResultClass = None, Role = None, Props = None):
"""
Returns the first association _LmiInstance with this object.
@@ -2300,7 +2385,7 @@ class _LmiInstance(BaseObject):
return None
return result[0]
- @possibly_deleted
+ @lmi_possibly_deleted([])
def properties(self):
"""
Returns a list of CIMInstance properties.
@@ -2310,7 +2395,7 @@ class _LmiInstance(BaseObject):
"""
return self._cim_instance.properties.keys()
- @possibly_deleted
+ @lmi_possibly_deleted(None)
def print_properties(self):
"""
Prints out the list of CIMInstance properties.
@@ -2321,7 +2406,7 @@ class _LmiInstance(BaseObject):
for (name, prop) in self._cim_instance.properties.iteritems():
sys.stdout.write("%s\n" % name)
- @possibly_deleted
+ @lmi_possibly_deleted({})
def properties_dict(self):
"""
Returns dictionary containing property name and value pairs.
@@ -2333,7 +2418,7 @@ class _LmiInstance(BaseObject):
return dict(zip(self._cim_instance.properties.keys(),
map(lambda x: x.value, self._cim_instance.properties.values())))
- @possibly_deleted
+ @lmi_possibly_deleted(None)
def property_value(self, prop_name):
"""
Returns a CIMInstance property value.
@@ -2346,7 +2431,7 @@ class _LmiInstance(BaseObject):
"""
return getattr(self, prop_name)
- @possibly_deleted
+ @lmi_possibly_deleted([])
def methods(self):
"""
Returns a list of CIMInstance methods' names.
@@ -2356,7 +2441,7 @@ class _LmiInstance(BaseObject):
"""
return self._lmi_class.methods()
- @possibly_deleted
+ @lmi_possibly_deleted(None)
def print_methods(self):
"""
Prints out the list of CIMInstance methods' names.
@@ -2366,7 +2451,11 @@ class _LmiInstance(BaseObject):
"""
self._lmi_class.print_methods()
- @possibly_deleted
+ @lmi_possibly_deleted( \
+ LmiReturnValue( \
+ rval = False, \
+ errorstr = "This instance has been deleted from a CIM broker") \
+ )
def push(self):
"""
Pushes the modified object to the CIMOM. Returns LmiReturnValue with rval set to
@@ -2392,8 +2481,8 @@ class _LmiInstance(BaseObject):
rparams = return_value.rparams,
errorstr = return_value.errorstr)
- @possibly_deleted
- @lmi_return_if_fail("_lmi_class._namespace")
+ @lmi_possibly_deleted(None)
+ @lmi_return_if_fail(lambda obj: obj._lmi_class._namespace)
def delete(self):
"""
Deletes this instance from the CIMOM.
10 years, 10 months
[cura-tools] master: switch to keyword arguments in _LmiInstance::*associator*(), ::*reference*() (c396b13)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit c396b136499c907095dc8f169f154bc503f5631d
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Jul 19 13:17:56 2013 +0200
switch to keyword arguments in _LmiInstance::*associator*(), ::*reference*()
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 119 ++++++++++++------------------------
1 files changed, 40 insertions(+), 79 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index 9735fa7..8b77822 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -2062,15 +2062,14 @@ class _LmiInstance(BaseObject):
@lmi_possibly_deleted([])
@lmi_return_val_if_fail(lambda obj: obj._cim_instance.path, [])
- def associator_names(self, AssocClass = None, ResultClass = None, Role = None,\
- ResultRole = None):
+ def associator_names(self, **kwargs):
"""
Returns a list of associated _LmiInstanceName with this object.
Note: If the method _LmiInstance.delete() was called, this method will not execute
its code and will return LmiReturnValue containing None as a return value.
- Arguments:
+ Keyword Arguments:
AssocClass -- valid CIM association class name. It acts as a filter on the
returned set of names by mandating that each returned name identify an object
that shall be associated to the source object through an instance of this
@@ -2093,31 +2092,20 @@ class _LmiInstance(BaseObject):
value of this parameter.
"""
result = []
- assoc_names_args = {}
- if AssocClass:
- assoc_names_args["AssocClass"] = AssocClass
- if ResultClass:
- assoc_names_args["ResultClass"] = ResultClass
- if Role:
- assoc_names_args["Role"] = Role
- if ResultRole:
- assoc_names_args["ResultRole"] = ResultRole
- assoc_names_list = self._client._get_associator_names(self._cim_instance,
- **assoc_names_args)
+ assoc_names_list = self._client._get_associator_names(self._cim_instance, **kwargs)
for i in assoc_names_list:
result.append(_LmiInstanceName(self._client, i))
return result
@lmi_possibly_deleted(None)
- def first_associator_name(self, AssocClass = None, ResultClass = None, Role = None,
- ResultRole = None):
+ def first_associator_name(self, **kwargs):
"""
Returns the first associated _LmiInstanceName with this object.
Note: If the method _LmiInstance.delete() was called, this method will not execute
its code and will return LmiReturnValue containing None as a return value.
- Arguments:
+ Keyword Arguments:
AssocClass -- valid CIM association class name. It acts as a filter on the
returned set of names by mandating that each returned name identify an object
that shall be associated to the source object through an instance of this
@@ -2139,23 +2127,21 @@ class _LmiInstance(BaseObject):
in the association class that refers to the returned object shall match the
value of this parameter.
"""
- result = self.associator_names(AssocClass = AssocClass, ResultClass = ResultClass,
- Role = Role, ResultRole = ResultRole)
+ result = self.associator_names(**kwargs)
if not result:
return None
return result[0]
@lmi_possibly_deleted([])
@lmi_return_val_if_fail(lambda obj: obj._cim_instance.path, [])
- def associators(self, AssocClass = None, ResultClass = None, Role = None,\
- ResultRole = None, Props = None):
+ def associators(self, **kwargs):
"""
Returns a list of associated _LmiInstance with this object.
Note: If the method _LmiInstance.delete() was called, this method will not execute
its code and will return LmiReturnValue containing None as a return value.
- Arguments:
+ Keyword Arguments:
AssocClass -- valid CIM association class name. It acts as a filter on the
returned set of objects by mandating that each returned object shall be
associated to the source object through an instance of this class or one of
@@ -2183,25 +2169,14 @@ class _LmiInstance(BaseObject):
IncludeClassOrigin -- bool flag indicating, if the CLASSORIGIN attribute shall
be present on all appropriate elements in each returned object. Default
value is False.
- Props -- if not None, the members of the array define one or more property
+ PropertyList -- if not None, the members of the array define one or more property
names. Each returned object shall not include elements for any properties
- missing from this list. If Props is an empty list, no properties are included
- in each returned object. If it is None, no additional filtering is
- defined. Default value is None.
+ missing from this list. If PropertyList is an empty list, no properties
+ are included in each returned object. If it is None, no additional
+ filtering is defined. Default value is None.
"""
result = []
- assoc_args = {}
- if AssocClass:
- assoc_args["AssocClass"] = AssocClass
- if ResultClass:
- assoc_args["ResultClass"] = ResultClass
- if Role:
- assoc_args["Role"] = Role
- if ResultRole:
- assoc_args["ResultRole"] = ResultRole
- if Props:
- assoc_args["Props"] = Props
- associators_list = self._client._get_associators(self._cim_instance, **assoc_args)
+ associators_list = self._client._get_associators(self._cim_instance, **kwargs)
for i in associators_list:
lmi_namespace = _LmiNamespace(self._client, i.path.namespace)
lmi_class = _LmiClass(self._client, lmi_namespace, i.classname)
@@ -2210,15 +2185,14 @@ class _LmiInstance(BaseObject):
return result
@lmi_possibly_deleted(None)
- def first_associator(self, AssocClass = None, ResultClass = None, Role = None, \
- ResultRole = None, Props = None):
+ def first_associator(self, **kwargs):
"""
Returns the first associated _LmiInstance with this object.
Note: If the method _LmiInstance.delete() was called, this method will not execute
its code and will return LmiReturnValue containing None as a return value.
- Arguments:
+ Keyword Arguments:
AssocClass -- valid CIM association class name. It acts as a filter on the
returned set of objects by mandating that each returned object shall be
associated to the source object through an instance of this class or one of
@@ -2246,28 +2220,27 @@ class _LmiInstance(BaseObject):
IncludeClassOrigin -- bool flag indicating, if the CLASSORIGIN attribute shall
be present on all appropriate elements in each returned object. Default
value is False.
- Props -- if not None, the members of the array define one or more property
+ PropertyList -- if not None, the members of the array define one or more property
names. Each returned object shall not include elements for any properties
- missing from this list. If Props is an empty list, no properties are included
- in each returned object. If it is None, no additional filtering is
- defined. Default value is None.
+ missing from this list. If PropertyList is an empty list, no properties
+ are included in each returned object. If it is None, no additional
+ filtering is defined. Default value is None.
"""
- result = self.associators(AssocClass = AssocClass, ResultClass = ResultClass,
- Role = Role, ResultRole = ResultRole, Props = Props)
+ result = self.associators(**kwargs)
if not result:
return None
return result[0]
@lmi_possibly_deleted([])
@lmi_return_val_if_fail(lambda obj: obj._cim_instance.path, [])
- def reference_names(self, ResultClass = None, Role = None):
+ def reference_names(self, **kwargs):
"""
Returns a list of association _LmiInstanceName objects with this object.
Note: If the method _LmiInstance.delete() was called, this method will not execute
its code and will return LmiReturnValue containing None as a return value.
- Arguments:
+ Keyword Arguments:
ResultClass -- valid CIM class name. It acts as a filter on the returned set
of object names by mandating that each returned Object Name identify an
instance of this class (or one of its subclasses) or this class (or one of its
@@ -2278,26 +2251,20 @@ class _LmiInstance(BaseObject):
the value of this parameter.
"""
result = []
- reference_names_args = {}
- if ResultClass:
- reference_names_args["ResultClass"] = ResultClass
- if Role:
- reference_names_args["Role"] = Role
- reference_names_list = self._client._get_reference_names(
- self._cim_instance, **reference_names_args)
+ reference_names_list = self._client._get_reference_names(self._cim_instance, **kwargs)
for i in reference_names_list:
result.append(_LmiInstanceName(self._client, i))
return result
@lmi_possibly_deleted(None)
- def first_reference_name(self, ResultClass = None, Role = None):
+ def first_reference_name(self, **kwargs):
"""
Returns the first association _LmiInstanceName with this object.
Note: If the method _LmiInstance.delete() was called, this method will not execute
its code and will return LmiReturnValue containing None as a return value.
- Arguments:
+ Keywords Arguments:
ResultClass -- valid CIM class name. It acts as a filter on the returned set
of object names by mandating that each returned Object Name identify an
instance of this class (or one of its subclasses) or this class (or one of its
@@ -2307,21 +2274,21 @@ class _LmiInstance(BaseObject):
that refers to the target instance through a property with a name that matches
the value of this parameter.
"""
- result = self.reference_names(ResultClass = ResultClass, Role = Role)
+ result = self.reference_names(**kwargs)
if not result:
return None
return result[0]
@lmi_possibly_deleted([])
@lmi_return_val_if_fail(lambda obj: obj._cim_instance.path, [])
- def references(self, ResultClass = None, Role = None, Props = None):
+ def references(self, **kwargs):
"""
Returns a list of association _LmiInstance objects with this object.
Note: If the method _LmiInstance.delete() was called, this method will not execute
its code and will return LmiReturnValue containing None as a return value.
- Arguments:
+ Keyword Arguments:
ResultClass -- valid CIM class name. It acts as a filter on the returned set
of objects by mandating that each returned object shall be an instance of this
class (or one of its subclasses) or this class (or one of its subclasses).
@@ -2336,21 +2303,14 @@ class _LmiInstance(BaseObject):
IncludeClassOrigin -- bool flag indicating, if the CLASSORIGIN attribute shall
be present on all appropriate elements in each returned object. Default
value is False.
- Props -- if not None, the members of the list define one or more property
+ PropertyList -- if not None, the members of the list define one or more property
names. Each returned object shall not include elements for any properties
- missing from this list. If Props is an empty list, no properties are included
- in each returned object. If Props is None, no additional filtering is
- defined. Default value is None.
+ missing from this list. If PropertyList is an empty list, no properties
+ are included in each returned object. If PropertyList is None, no
+ additional filtering is defined. Default value is None.
"""
result = []
- references_args = {}
- if ResultClass:
- references_args["ResultClass"] = ResultClass
- if Role:
- references_args["Role"] = Role
- if Props:
- references_args["Props"] = Props
- references_list = self._client._get_references(self._cim_instance, **references_args)
+ references_list = self._client._get_references(self._cim_instance, **kwargs)
for i in references_list:
lmi_namespace = _LmiNamespace(self._client, i.path.namespace)
lmi_class = _LmiClass(self._client, lmi_namespace, i.classname)
@@ -2359,14 +2319,14 @@ class _LmiInstance(BaseObject):
return result
@lmi_possibly_deleted(None)
- def first_reference(self, ResultClass = None, Role = None, Props = None):
+ def first_reference(self, **kwargs):
"""
Returns the first association _LmiInstance with this object.
Note: If the method _LmiInstance.delete() was called, this method will not execute
its code and will return LmiReturnValue containing None as a return value.
- Arguments:
+ Keyword Arguments:
ResultClass -- valid CIM class name. It acts as a filter on the returned set
of objects by mandating that each returned object shall be an instance of this
class (or one of its subclasses) or this class (or one of its subclasses).
@@ -2374,12 +2334,13 @@ class _LmiInstance(BaseObject):
objects by mandating that each returned object shall refer to the target
object through a property with a name that matches the value of this
parameter.
- Props -- if not None, the members of the list define one or more property
+ PropertyList -- if not None, the members of the list define one or more property
names. Each returned object shall not include elements for any properties
- missing from this list. If Props is an empty list, no properties are included
- in each returned object. If Props is None, no additional filtering is defined.
+ missing from this list. If PropertyList is an empty list, no properties
+ are included in each returned object. If PropertyList is None, no
+ additional filtering is defined.
"""
- result = self.references(ResultClass = ResultClass, Role = Role, Props = Props)
+ result = self.references(**kwargs)
if not result:
return None
return result[0]
10 years, 10 months
[cura-tools] master: drop LmiInteractiveShell::cleanup() (b651ec0)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit b651ec0e1089777f72cfbad890f6120fd25502d2
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Jul 19 13:26:05 2013 +0200
drop LmiInteractiveShell::cleanup()
All subscribed indications via LMIShell are autodeleted by registering atexit hook. There is no need to manually delete them on shell's exit.
>---------------------------------------------------------------
cli-tools/lmishell | 9 ---------
1 files changed, 0 insertions(+), 9 deletions(-)
diff --git a/cli-tools/lmishell b/cli-tools/lmishell
index f99521f..b3c018d 100755
--- a/cli-tools/lmishell
+++ b/cli-tools/lmishell
@@ -458,14 +458,6 @@ class LmiInteractiveShell(code.InteractiveConsole):
more = 0
self.save_history()
- def cleanup(self):
- """
- Cleanup in terms of unsubscribing all the indications.
- """
- for (k, v) in self.locals.iteritems():
- if isinstance(v, LmiConnection):
- v.unsubscribe_all_indications()
-
def load_history(self):
"""
Loads the shell's history from the history file.
@@ -533,7 +525,6 @@ def _lmi_interact(locals = None):
"""
console = LmiInteractiveShell("> ", "... ", locals)
console.interact()
- console.cleanup()
def _connect(hostname, username = "", password = "", interactive = False, use_cache = True):
"""
10 years, 10 months
[cura-tools] master: drop standalone (re)raise statements (6e9e149)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 6e9e14979e6c9b90143be84762d2ca1280c93338
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Jul 19 12:29:07 2013 +0200
drop standalone (re)raise statements
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 4 ++--
cli-tools/lmishell | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index ba5ffe3..2cb6c17 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -121,7 +121,7 @@ def _lmi_start_indication_listener(hostname, port, handler, certfile = None, key
listener.start()
except socket.error, e:
if LmiBaseClient._get_use_exceptions():
- raise
+ raise e
return LmiReturnValue(
use_display_hook = True,
rval = False,
@@ -2773,7 +2773,7 @@ class LmiConnection(object):
if e.args[0] == pywbem.cim_constants.CIM_ERR_NOT_FOUND:
return True
if use_exceptions:
- raise
+ raise e
return False
except pywbem.cim_http.AuthError, e:
return False
diff --git a/cli-tools/lmishell b/cli-tools/lmishell
index d4ef7f9..024ba20 100755
--- a/cli-tools/lmishell
+++ b/cli-tools/lmishell
@@ -518,7 +518,7 @@ def __lmi_raw_input(prompt, use_echo = True):
except KeyboardInterrupt, e:
if not use_echo:
os.system("stty echo")
- raise
+ raise e
if not use_echo:
os.system("stty echo")
sys.stdout.write("\n")
10 years, 10 months
[cura-tools] master: add doc strings (b87e9e7)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit b87e9e70b1d838100760988f60deac38dec8d27d
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Jul 18 21:34:48 2013 +0200
add doc strings
>---------------------------------------------------------------
Diff suppressed because of size. To see it, use:
git diff --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol ^b87e9e70b1d838100760988f60deac38dec8d27d~1 b87e9e70b1d838100760988f60deac38dec8d27d
10 years, 10 months
[cura-tools] master: drop default values as dictionaries (77a253e)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 77a253e4cd36b27932d3604bfff1058463b2fc8b
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Jul 19 08:39:26 2013 +0200
drop default values as dictionaries
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_base.py | 6 +++++-
cli-tools/lmi/lmi_client_shell.py | 10 +++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_base.py b/cli-tools/lmi/lmi_client_base.py
index 0b0e76f..7339cf3 100644
--- a/cli-tools/lmi/lmi_client_base.py
+++ b/cli-tools/lmi/lmi_client_base.py
@@ -668,7 +668,7 @@ class LmiBaseClient(object):
raise_or_dump_exception(e)
return []
- def _create_instance(self, classname, namespace, properties = {}, qualifiers = {}, property_list = None):
+ def _create_instance(self, classname, namespace, properties = None, qualifiers = None, property_list = None):
"""
Returns a new CIMInstance, if no error occurs; otherwise None is returned. If the
shell does not dump exceptions, an appropriate exception is raised.
@@ -684,6 +684,10 @@ class LmiBaseClient(object):
qualifiers -- dictionary containing a qualifier names and values
property_list -- property list for property filtering, see pywbem.CIMInstance
"""
+ # Create a new dictionaries from the input ones, we do not want to modify user's
+ # input variables.
+ properties = dict(properties) if not properties is None else {}
+ qualifiers = dict(qualifiers) if not qualifiers is None else {}
cim_instance = pywbem.CIMInstance(classname, properties, qualifiers,
pywbem.CIMInstanceName(classname, namespace = namespace), property_list)
try:
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index ed5ceff..84fa854 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -1045,7 +1045,7 @@ class _LmiClass(BaseObject):
@lmi_class_fetch_lazy
@lmi_return_val_if_fail("_namespace", None)
- def create_instance(self, properties = {}, qualifiers = {}, property_list = None):
+ def create_instance(self, properties = None, qualifiers = None, property_list = None):
"""
Creates a new CIMInstance at the server side and returns LmiReturn value
containing _LmiInstance as a result.
@@ -1055,6 +1055,10 @@ class _LmiClass(BaseObject):
qualifiers -- dictionary with initial qualifiers
property_list -- pywbem.CIMInstance.property_list
"""
+ # No need to copy dictionaries to avoid the variable mixup, the copying is done in
+ # LmiBaseClient._create_instance(), we just pass what we get.
+ properties = properties if not properties is None else {}
+ qualifiers = qualifiers if not qualifiers is None else {}
self_properties = self._cim_class.properties
for (key, value) in properties.iteritems():
if not key in self._cim_class.properties:
@@ -2405,7 +2409,7 @@ class _LmiShellCache(object):
Class representing a shell cache. Currently, it caches retrieved classes from the
CIMOM.
"""
- def __init__(self, active = True, classname_list = None, classes = {}):
+ def __init__(self, active = True, classname_list = None, classes = None):
"""
Constructs a _LmiShellCache object.
@@ -2416,7 +2420,7 @@ class _LmiShellCache(object):
name and value is CIMClass object
"""
self._classname_list = classname_list
- self._classes = classes
+ self._classes = classes if not classes is None else {}
self._active = active
def clear(self):
10 years, 10 months
[cura-tools] master: drop kwargs in _LmiClass::new_instance_name() (96c25ca)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 96c25ca045c603d616126a275c1b92ddbf0727fc
Author: Peter Hatina <phatina(a)redhat.com>
Date: Wed Jul 17 15:58:11 2013 +0200
drop kwargs in _LmiClass::new_instance_name()
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index 116f8d7..3b21b60 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -655,12 +655,12 @@ class _LmiClass(BaseObject):
result.append(_LmiInstanceName(self._client, i))
return result
- def new_instance_name(self, keybindings, **kwargs):
+ def new_instance_name(self, keybindings):
"""
Create new _LmiInstanceName object by passing all the keys/values of the object.
"""
- cim_inst_name = pywbem.CIMInstanceName(self.classname, namespace = self.namespace,
- keybindings = keybindings, **kwargs)
+ cim_inst_name = pywbem.CIMInstanceName(self.classname, keybindings,
+ self._client.hostname, self.namespace)
return _LmiInstanceName(self._client, cim_inst_name)
# NOTE: usage with Key=something, Value=something is deprecated
10 years, 10 months
[cura-tools] master: rename _LmiConstantValues and _LmiConstantValuesMethodReturnType members (d889dac)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit d889dac1b7fe8e5f7d364b332a485ce783096d13
Author: Peter Hatina <phatina(a)redhat.com>
Date: Wed Jul 17 14:50:33 2013 +0200
rename _LmiConstantValues and _LmiConstantValuesMethodReturnType members
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index 87d0cb6..116f8d7 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -500,12 +500,12 @@ class _LmiConstantValues(BaseObject):
"""
__metaclass__ = abc.ABCMeta
- def __init__(self, cim_property):
+ def __init__(self, cim_obj):
# Keys can contain various undesirable characters, such as python
# operators, etc. So we drop them.
keys = map(lambda v: "".join(c for c in v if c.isalnum()),
- cim_property.qualifiers["Values"].value)
- values = cim_property.qualifiers["ValueMap"].value
+ cim_obj.qualifiers["Values"].value)
+ values = cim_obj.qualifiers["ValueMap"].value
self._value_map = {}
for i in range(0, len(keys)):
try:
@@ -576,9 +576,9 @@ class _LmiContantValuesMethodReturnType(_LmiConstantValues):
"""
Derived class used for constant values of CIMMethod.
"""
- def __init__(self, cim_property):
- self._cast_type = cim_property.return_type
- super(self.__class__, self).__init__(cim_property)
+ def __init__(self, cim_method):
+ self._cast_type = cim_method.return_type
+ super(self.__class__, self).__init__(cim_method)
class _LmiClass(BaseObject):
def __init__(self, client, namespace, classname):
10 years, 10 months
[cura-tools] master: drop sample scripts (f242481)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit f2424814f591691f6dbb004add75d0d0a1e89358
Author: Peter Hatina <phatina(a)redhat.com>
Date: Wed Jul 17 10:03:01 2013 +0200
drop sample scripts
These tools will be replaced by LMI scripts
>---------------------------------------------------------------
Diff suppressed because of size. To see it, use:
git diff --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol ^f2424814f591691f6dbb004add75d0d0a1e89358~1 f2424814f591691f6dbb004add75d0d0a1e89358
10 years, 10 months