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]
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):
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