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
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
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
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