[cura-tools] master: introduce LMIInstanceName::delete() (96a3a2a)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 96a3a2aa5798ecab82bd8c990d8b75e086082db6
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Jul 29 13:44:38 2014 +0200
introduce LMIInstanceName::delete()
>---------------------------------------------------------------
cli/lmi/shell/LMIInstanceName.py | 199 +++++++++++++++++++++++++++++++++++++-
doc/src/shell/instance_names.rst | 23 +++++
2 files changed, 221 insertions(+), 1 deletions(-)
diff --git a/cli/lmi/shell/LMIInstanceName.py b/cli/lmi/shell/LMIInstanceName.py
index 2e45a8b..ae9015b 100644
--- a/cli/lmi/shell/LMIInstanceName.py
+++ b/cli/lmi/shell/LMIInstanceName.py
@@ -20,6 +20,7 @@ from lmi.shell.compat import *
from lmi.shell.LMIObjectFactory import LMIObjectFactory
from lmi.shell.LMIBaseObject import LMIWrapperBaseObject
from lmi.shell.LMIDecorators import lmi_instance_name_fetch_lazy
+from lmi.shell.LMIDecorators import lmi_possibly_deleted
from lmi.shell.LMIUtil import lmi_transform_to_lmi
from lmi.shell.LMIUtil import lmi_wrap_cim_method
@@ -37,6 +38,7 @@ class LMIInstanceName(LMIWrapperBaseObject):
# We use __dict__ to avoid recursion potentially caused by
# combo __setattr__ and __getattr__
self.__dict__["_cim_instance_name"] = cim_instance_name
+ self.__dict__["_deleted"] = False
self.__dict__["_lmi_class"] = None
super(LMIInstanceName, self).__init__(conn)
@@ -50,24 +52,39 @@ class LMIInstanceName(LMIWrapperBaseObject):
"""
if not isinstance(other, LMIInstanceName):
return -1
+ if self._deleted and not other._deleted:
+ return -1
+ elif not self._deleted and other._deleted:
+ return 1
return cmp(self._cim_instance_name, other._cim_instance_name)
+ @lmi_possibly_deleted(False)
def __contains__(self, key):
"""
:param string key: key name, which will be tested for presence in
keybindings
:returns: True, if the specified key is present in keybindings, False
otherwise
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return False. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
"""
return key in self._cim_instance_name
+ @lmi_possibly_deleted(None)
def __getattr__(self, name):
"""
Returns class member or key property.
:param string name: class member or key property name
:returns: class member or key property
- :raises: :py:exc:`AttributeError`
+ :raises: :py:exc:`AttributeError`, :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return None. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
"""
if name in self._cim_instance_name:
member = self._cim_instance_name[name]
@@ -80,12 +97,18 @@ class LMIInstanceName(LMIWrapperBaseObject):
return lmi_wrap_cim_method(self._conn, name, self)
raise AttributeError(name)
+ @lmi_possibly_deleted(None)
def __setattr__(self, name, value):
"""
Assigns a new value to class member or key property.
:param string name: class member or key property name
:param value: new value to assign
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return None. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
"""
if name in self._cim_instance_name.keys():
if isinstance(value, str):
@@ -101,26 +124,48 @@ class LMIInstanceName(LMIWrapperBaseObject):
else:
self.__dict__[name] = value
+ @lmi_possibly_deleted("")
def __str__(self):
"""
:returns: string containing object path
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty string.
+ If the shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be
+ raised.
"""
return unicode(self).encode("utf-8")
+ @lmi_possibly_deleted(u"")
def __unicode__(self):
"""
:returns: unicode string containing object path
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty unicode
+ string. If the shell uses exceptions, :py:exc:`.LMIDeletedObjectError`
+ will be raised.
"""
return unicode(self._cim_instance_name)
+ @lmi_possibly_deleted("")
def __repr__(self):
"""
:returns: pretty string for the object
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty string.
+ If the shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be
+ raised.
"""
return "%s(classname=\"%s\"...)" % (
self.__class__.__name__,
self.classname)
+ @lmi_possibly_deleted([])
def associator_names(self, AssocClass=None, ResultClass=None, Role=None,
ResultRole=None):
"""
@@ -152,6 +197,12 @@ class LMIInstanceName(LMIWrapperBaseObject):
association class that refers to the returned object shall match
the value of this parameter.
:returns: list of associated :py:class:`.LMIInstanceName` objects
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty list. If
+ the shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be
+ raised.
**Usage:** :ref:`associators_instance_names`.
"""
@@ -159,6 +210,7 @@ class LMIInstanceName(LMIWrapperBaseObject):
self._cim_instance_name, AssocClass, ResultClass, Role, ResultRole)
return lmi_transform_to_lmi(self._conn, assoc_names)
+ @lmi_possibly_deleted(None)
def first_associator_name(self, AssocClass=None, ResultClass=None,
Role=None, ResultRole=None):
"""
@@ -190,6 +242,11 @@ class LMIInstanceName(LMIWrapperBaseObject):
association class that refers to the returned object shall match
the value of this parameter.
:returns: first associated :py:class:`.LMIInstanceName` object
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return None. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
**Usage:** :ref:`associators_instance_names`.
"""
@@ -200,6 +257,7 @@ class LMIInstanceName(LMIWrapperBaseObject):
return None
return lmi_transform_to_lmi(self._conn, assoc_names[0])
+ @lmi_possibly_deleted([])
def associators(self, AssocClass=None, ResultClass=None, Role=None,
ResultRole=None, IncludeQualifiers=False,
IncludeClassOrigin=False, PropertyList=None):
@@ -241,6 +299,12 @@ class LMIInstanceName(LMIWrapperBaseObject):
returned object. If it is None, no additional filtering is
defined.
:returns: list of associated :py:class:`.LMIInstance` objects
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty list. If
+ the shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be
+ raised.
**Usage:** :ref:`associators_instances`.
"""
@@ -249,6 +313,7 @@ class LMIInstanceName(LMIWrapperBaseObject):
IncludeQualifiers, IncludeClassOrigin, PropertyList)
return lmi_transform_to_lmi(self._conn, associators)
+ @lmi_possibly_deleted(None)
def first_associator(self, AssocClass=None, ResultClass=None, Role=None,
ResultRole=None, IncludeQualifiers=False,
IncludeClassOrigin=False, PropertyList=None):
@@ -288,6 +353,11 @@ class LMIInstanceName(LMIWrapperBaseObject):
is an empty list, no properties are included in each returned
object. If it is None, no additional filtering is defined.
:returns: first associated :py:class:`.LMIInstance`
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return None. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
**Usage:** :ref:`associators_instances`.
"""
@@ -298,6 +368,7 @@ class LMIInstanceName(LMIWrapperBaseObject):
return None
return lmi_transform_to_lmi(self._conn, associators[0])
+ @lmi_possibly_deleted([])
def reference_names(self, ResultClass=None, Role=None):
"""
Returns a list of association :py:class:`.LMIInstanceName` objects with
@@ -313,6 +384,12 @@ class LMIInstanceName(LMIWrapperBaseObject):
through a property with a name that matches the value of this
parameter.
:returns: list of association :py:class:`.LMIInstanceName` objects
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty list. If
+ the shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be
+ raised.
**Usage:** :ref:`references_instance_names`.
"""
@@ -320,6 +397,7 @@ class LMIInstanceName(LMIWrapperBaseObject):
self._cim_instance_name, ResultClass, Role)
return lmi_transform_to_lmi(self._conn, reference_names)
+ @lmi_possibly_deleted(None)
def first_reference_name(self, ResultClass=None, Role=None):
"""
Returns the first association :py:class:`.LMIInstanceName` with this
@@ -335,6 +413,11 @@ class LMIInstanceName(LMIWrapperBaseObject):
through a property with a name that matches the value of this
parameter.
:returns: first association :py:class:`.LMIInstanceName` object
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return None. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
**Usage:** :ref:`references_instance_names`.
"""
@@ -344,6 +427,7 @@ class LMIInstanceName(LMIWrapperBaseObject):
return None
return lmi_transform_to_lmi(self._conn, reference_names[0])
+ @lmi_possibly_deleted([])
def references(self, ResultClass=None, Role=None, IncludeQualifiers=False,
IncludeClassOrigin=False, PropertyList=None):
"""
@@ -372,6 +456,12 @@ class LMIInstanceName(LMIWrapperBaseObject):
object. If PropertyList is None, no additional filtering is
defined.
:returns: list of association :py:class:`.LMIInstance` objects
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty list. If
+ the shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be
+ raised.
**Usage:** :ref:`references_instances`.
"""
@@ -380,6 +470,7 @@ class LMIInstanceName(LMIWrapperBaseObject):
IncludeClassOrigin, PropertyList)
return lmi_transform_to_lmi(self._conn, references)
+ @lmi_possibly_deleted(None)
def first_reference(self, ResultClass=None, Role=None,
IncludeQualifiers=False, IncludeClassOrigin=False,
PropertyList=None):
@@ -409,6 +500,11 @@ class LMIInstanceName(LMIWrapperBaseObject):
object. If PropertyList is None, no additional filtering is
defined.
:returns: first association :py:class:`.LMIInstance` object
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return None. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
**Usage:** :ref:`references_instances`.
"""
@@ -425,6 +521,26 @@ class LMIInstanceName(LMIWrapperBaseObject):
"""
return lmi_transform_to_lmi(self._conn, self._cim_instance_name.copy())
+ @lmi_possibly_deleted(True)
+ def delete(self):
+ """
+ Deletes the instance defined by this object path from the CIMOM.
+
+ :returns: True, if the instance is deleted; False otherwise
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return True. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
+
+ **Usage:** :ref:`instance_names_delete`.
+ """
+ rval, _, _ = self._conn.client.delete_instance(
+ self._cim_instance_name)
+ self._deleted = rval
+ return self._deleted
+
+ @lmi_possibly_deleted(None)
def to_instance(self):
"""
Creates a new :py:class:`.LMIInstance` object from
@@ -432,6 +548,11 @@ class LMIInstanceName(LMIWrapperBaseObject):
:returns: :py:class:`.LMIInstance` object if the object was retrieved
successfully; None otherwise.
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return None. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
**Usage:** :ref:`instance_names_conversion`.
"""
@@ -441,38 +562,66 @@ class LMIInstanceName(LMIWrapperBaseObject):
return None
return lmi_transform_to_lmi(self._conn, instance)
+ @lmi_possibly_deleted([])
@lmi_instance_name_fetch_lazy()
def methods(self):
"""
Returns a list of :py:class:`wbem.CIMInstance` methods' names.
:returns: list of :py:class:`wbem.CIMInstance` methods' names
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty list. If
+ the shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be
+ raised.
**Usage:** :ref:`instances_methods`.
"""
return self._lmi_class.methods()
+ @lmi_possibly_deleted(None)
@lmi_instance_name_fetch_lazy()
def print_methods(self):
"""
Prints out the list of :py:class:`wbem.CIMInstance` methods' names.
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return None. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
+
**Usage:** :ref:`instances_methods`.
"""
self._lmi_class.print_methods()
+ @lmi_possibly_deleted([])
def key_properties(self):
"""
:returns: list of strings of key properties
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty list. If
+ the shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be
+ raised.
**Usage:** :ref:`instance_names_key_properties`.
"""
return self._cim_instance_name.keys()
+ @lmi_possibly_deleted(None)
def print_key_properties(self):
"""
Prints out the list of key properties.
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return None. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
+
**Usage:** :ref:`instance_names_key_properties`.
"""
for name, key_prop in self._cim_instance_name.iteritems():
@@ -481,46 +630,94 @@ class LMIInstanceName(LMIWrapperBaseObject):
value = "'%s'" % value
sys.stdout.write("%s = %s\n" % (name, value))
+ @lmi_possibly_deleted({})
def key_properties_dict(self):
"""
:returns: dictionary with key properties and corresponding values
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty
+ dictionary. If the shell uses exceptions,
+ :py:exc:`.LMIDeletedObjectError` will be raised.
"""
return self._cim_instance_name.keybindings.copy()
+ @lmi_possibly_deleted(None)
def key_property_value(self, prop_name):
"""
:param string prop_name: key property name
:returns: key property value
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return None. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
"""
return getattr(self, prop_name)
@property
+ @lmi_possibly_deleted("")
def classname(self):
"""
:returns: class name
:rtype: string
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty string.
+ If the shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be
+ raised.
"""
return self._cim_instance_name.classname
@property
+ @lmi_possibly_deleted("")
def namespace(self):
"""
:returns: namespace name
:rtype: string
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty string.
+ If the shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be
+ raised.
"""
return self._cim_instance_name.namespace
@property
+ @lmi_possibly_deleted("")
def hostname(self):
"""
:returns: host name
:rtype: string
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return an empty string.
+ If the shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be
+ raised.
"""
return self._cim_instance_name.host
@property
+ def is_deleted(self):
+ """
+ :returns: True, if the instance was deleted from the CIMOM; False
+ otherwise
+ """
+ return self._deleted
+
+ @property
+ @lmi_possibly_deleted(None)
def wrapped_object(self):
"""
:returns: wrapped :py:class:`wbem.CIMInstanceName` object
+ :raises: :py:exc:`.LMIDeletedObjectError`
+
+ **NOTE:** If the method :py:meth:`.LMIInstanceName.delete` was called,
+ this method will not execute its code and will return None. If the
+ shell uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
"""
return self._cim_instance_name
diff --git a/doc/src/shell/instance_names.rst b/doc/src/shell/instance_names.rst
index 3644b0b..4e9c68b 100644
--- a/doc/src/shell/instance_names.rst
+++ b/doc/src/shell/instance_names.rst
@@ -19,6 +19,29 @@ To get a list of key properties, see following example:
...
>
+.. _instance_names_delete:
+
+Instance Names deletion
+-----------------------
+A single instance can be removed from the CIMOM by executing:
+
+.. code-block:: python
+
+ > instance_name.delete()
+ True
+ >
+
+**NOTE:** After executing the :py:meth:`.LMIInstanceName.delete` method, all
+the object key properties, methods will become inaccessible.
+
+Deletion of the instance can be verified by:
+
+.. code-block:: python
+
+ > instance_name.is_deleted
+ True
+ >
+
.. _instance_names_conversion:
Conversion to a LMIInstance
9 years, 9 months
[cura-tools] master: fix synchro methods indication listener startup (6a74b0c)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 6a74b0c70c1b4f9003ac550afcca43175ca27dd1
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Jul 25 12:04:17 2014 +0200
fix synchro methods indication listener startup
>---------------------------------------------------------------
cli/lmi/shell/LMIMethod.py | 33 ++++++++----------------
cli/lmi/shell/compat/CIMIndicationListener.py | 23 +++++++++++++----
2 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/cli/lmi/shell/LMIMethod.py b/cli/lmi/shell/LMIMethod.py
index 7b9a316..885f251 100644
--- a/cli/lmi/shell/LMIMethod.py
+++ b/cli/lmi/shell/LMIMethod.py
@@ -334,36 +334,25 @@ class LMIMethod(LMIWrapperBaseObject):
cond.notify()
cond.release()
- # Start indication listener.
cond = threading.Condition()
job_finished = LMIPassByRef(JOB_NOT_FINISHED)
job_exception = LMIPassByRef(None)
# There needs to be a pattern of at least 8 "X" in a row at the end of
# the indication_name.
indication_name = "synchro-method-call-XXXXXXXX"
- listener = LMIIndicationListener()
+
+ # Start the indication listener
+ listener = LMIIndicationListener(
+ "0.0.0.0",
+ self._INDICATION_DESTINATION_PORT,
+ LMIShellConfig().cert_file,
+ LMIShellConfig().key_file)
indication_name = listener.add_handler(
indication_name, handle_job, cond, job_finished, job_exception)
- # Search for free port.
- port = LMIMethod._INDICATION_DESTINATION_PORT
- for i in xrange(LMIMethod._INDICATION_BIND_TRIES):
- try:
- cert_file = LMIShellConfig
- listener.start(
- port,
- LMIShellConfig().cert_file,
- LMIShellConfig().key_file)
- break
- except wbem.ConnectionError, e:
- port += 1
- except wbem.AuthError, e:
- port += 1
- else:
- raise LMIIndicationListenerError(
- "Can not start indication listener")
+ listener.start(self._INDICATION_BIND_TRIES)
logger.debug(
"Choosing port for Sync%s() indications: %d" %
- (self._method_name, port))
+ (self._method_name, listener.port))
# Search for necessary static filter
filter_name = "LMI:%s:Changed" % job_inst.classname
@@ -387,7 +376,7 @@ class LMIMethod(LMIWrapperBaseObject):
# LMIMethod() and PreferPolling.
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
- s.connect((netloc, port))
+ s.connect((netloc, listener.port))
except socket.gaierror, e:
listener.stop()
errorstr = "Can not determine IP address of this machine"
@@ -403,7 +392,7 @@ class LMIMethod(LMIWrapperBaseObject):
"Name": indication_name,
"Destination": "%s://%s:%d/%s%s" % (
"https" if listener.uses_ssl else "http",
- destination, port, indication_prefix, indication_name),
+ destination, listener.port, indication_prefix, indication_name),
}
cim_handler, _, _ = self._conn.client.create_instance(
"CIM_IndicationHandlerCIMXML",
diff --git a/cli/lmi/shell/compat/CIMIndicationListener.py b/cli/lmi/shell/compat/CIMIndicationListener.py
index 79f49ee..6b8a2d1 100644
--- a/cli/lmi/shell/compat/CIMIndicationListener.py
+++ b/cli/lmi/shell/compat/CIMIndicationListener.py
@@ -27,6 +27,8 @@ from SocketServer import ThreadingMixIn
from BaseHTTPServer import HTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler
+from lmi.shell.LMIExceptions import ConnectionError
+
class CIMIndicationHandlerCallback(object):
"""
@@ -138,17 +140,26 @@ class CIMIndicationListener(object):
self._server = None
self._server_thread = None
- def start(self):
+ def start(self, retries=1):
"""
Starts a indication listener.
The indication listener runs in a newly-created thread.
+
+ :param int retries: number of bind retries.
"""
- try:
- self._server = CIMIndicationServer(
- (self._hostname, self._port), CIMIndicationHandler)
- except socket.error, e:
- raise ConnectionError(e)
+ # Try to create a listener for retries-times.
+ for i in xrange(retries):
+ try:
+ self._server = CIMIndicationServer(
+ (self._hostname, self._port), CIMIndicationHandler)
+ break
+ except socket.error as e:
+ # We raise the exception, when we run out of retries or TCP port
+ # is out of range.
+ self._port += 1
+ if i == retries - 1 or self._port >= 65536:
+ raise ConnectionError(e)
self._server._handlers = self._handlers
self._server_thread = threading.Thread(
target=self._server.serve_forever)
9 years, 9 months
[cura-tools] master: fix CIMIndicationListener API due to compatibility (a3a73f0)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit a3a73f0e8e005dad9ed3dc44b28799905b2b5492
Author: Peter Hatina <phatina(a)redhat.com>
Date: Wed Jul 23 13:00:57 2014 +0200
fix CIMIndicationListener API due to compatibility
>---------------------------------------------------------------
cli/lmi/shell/LMIIndicationListener.py | 14 ++++++----
cli/lmi/shell/compat/CIMIndicationListener.py | 33 +++++++++++++++----------
2 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/cli/lmi/shell/LMIIndicationListener.py b/cli/lmi/shell/LMIIndicationListener.py
index 5074874..8c9abf8 100644
--- a/cli/lmi/shell/LMIIndicationListener.py
+++ b/cli/lmi/shell/LMIIndicationListener.py
@@ -28,18 +28,20 @@ class LMIIndicationListener(wbem.CIMIndicationListener):
Class representing indication listener, which provides a unified API for
the server startup and shutdown and for registering an indication handler.
- :param string hostname: hostname or address of the machine, where the
- indications will be delivered
+ :param str hostname: bind hostname
:param int port: TCP port, where the server should listen for incoming
messages
- :param string certfile: path to certificate file, if SSL used
- :param string keyfile: path to key file, if SSL used
+ :param str certfile: path to certificate file, if SSL used
+ :param str keyfile: path to key file, if SSL used
+ :param str trust_store: path to trust store
"""
# Minimum replacable "X" characters in handler pattern string.
HANDLER_MINIMUM_REPL_CHARS_COUNT = 8
- def __init__(self):
- super(LMIIndicationListener, self).__init__()
+ def __init__(self, hostname, port, certfile=None, keyfile=None,
+ trust_store=None):
+ super(LMIIndicationListener, self).__init__(
+ hostname, port, certfile, keyfile, trust_store)
def __create_handler_name(self, handler_name_pattern):
"""
diff --git a/cli/lmi/shell/compat/CIMIndicationListener.py b/cli/lmi/shell/compat/CIMIndicationListener.py
index 18999aa..79f49ee 100644
--- a/cli/lmi/shell/compat/CIMIndicationListener.py
+++ b/cli/lmi/shell/compat/CIMIndicationListener.py
@@ -118,28 +118,35 @@ class CIMIndicationListener(object):
"""
Class representing indication listener, which provides a unified API for
the server startup and shutdown and for registering an indication handler.
+
+ :param str hostname: bind hostname
+ :param int port: listening port
+ :param str cert_file: path to X509 certificate
+ :param str key_file: path to X509 private key; may be None, if
+ cert_file also contains private key
+ :param str trust_store: path to trust store
"""
- def __init__(self):
+ def __init__(self, hostname, port, certfile=None, keyfile=None,
+ trust_store=None):
self._handlers = {}
+ self._hostname = hostname
+ self._port = port
+ self._certfile = certfile
+ self._keyfile = keyfile
+ self._trust_store = trust_store
self._server = None
self._server_thread = None
- def start(self, port, cert_file=None, key_file=None, trust_store=None):
+ def start(self):
"""
Starts a indication listener.
The indication listener runs in a newly-created thread.
-
- :param int port: listening port
- :param str cert_file: path to X509 certificate
- :param str key_file: path to X509 private key; may be None, if
- cert_file also contains private key
- :param str trust_store: path to trust store
"""
try:
self._server = CIMIndicationServer(
- ("", port), CIMIndicationHandler)
+ (self._hostname, self._port), CIMIndicationHandler)
except socket.error, e:
raise ConnectionError(e)
self._server._handlers = self._handlers
@@ -147,13 +154,13 @@ class CIMIndicationListener(object):
target=self._server.serve_forever)
self._server_thread.daemon = True
self._server_uses_ssl = False
- if cert_file:
+ if self._certfile:
self._server.socket = ssl.wrap_socket(
self._server.socket,
- certfile=cert_file,
- keyfile=key_file,
+ certfile=self._certfile,
+ keyfile=self._keyfile,
server_side=True,
- ca_certs=trust_store)
+ ca_certs=self._trust_store)
self._server_uses_ssl = True
self._server_thread.start()
9 years, 9 months
[cura-tools] master: fix README.md (c82b86a)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit c82b86ad262600bfb0ae5b7b1b455a20b9206741
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Jul 22 12:21:27 2014 +0200
fix README.md
>---------------------------------------------------------------
README.md | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 7ed0b84..28ae341 100644
--- a/README.md
+++ b/README.md
@@ -10,18 +10,18 @@ bindings, standard APIs, and standard scripting interfaces.
OpenLMI-tools
=============
-OpenLMI-tools currently contains LMIShell, a (non)interactive command
-interpreter for CIM objects access. And lmi meta-command serving as a command
-line interface to OpenLMI Providers, which utilizes LMIShell.
+OpenLMI-tools currently contains LMIShell, a (non)interactive command
+interpreter for CIM objects access and LMI-Meta Command, which serves as a
+command line interface to OpenLMI Providers, which utilizes LMIShell.
Dependencies
------------
OpenLMI tools require
- * python2.7,
+ * python2.7
* python-setuptools
- * pywbem
+ * lmiwbem
* python-docopt
### Uploading to PyPI
@@ -39,6 +39,7 @@ Installation
Use standard `setuptools` script for installation:
$ cd cli
+ $ make # generate setup.py
$ python setup.py install --root=/path/to/install/directory
If you have limited access to system path, you may wish to install to user
9 years, 9 months
[cura-tools] master: fix sphinx documentation references (c93ec6d)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit c93ec6d7db58200c19662792e752f487c7532a11
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Jul 22 11:09:56 2014 +0200
fix sphinx documentation references
>---------------------------------------------------------------
cli/lmi/shell/LMICIMXMLClient.py | 2 +-
cli/lmi/shell/LMIConnection.py | 12 ++++----
cli/lmi/shell/LMIConsole.py | 8 ++--
cli/lmi/shell/LMIDecorators.py | 6 ++--
cli/lmi/shell/LMIExceptions.py | 2 +-
cli/lmi/shell/LMIInstance.py | 58 ++++++++++++++++++------------------
cli/lmi/shell/LMIObjectFactory.py | 2 +-
cli/lmi/shell/LMIShellCache.py | 4 +-
cli/lmi/shell/LMIShellConfig.py | 2 +-
9 files changed, 48 insertions(+), 48 deletions(-)
diff --git a/cli/lmi/shell/LMICIMXMLClient.py b/cli/lmi/shell/LMICIMXMLClient.py
index 4cd9d5a..fc62394 100644
--- a/cli/lmi/shell/LMICIMXMLClient.py
+++ b/cli/lmi/shell/LMICIMXMLClient.py
@@ -269,7 +269,7 @@ class LMICIMXMLClient(object):
properties are included in the response. If the PropertyList input
parameter is None, no additional filtering is defined.
:returns: :py:class:`.LMIReturnValue` object, where ``rval`` is set to
- :pyclass:`wbem.CIMInstance` object, if no error occurs; otherwise
+ :py:class:`wbem.CIMInstance` object, if no error occurs; otherwise
``rval`` is set to None and ``errorstr`` is set to corresponding
error string.
:raises: :py:exc:`.CIMError`, :py:exc:`.ConnectionError`,
diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py
index 7ab9e2c..97bceaa 100644
--- a/cli/lmi/shell/LMIConnection.py
+++ b/cli/lmi/shell/LMIConnection.py
@@ -115,7 +115,7 @@ def connect(uri, username="", password="", interactive=False, use_cache=True,
certificate needs to be verified, if SSL used; default value is True.
:param string prompt_prefix: username and password prompt prefix in case
the user is asked for credentials. Default value is empty string.
- :returns: :py:class:`LMIConnection` object or None, if LMIShell does not
+ :returns: :py:class:`.LMIConnection` object or None, if LMIShell does not
use exceptions
:raises: :py:exc:`.ConnectionError`
@@ -317,7 +317,7 @@ class LMIConnection(object):
def get_namespace(self, namespace):
"""
:param string namespace: namespace path (eg. `root/cimv2`)
- :returns: :py:class:`LMINamespace` object
+ :returns: :py:class:`.LMINamespace` object
:raises: :py:exc:`.LMINamespaceNotFound`
"""
def get_namespace_priv(namespace, namespace_path):
@@ -353,11 +353,11 @@ class LMIConnection(object):
Connects to CIMOM and verifies credentials by performing a "dummy"
request.
- :returns: :py:class:`LMIReturnValue` object with rval set to True, if
+ :returns: :py:class:`.LMIReturnValue` object with rval set to True, if
the user was properly authenticated; False otherwise. In case of
any error, rval is set to False and errorstr contains appropriate
error string.
- :rtype: :py:class:`LMIReturnValue`
+ :rtype: :py:class:`.LMIReturnValue`
"""
# Connect to CIMOM. We may fail before the actual "dummy" request is
# sent. This only applies for LMIWBEM.
@@ -430,7 +430,7 @@ class LMIConnection(object):
* **Destination** (*string*) -- destination URI, where the
indications should be delivered
- :returns: :py:class:`LMIReturnValue` object with ``rval`` set to True,
+ :returns: :py:class:`.LMIReturnValue` object with ``rval`` set to True,
if indication was subscribed; False otherwise. If a error occurs,
``errorstr`` is set to appropriate error string.
"""
@@ -550,7 +550,7 @@ class LMIConnection(object):
Unsubscribes an indication.
:param string name: indication name
- :returns: :py:class:`LMIReturnValue` object with ``rval`` set to True,
+ :returns: :py:class:`.LMIReturnValue` object with ``rval`` set to True,
if unsubscribed; False otherwise
"""
if name not in self._indications:
diff --git a/cli/lmi/shell/LMIConsole.py b/cli/lmi/shell/LMIConsole.py
index 2092482..93911cc 100644
--- a/cli/lmi/shell/LMIConsole.py
+++ b/cli/lmi/shell/LMIConsole.py
@@ -123,7 +123,7 @@ class LMIConsole(code.InteractiveConsole):
verify_server_cert=self._verify_server_cert,
prompt_prefix=""):
"""
- Returns :py:class:`LMIConnection` object with provided URI and
+ Returns :py:class:`.LMIConnection` object with provided URI and
credentials.
:param string uri: URI of the CIMOM
@@ -142,7 +142,7 @@ class LMIConsole(code.InteractiveConsole):
default value is empty string
:returns: connection object
- :rtype: :py:class:`LMIConnection`
+ :rtype: :py:class:`.LMIConnection`
"""
return connect_internal(
uri, username, password, interactive=True,
@@ -225,7 +225,7 @@ class LMIConsole(code.InteractiveConsole):
verify_server_cert=self._verify_server_cert,
prompt_prefix=""):
"""
- Returns :py:class:`LMIConnection` object with provided URI and
+ Returns :py:class:`.LMIConnection` object with provided URI and
credentials.
:param string uri: URI of the CIMOM
@@ -244,7 +244,7 @@ class LMIConsole(code.InteractiveConsole):
default value is empty string
:returns: connection object
- :rtype: :py:class:`LMIConnection`
+ :rtype: :py:class:`.LMIConnection`
"""
return connect_internal(
uri, username, password, interactive=interactive,
diff --git a/cli/lmi/shell/LMIDecorators.py b/cli/lmi/shell/LMIDecorators.py
index cc33605..8be5694 100644
--- a/cli/lmi/shell/LMIDecorators.py
+++ b/cli/lmi/shell/LMIDecorators.py
@@ -231,7 +231,7 @@ class lmi_possibly_deleted(lmi_return_expr_if_fail):
class lmi_class_fetch_lazy(object):
"""
- Decorator for :py:class:`LMIClass`, which first fetches a wrapped
+ Decorator for :py:class:`.LMIClass`, which first fetches a wrapped
:py:class:`wbem.CIMClass` object and then executes a wrapped method.
:param bool full_fetch: True, if :py:class:`wbem.CIMClass` should include
@@ -310,7 +310,7 @@ class lmi_process_cim_exceptions(object):
Execute a wrapped method.
:param instancemethod fn: decorated method
- :raises: :py:exc:`CIMError`, :py:exc:`ConnectionError`
+ :raises: :py:exc:`.CIMError`, :py:exc:`.ConnectionError`
"""
@wraps(fn)
def wrapped(*args, **kwargs):
@@ -363,7 +363,7 @@ class lmi_process_wsman_exceptions(object):
Execute a wrapped method.
:param instancemethod fn: decorated method
- :raises: :py:exc:`CIMError`
+ :raises: :py:exc:`.CIMError`
"""
@wraps(fn)
def wrapped(*args, **kwargs):
diff --git a/cli/lmi/shell/LMIExceptions.py b/cli/lmi/shell/LMIExceptions.py
index 58ececc..9a3f65c 100644
--- a/cli/lmi/shell/LMIExceptions.py
+++ b/cli/lmi/shell/LMIExceptions.py
@@ -17,7 +17,7 @@
class LMIDeletedObjectError(Exception):
"""
Raised, when there is an attempt to access properties on deleted
- :py:class:`LMIInstance` object.
+ :py:class:`.LMIInstance` object.
"""
diff --git a/cli/lmi/shell/LMIInstance.py b/cli/lmi/shell/LMIInstance.py
index f478b84..f842ab8 100644
--- a/cli/lmi/shell/LMIInstance.py
+++ b/cli/lmi/shell/LMIInstance.py
@@ -54,7 +54,7 @@ class LMIInstance(LMIWrapperBaseObject):
def __cmp__(self, other):
"""
- :param LMIInstance other: :py:class:`LMIInstance` object to compare
+ :param LMIInstance other: :py:class:`.LMIInstance` object to compare
:returns: If both instances are (not) deleted: negative number, if
self < other; 0 if self == other or positive number,
if self > other. If the first or second instance is deleted, -1 or
@@ -75,7 +75,7 @@ class LMIInstance(LMIWrapperBaseObject):
Returns True, if the specified key is present in the properties, False
otherwise.
- **NOTE:** If the method :py:meth:``LMIInstance.delete` was called, this
+ **NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
method will not execute its code and will return None. If the shell
uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
@@ -90,16 +90,16 @@ class LMIInstance(LMIWrapperBaseObject):
@lmi_possibly_deleted(None)
def __getattr__(self, name):
"""
- Returns either a class member, :py:class:`LMIMethod` object, or a
+ Returns either a class member, :py:class:`.LMIMethod` object, or a
:py:class:`wbem.CIMInstance` object property.
- **NOTE:** If the method :py:meth:``LMIInstance.delete` was called, this
+ **NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
method will not execute its code and will return None. If the shell
uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
:param string name: class member, the method name, or the property to
be returned
- :returns: class member, :py:class:`LMIMethod` object or
+ :returns: class member, :py:class:`.LMIMethod` object or
:py:class:`wbem.CIMInstance` object property
:raises: :py:exc:`.LMIDeletedObjectError`
"""
@@ -226,13 +226,13 @@ class LMIInstance(LMIWrapperBaseObject):
@lmi_possibly_deleted(None)
def path(self):
"""
- Property returning a :py:class:`LMIInstanceName` object.
+ Property returning a :py:class:`.LMIInstanceName` object.
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
method will not execute its code and will return None. If the shell
- uses exceptions, :py:exc:`LMIDeletedObjectError` will be raised.
+ uses exceptions, :py:exc:`.LMIDeletedObjectError` will be raised.
- :returns: :py:class:`LMIInstanceName` object
+ :returns: :py:class:`.LMIInstanceName` object
:raises: :py:exc:`.LMIDeletedObjectError`
"""
return lmi_transform_to_lmi(self._conn, self._cim_instance.path)
@@ -280,7 +280,7 @@ class LMIInstance(LMIWrapperBaseObject):
def associator_names(self, AssocClass=None, ResultClass=None, Role=None,
ResultRole=None):
"""
- Returns a list of associated :py:class:`LMIInstanceName` with this
+ Returns a list of associated :py:class:`.LMIInstanceName` with this
object.
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
@@ -311,7 +311,7 @@ class LMIInstance(LMIWrapperBaseObject):
specified role. That is, the name of the property in the
association class that refers to the returned object shall match
the value of this parameter.
- :returns: list of associated :py:class:`LMIInstanceName` objects
+ :returns: list of associated :py:class:`.LMIInstanceName` objects
:raises: :py:exc:`.LMIDeletedObjectError`
**Usage:** :ref:`associators_instance_names`.
@@ -324,7 +324,7 @@ class LMIInstance(LMIWrapperBaseObject):
def first_associator_name(self, AssocClass=None, ResultClass=None, Role=None,
ResultRole=None):
"""
- Returns the first associated :py:class:`LMIInstanceName` with this
+ Returns the first associated :py:class:`.LMIInstanceName` with this
object.
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
@@ -355,7 +355,7 @@ class LMIInstance(LMIWrapperBaseObject):
specified role. That is, the name of the property in the
association class that refers to the returned object shall match
the value of this parameter.
- :returns: first associated :py:class:`LMIInstanceName` object
+ :returns: first associated :py:class:`.LMIInstanceName` object
:raises: :py:exc:`.LMIDeletedObjectError`
**Usage:** :ref:`associators_instance_names`.
@@ -373,7 +373,7 @@ class LMIInstance(LMIWrapperBaseObject):
ResultRole=None, IncludeQualifiers=False,
IncludeClassOrigin=False, PropertyList=None):
"""
- Returns a list of associated :py:class:`LMIInstance` objects with this
+ Returns a list of associated :py:class:`.LMIInstance` objects with this
instance.
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
@@ -413,7 +413,7 @@ class LMIInstance(LMIWrapperBaseObject):
*PropertyList* is an empty list, no properties are included in each
returned object. If it is None, no additional filtering is
defined.
- :returns: list of associated :py:class:`LMIInstance` objects
+ :returns: list of associated :py:class:`.LMIInstance` objects
:raises: :py:exc:`.LMIDeletedObjectError`
**Usage:** :ref:`associators_instances`.
@@ -429,7 +429,7 @@ class LMIInstance(LMIWrapperBaseObject):
ResultRole=None, IncludeQualifiers=False,
IncludeClassOrigin=False, PropertyList=None):
"""
- Returns the first associated :py:class:`LMIInstance` with this object.
+ Returns the first associated :py:class:`.LMIInstance` with this object.
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
method will not execute its code and will return None. If the shell
@@ -467,7 +467,7 @@ class LMIInstance(LMIWrapperBaseObject):
elements for any properties 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.
- :returns: first associated :py:class:`LMIInstance`
+ :returns: first associated :py:class:`.LMIInstance`
:raises: :py:exc:`.LMIDeletedObjectError`
**Usage:** :ref:`associators_instances`.
@@ -484,7 +484,7 @@ class LMIInstance(LMIWrapperBaseObject):
@lmi_return_val_if_fail(lambda obj: obj._cim_instance.path, [])
def reference_names(self, ResultClass=None, Role=None):
"""
- Returns a list of association :py:class:`LMIInstanceName` objects with
+ Returns a list of association :py:class:`.LMIInstanceName` objects with
this object.
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
@@ -500,7 +500,7 @@ class LMIInstance(LMIWrapperBaseObject):
name shall identify an object that refers to the target instance
through a property with a name that matches the value of this
parameter.
- :returns: list of association :py:class:`LMIInstanceName` objects
+ :returns: list of association :py:class:`.LMIInstanceName` objects
:raises: :py:exc:`.LMIDeletedObjectError`
**Usage:** :ref:`references_instance_names`.
@@ -512,7 +512,7 @@ class LMIInstance(LMIWrapperBaseObject):
@lmi_possibly_deleted(None)
def first_reference_name(self, ResultClass=None, Role=None):
"""
- Returns the first association :py:class:`LMIInstanceName` with this
+ Returns the first association :py:class:`.LMIInstanceName` with this
object.
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
@@ -528,7 +528,7 @@ class LMIInstance(LMIWrapperBaseObject):
name shall identify an object that refers to the target instance
through a property with a name that matches the value of this
parameter.
- :returns: first association :py:class:`LMIInstanceName` object
+ :returns: first association :py:class:`.LMIInstanceName` object
:raises: :py:exc:`.LMIDeletedObjectError`
**Usage:** :ref:`references_instance_names`.
@@ -544,7 +544,7 @@ class LMIInstance(LMIWrapperBaseObject):
def references(self, ResultClass=None, Role=None, IncludeQualifiers=False,
IncludeClassOrigin=False, PropertyList=None):
"""
- Returns a list of association :py:class:`LMIInstance` objects with this
+ Returns a list of association :py:class:`.LMIInstance` objects with this
object.
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
@@ -572,7 +572,7 @@ class LMIInstance(LMIWrapperBaseObject):
is an empty list, no properties are included in each returned
object. If PropertyList is None, no additional filtering is
defined.
- :returns: list of association :py:class:`LMIInstance` objects
+ :returns: list of association :py:class:`.LMIInstance` objects
:raises: :py:exc:`.LMIDeletedObjectError`
**Usage:** :ref:`references_instances`.
@@ -587,7 +587,7 @@ class LMIInstance(LMIWrapperBaseObject):
IncludeQualifiers=False, IncludeClassOrigin=False,
PropertyList=None):
"""
- Returns the first association :py:class:`LMIInstance` with this object.
+ Returns the first association :py:class:`.LMIInstance` with this object.
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
method will not execute its code and will return None. If the shell
@@ -614,7 +614,7 @@ class LMIInstance(LMIWrapperBaseObject):
is an empty list, no properties are included in each returned
object. If PropertyList is None, no additional filtering is
defined.
- :returns: first association :py:class:`LMIInstance` object
+ :returns: first association :py:class:`.LMIInstance` object
:raises: :py:exc:`.LMIDeletedObjectError`
**Usage:** :ref:`references_instances`.
@@ -738,17 +738,17 @@ class LMIInstance(LMIWrapperBaseObject):
def refresh(self):
"""
Retrieves a new :py:class:`wbem.CIMInstance` object. Basically
- refreshes the object properties. Returns :py:class:`LMIReturnValue`
+ refreshes the object properties. Returns :py:class:`.LMIReturnValue`
with rval set to 0, if the wrapped :py:class:`wbem.CIMInstance` object
was refreshed; otherwise rval is set to -1.
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
method will not execute its code and will return
- :py:class:`LMIReturnValue` object containing -1 as a return value with
+ :py:class:`.LMIReturnValue` object containing -1 as a return value with
proper error string set. If the shell uses exceptions,
:py:exc:`.LMIDeletedObjectError` will be raised.
- :returns: :py:class:`LMIReturnValue` object with ``rval`` set to 0, if
+ :returns: :py:class:`.LMIReturnValue` object with ``rval`` set to 0, if
refreshed; -1 otherwise
:raises: :py:exc:`.LMIDeletedObjectError`
@@ -774,11 +774,11 @@ class LMIInstance(LMIWrapperBaseObject):
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
method will not execute its code and will return
- :py:class:`LMIReturnValue` object containing False as a return value
+ :py:class:`.LMIReturnValue` object containing False as a return value
with proper error string set. If the shell uses exceptions,
:py:exc:`.LMIDeletedObjectError` will be raised.
- :returns: :py:class:`LMIReturnValue` object with ``rval`` set to True, if
+ :returns: :py:class:`.LMIReturnValue` object with ``rval`` set to True, if
modified; False otherwise
:raises: :py:exc:`.LMIDeletedObjectError`
diff --git a/cli/lmi/shell/LMIObjectFactory.py b/cli/lmi/shell/LMIObjectFactory.py
index 3847673..e3c6156 100644
--- a/cli/lmi/shell/LMIObjectFactory.py
+++ b/cli/lmi/shell/LMIObjectFactory.py
@@ -41,7 +41,7 @@ class LMIObjectFactory(object):
def __new__(cls):
"""
- Creates a new :py:class:`LMIObjectFactory` instance, if not created,
+ Creates a new :py:class:`.LMIObjectFactory` instance, if not created,
and returns the singleton instance object.
"""
if not cls._instance:
diff --git a/cli/lmi/shell/LMIShellCache.py b/cli/lmi/shell/LMIShellCache.py
index 385b9fb..33ee5e0 100644
--- a/cli/lmi/shell/LMIShellCache.py
+++ b/cli/lmi/shell/LMIShellCache.py
@@ -19,7 +19,7 @@ from lmi.shell.compat import *
class LMIClassCacheEntry(object):
"""
Class used for storing :py:class:`wbem.CIMClass` in
- :py:class:`LMIShellCache`.
+ :py:class:`.LMIShellCache`.
:param CIMClass cim_class: :py:class:`wbem.CIMClass` to cache
:param bool full_fetch: True, if class is cached with qualifiers
@@ -78,7 +78,7 @@ class LMIShellCache(object):
:param string classname: cached class name
:param string namespace: namespace storing cached classes
:returns: cache object, if proper class name provided, None otherwise
- :rtype: :py:class:`LMIClassCacheEntry`
+ :rtype: :py:class:`.LMIClassCacheEntry`
"""
if namespace not in self._class_dict or \
classname not in self._class_dict[namespace]:
diff --git a/cli/lmi/shell/LMIShellConfig.py b/cli/lmi/shell/LMIShellConfig.py
index cd472ae..ca6192e 100644
--- a/cli/lmi/shell/LMIShellConfig.py
+++ b/cli/lmi/shell/LMIShellConfig.py
@@ -23,7 +23,7 @@ class LMIShellConfig(object):
loading the configuration from the file and provides a unified API to
access these settings.
- Constructs a :py:class:`LMIShellConfig` object and loads the configuration
+ Constructs a :py:class:`.LMIShellConfig` object and loads the configuration
from the file. If there is no such file, the shell's configuration
properties are set to default values. Configuration file uses python
syntax. If there is a syntax error in the configuration file, the
9 years, 9 months
[cura-tools] master: allow LMIInstanceNames to call CIMMethods (ecefb90)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit ecefb9068acfc42cf65759505a3f1b3f234af5f8
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Jul 21 14:48:09 2014 +0200
allow LMIInstanceNames to call CIMMethods
>---------------------------------------------------------------
cli/lmi/shell/LMICompleter.py | 1 +
cli/lmi/shell/LMIDecorators.py | 29 ++++++++++++++++++++
cli/lmi/shell/LMIInstanceName.py | 27 +++++++++++++++++++
cli/lmi/shell/LMIMethod.py | 53 ++++++++++++++++++++++++++++++-------
4 files changed, 100 insertions(+), 10 deletions(-)
diff --git a/cli/lmi/shell/LMICompleter.py b/cli/lmi/shell/LMICompleter.py
index b5a117b..2cd8609 100644
--- a/cli/lmi/shell/LMICompleter.py
+++ b/cli/lmi/shell/LMICompleter.py
@@ -97,6 +97,7 @@ class LMICompleter(rlcompleter.Completer):
words.extend([m + "(" for m in obj.methods()])
words.extend(obj.properties())
elif isinstance(obj, LMIInstanceName):
+ words.extend([m + "(" for m in obj.methods()])
words.extend(obj.key_properties())
elif isinstance(obj, LMIMethod):
words.extend([p + "Values" for p in obj.valuemap_parameters()])
diff --git a/cli/lmi/shell/LMIDecorators.py b/cli/lmi/shell/LMIDecorators.py
index f35db2b..cc33605 100644
--- a/cli/lmi/shell/LMIDecorators.py
+++ b/cli/lmi/shell/LMIDecorators.py
@@ -18,6 +18,7 @@ from functools import wraps
from lmi.shell.compat import *
from lmi.shell.LMIReturnValue import LMIReturnValue
+from lmi.shell.LMIUtil import lmi_wrap_cim_class
from lmi.shell.LMIUtil import lmi_raise_or_dump_exception
from lmi.shell.LMIExceptions import CIMError
@@ -253,6 +254,34 @@ class lmi_class_fetch_lazy(object):
return fn(self_wr, *args, **kwargs)
return wrapped
+class lmi_instance_name_fetch_lazy(object):
+ """
+ Decorator for :py:class:`.LMIInstanceName`, which first fetches a wrapped
+ :py:class:`wbem.CIMInstance` object and then executes a wrapped method.
+
+ :param bool full_fetch: True, if :py:class:`wbem.CIMClass` should include
+ qualifiers and class origin. Default value is False.
+ """
+ def __init__(self, full_fetch=False):
+ self._full_fetch = full_fetch
+
+ def __call__(self, fn):
+ """
+ Fetches a :py:class:`.LMIClass`, if necessary, and exeutes a wrapped
+ method.
+
+ :param instancemethod fn: decorated method
+ """
+ @wraps(fn)
+ def wrapped(self_wr, *args, **kwargs):
+ if self_wr._lmi_class is None:
+ self_wr._lmi_class = lmi_wrap_cim_class(
+ self_wr._conn,
+ self_wr._cim_instance_name.classname,
+ self_wr._cim_instance_name.namespace)
+ self_wr._lmi_class.fetch(self._full_fetch)
+ return fn(self_wr, *args, **kwargs)
+ return wrapped
# Default lmi_process_cim_exceptions error handler
def return_lmi_rval(rval, exc):
diff --git a/cli/lmi/shell/LMIInstanceName.py b/cli/lmi/shell/LMIInstanceName.py
index db344dd..2e45a8b 100644
--- a/cli/lmi/shell/LMIInstanceName.py
+++ b/cli/lmi/shell/LMIInstanceName.py
@@ -19,7 +19,9 @@ from lmi.shell.compat import *
from lmi.shell.LMIObjectFactory import LMIObjectFactory
from lmi.shell.LMIBaseObject import LMIWrapperBaseObject
+from lmi.shell.LMIDecorators import lmi_instance_name_fetch_lazy
from lmi.shell.LMIUtil import lmi_transform_to_lmi
+from lmi.shell.LMIUtil import lmi_wrap_cim_method
class LMIInstanceName(LMIWrapperBaseObject):
@@ -35,6 +37,7 @@ class LMIInstanceName(LMIWrapperBaseObject):
# We use __dict__ to avoid recursion potentially caused by
# combo __setattr__ and __getattr__
self.__dict__["_cim_instance_name"] = cim_instance_name
+ self.__dict__["_lmi_class"] = None
super(LMIInstanceName, self).__init__(conn)
def __cmp__(self, other):
@@ -71,6 +74,10 @@ class LMIInstanceName(LMIWrapperBaseObject):
if isinstance(member, wbem.CIMInstanceName):
member = lmi_transform_to_lmi(self._conn, member)
return member
+ elif not self._conn.is_wsman() and name in self.methods():
+ return lmi_wrap_cim_method(self._conn, name, self)
+ elif self._conn.is_wsman() and not name.startswith("_"):
+ return lmi_wrap_cim_method(self._conn, name, self)
raise AttributeError(name)
def __setattr__(self, name, value):
@@ -434,6 +441,26 @@ class LMIInstanceName(LMIWrapperBaseObject):
return None
return lmi_transform_to_lmi(self._conn, instance)
+ @lmi_instance_name_fetch_lazy()
+ def methods(self):
+ """
+ Returns a list of :py:class:`wbem.CIMInstance` methods' names.
+
+ :returns: list of :py:class:`wbem.CIMInstance` methods' names
+
+ **Usage:** :ref:`instances_methods`.
+ """
+ return self._lmi_class.methods()
+
+ @lmi_instance_name_fetch_lazy()
+ def print_methods(self):
+ """
+ Prints out the list of :py:class:`wbem.CIMInstance` methods' names.
+
+ **Usage:** :ref:`instances_methods`.
+ """
+ self._lmi_class.print_methods()
+
def key_properties(self):
"""
:returns: list of strings of key properties
diff --git a/cli/lmi/shell/LMIMethod.py b/cli/lmi/shell/LMIMethod.py
index 3aea5d6..7b9a316 100644
--- a/cli/lmi/shell/LMIMethod.py
+++ b/cli/lmi/shell/LMIMethod.py
@@ -47,6 +47,7 @@ from lmi.shell.LMIUtil import lmi_get_use_exceptions
from lmi.shell.LMIUtil import lmi_raise_or_dump_exception
from lmi.shell.LMIUtil import lmi_transform_to_cim_param
from lmi.shell.LMIUtil import lmi_transform_to_lmi
+from lmi.shell.LMIUtil import lmi_wrap_cim_class
from lmi.shell.LMIExceptions import *
@@ -141,8 +142,9 @@ class LMIMethod(LMIWrapperBaseObject):
LMI wrapper class representing :py:class:`wbem.CIMMethod`.
:param LMIConnection conn: connection object
- :param LMIInstance lmi_instance: :py:class:`.LMIInstance` object, on which
- the method call will be issued
+ :param LMIInstance(Name) lmi_instance: :py:class:`.LMIInstance` or
+ :py:class:`.LMIInstanceName` object, on which the method call will be
+ issued
:param string method_name: method name
"""
# 15 seconds sleep timeout for main waiting thread
@@ -175,7 +177,11 @@ class LMIMethod(LMIWrapperBaseObject):
def __init__(self, conn, lmi_instance, method_name):
super(LMIMethod, self).__init__(conn)
- self._lmi_instance = lmi_instance.copy()
+ if not isinstance(lmi_instance, (
+ LMIObjectFactory().LMIInstance,
+ LMIObjectFactory().LMIInstanceName)):
+ raise TypeError("lmi_instance must be LMIInstance(Name) type")
+ self._lmi_instance = lmi_instance
self._sync_method = False
self._method = None
self._method_name = method_name
@@ -190,8 +196,17 @@ class LMIMethod(LMIWrapperBaseObject):
self._method_name = method_name[4:]
# We need to have CIMClass with qualifiers. Fetch full class.
- lmi_class = self._lmi_instance._lmi_class
+ if isinstance(self._lmi_instance, LMIObjectFactory().LMIInstance):
+ # LMIInstance
+ lmi_class = self._lmi_instance._lmi_class
+ else:
+ # LMIInstanceName
+ lmi_class = lmi_wrap_cim_class(
+ self._conn,
+ self._lmi_instance.classname,
+ self._lmi_instance.namespace)
lmi_class.fetch(True)
+
self._method = lmi_class._cim_class.methods[self._method_name]
# Store the constant values as a list. This can consume some time, if
@@ -664,12 +679,15 @@ class LMIMethod(LMIWrapperBaseObject):
return LMIReturnValue(rval=-1, errorstr=e.message)
call_rparams = lmi_transform_to_lmi(self._conn, call_rparams)
- # Refresh the instance, within which the method was called
- if refresh_requested and not self._lmi_instance.refresh():
- # NOTE: this is wrong! What should we do?
- errorstr = "Could not update an LMI object after a method call"
- lmi_raise_or_dump_exception(LMIMethodCallError(errorstr))
- return LMIReturnValue(rval=rval, errorstr=errorstr)
+ # Refresh is requested
+ if refresh_requested:
+ # Refresh the instance, within which the method was called
+ ref_rval, _, ref_errorstr = self.__refresh_instance()
+ if not ref_rval:
+ errorstr = "Could not update an LMI object after a method call"
+ lmi_raise_or_dump_exception(LMIMethodCallError(ref_errorstr))
+ return LMIReturnValue(rval=ref_rval, errorstr=ref_errorstr)
+
return LMIReturnValue(
rval=rval, rparams=call_rparams, errorstr=call_errorstr)
@@ -699,6 +717,21 @@ class LMIMethod(LMIWrapperBaseObject):
cond.notify()
cond.release()
+ def __refresh_instance(self):
+ """
+ Refreshes nested :py:class:`.LMIInstance`.
+
+ **NOTE:** This method refreshes only nested :py:class:`.LMIInstance`.
+ Objects of this class may also contain :py:class:`.LMIInstanceName`; in
+ this case, no refreshing is performed.
+
+ :rtype: :py:class:`.LMIReturnValue`
+ """
+ if not isinstance(self._lmi_instance, LMIObjectFactory().LMIInstance):
+ # There is nothing to refresh here.
+ return LMIReturnValue(rval=True)
+ return self._lmi_instance.refresh()
+
def doc(self):
"""
Prints out pretty verbose message with documentation for the class. If
9 years, 9 months
[cura-tools] master: fix typo in LMIInstance docstring (c2b8c6c)
by amahdal@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit c2b8c6cf53496e7d35cf6e138b2aeb3da45c01e7
Author: Alois Mahdal <amahdal(a)redhat.com>
Date: Sun Jul 20 22:34:09 2014 +0200
fix typo in LMIInstance docstring
>---------------------------------------------------------------
cli/lmi/shell/LMIInstance.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/cli/lmi/shell/LMIInstance.py b/cli/lmi/shell/LMIInstance.py
index adbe98c..f478b84 100644
--- a/cli/lmi/shell/LMIInstance.py
+++ b/cli/lmi/shell/LMIInstance.py
@@ -226,7 +226,7 @@ class LMIInstance(LMIWrapperBaseObject):
@lmi_possibly_deleted(None)
def path(self):
"""
- Property returning a :py:class:`LMIInstanceName` objec5.
+ Property returning a :py:class:`LMIInstanceName` object.
**NOTE:** If the method :py:meth:`.LMIInstance.delete` was called, this
method will not execute its code and will return None. If the shell
9 years, 9 months
[cura-tools] master: Revert "drop unnecessary LMICompleter::_callable_postfix()" (280a76a)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 280a76a7a154421078cad026d0b6a4dff395aae5
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Jul 17 15:21:03 2014 +0200
Revert "drop unnecessary LMICompleter::_callable_postfix()"
This reverts commit 9d9b15bc8b4848797ae9f305a365a0b680752466.
>---------------------------------------------------------------
cli/lmi/shell/LMICompleter.py | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/cli/lmi/shell/LMICompleter.py b/cli/lmi/shell/LMICompleter.py
index 8859c5d..b5a117b 100644
--- a/cli/lmi/shell/LMICompleter.py
+++ b/cli/lmi/shell/LMICompleter.py
@@ -40,6 +40,16 @@ class LMICompleter(rlcompleter.Completer):
def __init__(self, namespace=None):
rlcompleter.Completer.__init__(self, namespace)
+ def _callable_postfix(self, val, word):
+ """
+ :param val: object, which is checked, if it is callable
+ :param string word: input string
+ :returns: string with opening parentheses, if the value is callable
+ """
+ if hasattr(val, word) and callable(getattr(val, word)):
+ word = word + "("
+ return word
+
def complete(self, text, state):
"""
:param string text: string to be completed.
9 years, 9 months
[cura-tools] master: drop unnecessary LMICompleter::_callable_postfix() (9d9b15b)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 9d9b15bc8b4848797ae9f305a365a0b680752466
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Jul 17 14:55:35 2014 +0200
drop unnecessary LMICompleter::_callable_postfix()
>---------------------------------------------------------------
cli/lmi/shell/LMICompleter.py | 10 ----------
1 files changed, 0 insertions(+), 10 deletions(-)
diff --git a/cli/lmi/shell/LMICompleter.py b/cli/lmi/shell/LMICompleter.py
index b5a117b..8859c5d 100644
--- a/cli/lmi/shell/LMICompleter.py
+++ b/cli/lmi/shell/LMICompleter.py
@@ -40,16 +40,6 @@ class LMICompleter(rlcompleter.Completer):
def __init__(self, namespace=None):
rlcompleter.Completer.__init__(self, namespace)
- def _callable_postfix(self, val, word):
- """
- :param val: object, which is checked, if it is callable
- :param string word: input string
- :returns: string with opening parentheses, if the value is callable
- """
- if hasattr(val, word) and callable(getattr(val, word)):
- word = word + "("
- return word
-
def complete(self, text, state):
"""
:param string text: string to be completed.
9 years, 9 months
[cura-tools] master: fix LMIInstance::__getattr__() (461e5c2)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 461e5c2f370836d474a26d376f5d45c170b9a1ed
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Jul 17 14:53:14 2014 +0200
fix LMIInstance::__getattr__()
>---------------------------------------------------------------
cli/lmi/shell/LMIInstance.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/cli/lmi/shell/LMIInstance.py b/cli/lmi/shell/LMIInstance.py
index f91a5ba..adbe98c 100644
--- a/cli/lmi/shell/LMIInstance.py
+++ b/cli/lmi/shell/LMIInstance.py
@@ -110,7 +110,7 @@ class LMIInstance(LMIWrapperBaseObject):
return lmi_cast_to_lmi(member.type, member.value)
elif not self._conn.is_wsman() and name in self.methods():
return lmi_wrap_cim_method(self._conn, name, self)
- elif self._conn.is_wsman():
+ elif self._conn.is_wsman() and not name.startswith("_"):
return lmi_wrap_cim_method(self._conn, name, self)
raise AttributeError(name)
9 years, 9 months