[cura-tools] 0.9-fixes: Improve lmishell indication documentation (400248e)
by Stephen Gallagher
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : 0.9-fixes
>---------------------------------------------------------------
commit 400248efc1b92873074a3b729114c8fa7435b106
Author: Stephen Gallagher <sgallagh(a)redhat.com>
Date: Tue Nov 26 13:54:19 2013 -0500
Improve lmishell indication documentation
Conflicts:
doc/src/indications.rst
>---------------------------------------------------------------
cli/lmi/shell/LMIIndicationListener.py | 4 ++
doc/src/indications.rst | 84 +++++++++++++++++++++++--------
2 files changed, 66 insertions(+), 22 deletions(-)
diff --git a/cli/lmi/shell/LMIIndicationListener.py b/cli/lmi/shell/LMIIndicationListener.py
index c8647bf..5b76f06 100644
--- a/cli/lmi/shell/LMIIndicationListener.py
+++ b/cli/lmi/shell/LMIIndicationListener.py
@@ -149,6 +149,8 @@ class LMIIndicationListener(object):
"""
Starts a indication listener.
+ The indication listener runs in a newly-created thread.
+
:returns: True, if the indication listener started with no errors; False otherwise
"""
try:
@@ -170,6 +172,8 @@ class LMIIndicationListener(object):
def stop(self):
"""
Stops the indication listener.
+
+ This method will also terminate the listener thread.
"""
if self._server:
self._server.shutdown()
diff --git a/doc/src/indications.rst b/doc/src/indications.rst
index 096d807..6cdcb69 100644
--- a/doc/src/indications.rst
+++ b/doc/src/indications.rst
@@ -1,8 +1,59 @@
Indications
===========
Indication is a reaction to some specific event that occurs in response to a
-change to a particular change in data. LMIShell can perform a indication
-subscription, by which we can receive such event responses.
+particular change in data. LMIShell can perform an indication subscription, by
+which we can receive such event responses.
+
+
+
+Indication handler
+------------------
+The first step is to set up an indication handler. This is a routine that will
+be triggered when the OpenLMI sends us an indication for which we have
+registered (see below). It is important to set up the handler first so that we
+can generate a unique registration name and avoid conflicts with other clients
+that may wish to register for the same indication. The indication handler may
+be part of the same process that will initiate the provider registration or it
+may be an independent script, but the unique registration name must be
+acquired first in either case.
+
+The following example describes creating a handler and a listener for an
+indication:
+
+.. code-block:: python
+
+ > def handler(ind, arg1, arg2, **kwargs):
+ ... exported_objects = ind.exported_objects()
+ ... do_something_with(exported_objects)
+ > listener = LMIIndicationListener("0.0.0.0", listening_port)
+ > unique_name = listener.add_handler("indication-name-XXXXXXXX", handler, arg1, arg2, **kwargs)
+ > listener.start()
+ >
+
+The first argument of the handler is an :py:class:`LMIIndication` object,
+which contains the list of methods and objects exported by the indication.
+The other arguments are handler-specific; Any number of arguments may be
+specified as necessary; those arguments must then be provided to the
+:py:meth:`.LMIIndicationListener.add_handler` method of the listener. In the
+above example, the string used in the
+:py:meth:`.LMIIndicationListener.add_handler` call is specified with eight
+**"X"** characters. Those characters will be replaced by unique string, which
+is generated by the listeners to avoid a handler name clash. Use of this
+uniqueness capability is not mandatory but is highly recommended. The
+substituted name is returned as the result of the
+:py:meth:`.LMIIndicationListener.add_handler` method so it can be used later.
+
+The :py:class:`LMIIndicationListener` constructor takes up to four
+arguments, two mandatory (hostname and port) and two optional when using SSL
+(certfile and keyfile). It returns an :py:class:`LMIIndicationListener`
+object.
+
+The :py:meth:`.LMIIndicationListener.start` method creates a new thread and
+runs an HTTP service in that thread, awaiting indications from the CIMOM. This
+method will continue to run until :py:meth:`.LMIIndicationListener.stop` is
+called or the current application exits.
+
+
Subscribing to an indication
----------------------------
@@ -18,7 +69,7 @@ How to subscribe to an indication, please, follow the next example:
> c.subscribe_indication(
... QueryLanguage="WQL",
... Query='SELECT * FROM CIM_InstModification',
- ... Name="cpu",
+ ... Name=unique_name,
... CreationNamespace="root/interop",
... SubscriptionCreationClassName="CIM_IndicationSubscription",
... FilterCreationClassName="CIM_IndicationFilter",
@@ -27,7 +78,7 @@ How to subscribe to an indication, please, follow the next example:
... HandlerCreationClassName="CIM_IndicationHandlerCIMXML",
... HandlerSystemCreationClassName="CIM_ComputerSystem",
... # destination computer, where the indications will be delivered
- ... Destination="http://192.168.122.1:5988"
+ ... Destination="http://192.168.122.1:%d" % listening_port
... )
LMIReturnValue(rval=True, rparams={}, errorstr="")
>
@@ -55,38 +106,27 @@ To list all the subscribed indications, run following code:
> subscribed_ind_lst = c.subscribed_indications()
>
-Unsubscribing from an indications
+Unsubscribing from an indication
---------------------------------
By default, the subscriptions created by the shell are auto-deleted, when the
shell quits.
-If you want to delete the subscriptions sooner, you can use following methods:
+If you want to delete the subscriptions sooner, you can use the following methods:
+
+To unsubscribe from a specific indication:
.. code-block:: python
- > c.unsubscribe_indication(indication_name)
+ > c.unsubscribe_indication(unique_name)
LMIReturnValue(rval=True, rparams={}, errorstr="")
> c.unsubscribe_all_indications()
>
-Indication handler
-------------------
-In the previous example, there is a local computer specified (the one, which
-runs the shell), now we need to start a indication listener with our indication
-handler function defined. This example continues (see previous one). It is also
-possible to start another shell, script and start the indication listener
-there.
-
-See the following example:
+Or to unsubscribe from all indications:
.. code-block:: python
- > def handler(ind, arg1, arg2, **kwargs):
- ... exported_objects = ind.exported_objects()
- ... do_something_with(exported_objects)
- > listener = LMIIndicationListener("0.0.0.0", listening_port)
- > listener.add_handler("indication-name-XXXXXXXX", handler, arg1, arg2, **kwargs)
- > listener.start()
+ > c.unsubscribe_all_indications()
>
The first argument of the handler is :py:class:`LMIIndication` object, which
10 years, 5 months
[cura-tools] master: Improve lmishell indication documentation (7ee33e3)
by Stephen Gallagher
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 7ee33e3a956b3d4e171a5de53a4e246f09f32ac1
Author: Stephen Gallagher <sgallagh(a)redhat.com>
Date: Tue Nov 26 13:54:19 2013 -0500
Improve lmishell indication documentation
>---------------------------------------------------------------
cli/lmi/shell/LMIIndicationListener.py | 4 +
doc/src/indications.rst | 99 ++++++++++++++++++++------------
2 files changed, 67 insertions(+), 36 deletions(-)
diff --git a/cli/lmi/shell/LMIIndicationListener.py b/cli/lmi/shell/LMIIndicationListener.py
index c8647bf..5b76f06 100644
--- a/cli/lmi/shell/LMIIndicationListener.py
+++ b/cli/lmi/shell/LMIIndicationListener.py
@@ -149,6 +149,8 @@ class LMIIndicationListener(object):
"""
Starts a indication listener.
+ The indication listener runs in a newly-created thread.
+
:returns: True, if the indication listener started with no errors; False otherwise
"""
try:
@@ -170,6 +172,8 @@ class LMIIndicationListener(object):
def stop(self):
"""
Stops the indication listener.
+
+ This method will also terminate the listener thread.
"""
if self._server:
self._server.shutdown()
diff --git a/doc/src/indications.rst b/doc/src/indications.rst
index d29a77d..50f8730 100644
--- a/doc/src/indications.rst
+++ b/doc/src/indications.rst
@@ -1,8 +1,59 @@
Indications
===========
Indication is a reaction to some specific event that occurs in response to a
-change to a particular change in data. LMIShell can perform a indication
-subscription, by which we can receive such event responses.
+particular change in data. LMIShell can perform an indication subscription, by
+which we can receive such event responses.
+
+
+
+Indication handler
+------------------
+The first step is to set up an indication handler. This is a routine that will
+be triggered when the OpenLMI sends us an indication for which we have
+registered (see below). It is important to set up the handler first so that we
+can generate a unique registration name and avoid conflicts with other clients
+that may wish to register for the same indication. The indication handler may
+be part of the same process that will initiate the provider registration or it
+may be an independent script, but the unique registration name must be
+acquired first in either case.
+
+The following example describes creating a handler and a listener for an
+indication:
+
+.. code-block:: python
+
+ > def handler(ind, arg1, arg2, **kwargs):
+ ... exported_objects = ind.exported_objects()
+ ... do_something_with(exported_objects)
+ > listener = LMIIndicationListener("0.0.0.0", listening_port)
+ > unique_name = listener.add_handler("indication-name-XXXXXXXX", handler, arg1, arg2, **kwargs)
+ > listener.start()
+ >
+
+The first argument of the handler is an :py:class:`LMIIndication` object,
+which contains the list of methods and objects exported by the indication.
+The other arguments are handler-specific; Any number of arguments may be
+specified as necessary; those arguments must then be provided to the
+:py:meth:`.LMIIndicationListener.add_handler` method of the listener. In the
+above example, the string used in the
+:py:meth:`.LMIIndicationListener.add_handler` call is specified with eight
+**"X"** characters. Those characters will be replaced by unique string, which
+is generated by the listeners to avoid a handler name clash. Use of this
+uniqueness capability is not mandatory but is highly recommended. The
+substituted name is returned as the result of the
+:py:meth:`.LMIIndicationListener.add_handler` method so it can be used later.
+
+The :py:class:`LMIIndicationListener` constructor takes up to four
+arguments, two mandatory (hostname and port) and two optional when using SSL
+(certfile and keyfile). It returns an :py:class:`LMIIndicationListener`
+object.
+
+The :py:meth:`.LMIIndicationListener.start` method creates a new thread and
+runs an HTTP service in that thread, awaiting indications from the CIMOM. This
+method will continue to run until :py:meth:`.LMIIndicationListener.stop` is
+called or the current application exits.
+
+
Subscribing to an indication
----------------------------
@@ -18,7 +69,7 @@ How to subscribe to an indication, please, follow the next example:
> c.subscribe_indication(
... QueryLanguage="WQL",
... Query='SELECT * FROM CIM_InstModification',
- ... Name="cpu",
+ ... Name=unique_name,
... CreationNamespace="root/interop",
... SubscriptionCreationClassName="CIM_IndicationSubscription",
... FilterCreationClassName="CIM_IndicationFilter",
@@ -27,7 +78,7 @@ How to subscribe to an indication, please, follow the next example:
... HandlerCreationClassName="CIM_IndicationHandlerCIMXML",
... HandlerSystemCreationClassName="CIM_ComputerSystem",
... # destination computer, where the indications will be delivered
- ... Destination="http://192.168.122.1:5988"
+ ... Destination="http://192.168.122.1:%d" % listening_port
... )
LMIReturnValue(rval=True, rparams={}, errorstr="")
>
@@ -49,7 +100,7 @@ Simplified subscription:
> c = connect("host", "privileged_user", "password")
> c.subscribe_indication(
- ... Name="cpu",
+ ... Name=unique_name,
... Query='SELECT * FROM CIM_InstModification',
... Destination="http://192.168.122.1:5988"
... )
@@ -79,47 +130,23 @@ To list all the subscribed indications, run following code:
> subscribed_ind_lst = c.subscribed_indications()
>
-Unsubscribing from an indications
+Unsubscribing from an indication
---------------------------------
By default, the subscriptions created by the shell are auto-deleted, when the
shell quits.
-If you want to delete the subscriptions sooner, you can use following methods:
+If you want to delete the subscriptions sooner, you can use the following methods:
+
+To unsubscribe from a specific indication:
.. code-block:: python
- > c.unsubscribe_indication(indication_name)
+ > c.unsubscribe_indication(unique_name)
LMIReturnValue(rval=True, rparams={}, errorstr="")
- > c.unsubscribe_all_indications()
- >
-
-Indication handler
-------------------
-In the previous example, there is a local computer specified (the one, which
-runs the shell), now we need to start a indication listener with our indication
-handler function defined. This example continues (see previous one). It is also
-possible to start another shell, script and start the indication listener
-there.
-See the following example:
+Or to unsubscribe from all indications:
.. code-block:: python
- > def handler(ind, arg1, arg2, **kwargs):
- ... exported_objects = ind.exported_objects()
- ... do_something_with(exported_objects)
- > listener = LMIIndicationListener("0.0.0.0", listening_port)
- > listener.add_handler("indication-name-XXXXXXXX", handler, arg1, arg2, **kwargs)
- > listener.start()
+ > c.unsubscribe_all_indications()
>
-
-The first argument of the handler is :py:class:`LMIIndication` object, which
-contains list of methods and objects exported by the indication. Other
-parameters are user specific; those arguments need to be specified, when adding
-a handler to the listener. In the example, there is a special string used in
-the :py:meth:`.LMIIndicationListener.add_handler` call; note the eight **"X"**
-characters. Those characters will be replaced by random string, which is
-generated by the listeners to avoid handler name clash. If you want to use that
-random-based string, start indication listener first, then subscribe to an
-indication, so the *Destination* property of a handler object contains
-``<schema>://<hostname>/<random-based string>``.
10 years, 5 months
[cura-tools] 0.9-fixes: fix indication unique name (7676efe)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : 0.9-fixes
>---------------------------------------------------------------
commit 7676efe4f84c34121277826a4ea9488762924f9e
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Dec 6 13:30:00 2013 +0100
fix indication unique name
>---------------------------------------------------------------
cli/lmi/shell/LMIIndicationListener.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/cli/lmi/shell/LMIIndicationListener.py b/cli/lmi/shell/LMIIndicationListener.py
index 4f70e77..c8647bf 100644
--- a/cli/lmi/shell/LMIIndicationListener.py
+++ b/cli/lmi/shell/LMIIndicationListener.py
@@ -137,7 +137,7 @@ class LMIIndicationListener(object):
while True:
while handler_name_pattern[pattern_len - 1 - x_cnt] == "X":
x_cnt += 1
- if x_cnt < LMIIndicationListener.HANDLER_MINIMUM_REPL_CHARS_COUNT:
+ if x_cnt and x_cnt < LMIIndicationListener.HANDLER_MINIMUM_REPL_CHARS_COUNT:
raise LMIHandlerNamePatternError("Not enough replaceable characters provided")
unique_str = handler_name_pattern[:pattern_len - x_cnt] + \
"".join(random.choice(string.ascii_uppercase + string.digits) for x in range(x_cnt))
@@ -219,7 +219,7 @@ class LMIIndicationListener(object):
:returns: handler unique name
:rtype: string
"""
- handler_name = self.__create_handler_name(handler_name_pattern + "X" * 16)
+ handler_name = self.__create_handler_name(handler_name_pattern)
self._handlers[handler_name] = LMIIndicationHandlerCallback(handler, *args, **kwargs)
return handler_name
10 years, 5 months
[cura-tools] master: fix indication unique name (99badf7)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 99badf76124fab972309c7b64c432a37c71cc99a
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Dec 6 13:30:00 2013 +0100
fix indication unique name
>---------------------------------------------------------------
cli/lmi/shell/LMIIndicationListener.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/cli/lmi/shell/LMIIndicationListener.py b/cli/lmi/shell/LMIIndicationListener.py
index 4f70e77..c8647bf 100644
--- a/cli/lmi/shell/LMIIndicationListener.py
+++ b/cli/lmi/shell/LMIIndicationListener.py
@@ -137,7 +137,7 @@ class LMIIndicationListener(object):
while True:
while handler_name_pattern[pattern_len - 1 - x_cnt] == "X":
x_cnt += 1
- if x_cnt < LMIIndicationListener.HANDLER_MINIMUM_REPL_CHARS_COUNT:
+ if x_cnt and x_cnt < LMIIndicationListener.HANDLER_MINIMUM_REPL_CHARS_COUNT:
raise LMIHandlerNamePatternError("Not enough replaceable characters provided")
unique_str = handler_name_pattern[:pattern_len - x_cnt] + \
"".join(random.choice(string.ascii_uppercase + string.digits) for x in range(x_cnt))
@@ -219,7 +219,7 @@ class LMIIndicationListener(object):
:returns: handler unique name
:rtype: string
"""
- handler_name = self.__create_handler_name(handler_name_pattern + "X" * 16)
+ handler_name = self.__create_handler_name(handler_name_pattern)
self._handlers[handler_name] = LMIIndicationHandlerCallback(handler, *args, **kwargs)
return handler_name
10 years, 5 months
[cura-tools] 0.9-fixes: fix blocking when receiving indication (8d75906)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : 0.9-fixes
>---------------------------------------------------------------
commit 8d75906abdb6f5f8128e12dba0a4db019566e3d4
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Dec 6 09:02:25 2013 +0100
fix blocking when receiving indication
>---------------------------------------------------------------
cli/lmi/shell/LMIIndicationListener.py | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/cli/lmi/shell/LMIIndicationListener.py b/cli/lmi/shell/LMIIndicationListener.py
index cc48b9b..4f70e77 100644
--- a/cli/lmi/shell/LMIIndicationListener.py
+++ b/cli/lmi/shell/LMIIndicationListener.py
@@ -62,7 +62,12 @@ class LMIIndicationHandler(ThreadingMixIn, BaseHTTPRequestHandler):
where the ``indication_name`` is a string, which properly defines the indication.
"""
- msg = self.rfile.read()
+ # If HTTP/1.1 used, try to get a message body length. If Content-Length header is
+ # not present, set length to -1; rfile.read() will block, until the connection is
+ # closed. Knowing the exact content length makes the routine to finish early, even
+ # if the TCP connection is not closed.
+ length = int(self.headers.get("Content-Length", "-1"))
+ msg = self.rfile.read(length)
tt = pywbem.parse_cim(pywbem.xml_to_tupletree(msg))
message = tt[2]
export_methods = {}
10 years, 5 months
[cura-tools] master: fix blocking when receiving indication (05c0480)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 05c0480c427278eafed77eeab4d7d4088fa4b3e5
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Dec 6 09:02:25 2013 +0100
fix blocking when receiving indication
>---------------------------------------------------------------
cli/lmi/shell/LMIIndicationListener.py | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/cli/lmi/shell/LMIIndicationListener.py b/cli/lmi/shell/LMIIndicationListener.py
index cc48b9b..4f70e77 100644
--- a/cli/lmi/shell/LMIIndicationListener.py
+++ b/cli/lmi/shell/LMIIndicationListener.py
@@ -62,7 +62,12 @@ class LMIIndicationHandler(ThreadingMixIn, BaseHTTPRequestHandler):
where the ``indication_name`` is a string, which properly defines the indication.
"""
- msg = self.rfile.read()
+ # If HTTP/1.1 used, try to get a message body length. If Content-Length header is
+ # not present, set length to -1; rfile.read() will block, until the connection is
+ # closed. Knowing the exact content length makes the routine to finish early, even
+ # if the TCP connection is not closed.
+ length = int(self.headers.get("Content-Length", "-1"))
+ msg = self.rfile.read(length)
tt = pywbem.parse_cim(pywbem.xml_to_tupletree(msg))
message = tt[2]
export_methods = {}
10 years, 5 months
[cura-tools] 0.9-fixes: fix compulsory call order of LMIIndicationListener::start(), ::is_alive, ::stop() (2c4238d)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : 0.9-fixes
>---------------------------------------------------------------
commit 2c4238d2346c8bc6503cb5ce41dcbfe48871e5bb
Author: Peter Hatina <phatina(a)redhat.com>
Date: Wed Dec 4 10:44:35 2013 +0100
fix compulsory call order of LMIIndicationListener::start(), ::is_alive, ::stop()
>---------------------------------------------------------------
cli/lmi/shell/LMIIndicationListener.py | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/cli/lmi/shell/LMIIndicationListener.py b/cli/lmi/shell/LMIIndicationListener.py
index 1ec2f21..cc48b9b 100644
--- a/cli/lmi/shell/LMIIndicationListener.py
+++ b/cli/lmi/shell/LMIIndicationListener.py
@@ -115,6 +115,9 @@ class LMIIndicationListener(object):
self._certfile = certfile
self._keyfile = keyfile
+ self._server = None
+ self._server_thread = None
+
def __create_handler_name(self, handler_name_pattern):
"""
Returns unique handler name by replacing "**X**" characters for random characters
@@ -163,8 +166,12 @@ class LMIIndicationListener(object):
"""
Stops the indication listener.
"""
- self._server.shutdown()
- self._server_thread.join()
+ if self._server:
+ self._server.shutdown()
+ if self._server_thread:
+ self._server_thread.join()
+ self._server = None
+ self._server_thread = None
@property
def is_alive(self):
@@ -172,7 +179,9 @@ class LMIIndicationListener(object):
:returns: flag indicating, if the indication listener is running
:rtype: bool
"""
- return self._server_thread.is_alive()
+ if self._server_thread:
+ return self._server_thread.is_alive()
+ return False
@property
def hostname(self):
10 years, 5 months
[cura-tools] master: fix compulsory call order of LMIIndicationListener::start(), ::is_alive, ::stop() (80e7ff2)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 80e7ff24926e96f855913972f383cd5cb3c7530e
Author: Peter Hatina <phatina(a)redhat.com>
Date: Wed Dec 4 10:44:35 2013 +0100
fix compulsory call order of LMIIndicationListener::start(), ::is_alive, ::stop()
>---------------------------------------------------------------
cli/lmi/shell/LMIIndicationListener.py | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/cli/lmi/shell/LMIIndicationListener.py b/cli/lmi/shell/LMIIndicationListener.py
index 1ec2f21..cc48b9b 100644
--- a/cli/lmi/shell/LMIIndicationListener.py
+++ b/cli/lmi/shell/LMIIndicationListener.py
@@ -115,6 +115,9 @@ class LMIIndicationListener(object):
self._certfile = certfile
self._keyfile = keyfile
+ self._server = None
+ self._server_thread = None
+
def __create_handler_name(self, handler_name_pattern):
"""
Returns unique handler name by replacing "**X**" characters for random characters
@@ -163,8 +166,12 @@ class LMIIndicationListener(object):
"""
Stops the indication listener.
"""
- self._server.shutdown()
- self._server_thread.join()
+ if self._server:
+ self._server.shutdown()
+ if self._server_thread:
+ self._server_thread.join()
+ self._server = None
+ self._server_thread = None
@property
def is_alive(self):
@@ -172,7 +179,9 @@ class LMIIndicationListener(object):
:returns: flag indicating, if the indication listener is running
:rtype: bool
"""
- return self._server_thread.is_alive()
+ if self._server_thread:
+ return self._server_thread.is_alive()
+ return False
@property
def hostname(self):
10 years, 5 months
[cura-tools] 0.9-fixes: use interactive connect() when script run with -i (8405c92)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : 0.9-fixes
>---------------------------------------------------------------
commit 8405c925f4110d45b7cd6ffb3d7afe45442c2454
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Dec 3 09:50:32 2013 +0100
use interactive connect() when script run with -i
>---------------------------------------------------------------
cli/lmi/shell/LMIConsole.py | 16 +++++++++++-----
cli/lmishell | 8 ++++++--
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/cli/lmi/shell/LMIConsole.py b/cli/lmi/shell/LMIConsole.py
index 21238e2..f1c9c4f 100644
--- a/cli/lmi/shell/LMIConsole.py
+++ b/cli/lmi/shell/LMIConsole.py
@@ -118,6 +118,7 @@ class LMIConsole(code.InteractiveConsole):
* **cert_file** (*string*) -- path to x509 cert file; default value is None
* **verify_server_cert** (*bool*) -- tells, if the server side certificate
needs to be verified, if SSL used; default value is True
+ * **prompt_prefix** (*string*) -- used for username/password prompt
:returns: connection object
:rtype: :py:class:`LMIConnection`
@@ -125,12 +126,13 @@ class LMIConsole(code.InteractiveConsole):
key_file = kwargs.pop("key_file", None)
cert_file = kwargs.pop("cert_file", None)
verify_server_cert = kwargs.pop("verify_server_cert", self._verify_server_cert)
+ prompt_prefix = kwargs.pop("propmpt_prefix", "")
if kwargs:
raise TypeError("connect() got an unexpected keyword arguments: %s" % ", ".join(kwargs.keys()))
return connect_internal(uri, username, password, interactive=True,
use_cache=self._use_cache, key_file=key_file, cert_file=cert_file,
- verify_server_cert=verify_server_cert)
+ verify_server_cert=verify_server_cert, prompt_prefix=prompt_prefix)
# Initialize the interpreter
if locals is None:
@@ -187,7 +189,7 @@ class LMIConsole(code.InteractiveConsole):
sys.ps2 = old_sys_ps2
self.save_history()
- def interpret(self, script_name, script_argv, locals=None):
+ def interpret(self, script_name, script_argv, locals=None, interactive=False):
"""
Interprets a specified script within additional provided locals.
There are :py:attr:`LMIConsole.DEFAULT_LOCALS` present.
@@ -195,10 +197,12 @@ class LMIConsole(code.InteractiveConsole):
:param string script_name: script name
:param list script_argv: script CLI arguments
:param dictionary locals: dictionary with locals
+ :param bool interactive: tells LMIShell, if the script should be treated
+ as if it was run in interactive mode
:returns: exit code of the script
:rtype: int
"""
- # Helper function for non-interactive connect
+ # Helper function for LMIShell's scripts
def connect(uri, username="", password="", **kwargs):
"""
Returns :py:class:`LMIConnection` object with provided URI and credentials.
@@ -212,6 +216,7 @@ class LMIConsole(code.InteractiveConsole):
* **cert_file** (*string*) -- path to x509 cert file; default value is None
* **verify_server_cert** (*bool*) -- tells, if the server side certificate
needs to be verified, if SSL used; default value is True
+ * **prompt_prefix** (*string*) -- used for username/password prompt
:returns: connection object
:rtype: :py:class:`LMIConnection`
@@ -220,12 +225,13 @@ class LMIConsole(code.InteractiveConsole):
key_file = kwargs.pop("key_file", None)
cert_file = kwargs.pop("cert_file", None)
verify_server_cert = kwargs.pop("verify_server_cert", self._verify_server_cert)
+ prompt_prefix = kwargs.pop("prompt_prefix", "")
if kwargs:
raise TypeError("connect() got an unexpected keyword arguments: %s" % ", ".join(kwargs.keys()))
- return connect_internal(uri, username, password, interactive=False,
+ return connect_internal(uri, username, password, interactive=interactive,
use_cache=self._use_cache, key_file=key_file, cert_file=cert_file,
- verify_server_cert=verify_server_cert)
+ verify_server_cert=verify_server_cert, prompt_prefix=prompt_prefix)
# Initialize locals
if locals is None:
locals = {}
diff --git a/cli/lmishell b/cli/lmishell
index aaa8f7b..433d413 100755
--- a/cli/lmishell
+++ b/cli/lmishell
@@ -47,8 +47,12 @@ if __name__ == "__main__":
else:
script_name = options.script_name
script_argv = options.script_argv
- exit_code = console.interpret(script_name, script_argv)
- if options.interact:
+ interactive = options.interact
+ exit_code = console.interpret(
+ script_name,
+ script_argv,
+ interactive=interactive)
+ if interactive:
console.interact(console.locals)
else:
sys.exit(exit_code)
10 years, 5 months
[cura-tools] master: use interactive connect() when script run with -i (fce05b3)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit fce05b3627cab3ad557067e2e855c198857a6f57
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Dec 3 09:50:32 2013 +0100
use interactive connect() when script run with -i
>---------------------------------------------------------------
cli/lmi/shell/LMIConsole.py | 16 +++++++++++-----
cli/lmishell | 8 ++++++--
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/cli/lmi/shell/LMIConsole.py b/cli/lmi/shell/LMIConsole.py
index 21238e2..f1c9c4f 100644
--- a/cli/lmi/shell/LMIConsole.py
+++ b/cli/lmi/shell/LMIConsole.py
@@ -118,6 +118,7 @@ class LMIConsole(code.InteractiveConsole):
* **cert_file** (*string*) -- path to x509 cert file; default value is None
* **verify_server_cert** (*bool*) -- tells, if the server side certificate
needs to be verified, if SSL used; default value is True
+ * **prompt_prefix** (*string*) -- used for username/password prompt
:returns: connection object
:rtype: :py:class:`LMIConnection`
@@ -125,12 +126,13 @@ class LMIConsole(code.InteractiveConsole):
key_file = kwargs.pop("key_file", None)
cert_file = kwargs.pop("cert_file", None)
verify_server_cert = kwargs.pop("verify_server_cert", self._verify_server_cert)
+ prompt_prefix = kwargs.pop("propmpt_prefix", "")
if kwargs:
raise TypeError("connect() got an unexpected keyword arguments: %s" % ", ".join(kwargs.keys()))
return connect_internal(uri, username, password, interactive=True,
use_cache=self._use_cache, key_file=key_file, cert_file=cert_file,
- verify_server_cert=verify_server_cert)
+ verify_server_cert=verify_server_cert, prompt_prefix=prompt_prefix)
# Initialize the interpreter
if locals is None:
@@ -187,7 +189,7 @@ class LMIConsole(code.InteractiveConsole):
sys.ps2 = old_sys_ps2
self.save_history()
- def interpret(self, script_name, script_argv, locals=None):
+ def interpret(self, script_name, script_argv, locals=None, interactive=False):
"""
Interprets a specified script within additional provided locals.
There are :py:attr:`LMIConsole.DEFAULT_LOCALS` present.
@@ -195,10 +197,12 @@ class LMIConsole(code.InteractiveConsole):
:param string script_name: script name
:param list script_argv: script CLI arguments
:param dictionary locals: dictionary with locals
+ :param bool interactive: tells LMIShell, if the script should be treated
+ as if it was run in interactive mode
:returns: exit code of the script
:rtype: int
"""
- # Helper function for non-interactive connect
+ # Helper function for LMIShell's scripts
def connect(uri, username="", password="", **kwargs):
"""
Returns :py:class:`LMIConnection` object with provided URI and credentials.
@@ -212,6 +216,7 @@ class LMIConsole(code.InteractiveConsole):
* **cert_file** (*string*) -- path to x509 cert file; default value is None
* **verify_server_cert** (*bool*) -- tells, if the server side certificate
needs to be verified, if SSL used; default value is True
+ * **prompt_prefix** (*string*) -- used for username/password prompt
:returns: connection object
:rtype: :py:class:`LMIConnection`
@@ -220,12 +225,13 @@ class LMIConsole(code.InteractiveConsole):
key_file = kwargs.pop("key_file", None)
cert_file = kwargs.pop("cert_file", None)
verify_server_cert = kwargs.pop("verify_server_cert", self._verify_server_cert)
+ prompt_prefix = kwargs.pop("prompt_prefix", "")
if kwargs:
raise TypeError("connect() got an unexpected keyword arguments: %s" % ", ".join(kwargs.keys()))
- return connect_internal(uri, username, password, interactive=False,
+ return connect_internal(uri, username, password, interactive=interactive,
use_cache=self._use_cache, key_file=key_file, cert_file=cert_file,
- verify_server_cert=verify_server_cert)
+ verify_server_cert=verify_server_cert, prompt_prefix=prompt_prefix)
# Initialize locals
if locals is None:
locals = {}
diff --git a/cli/lmishell b/cli/lmishell
index aaa8f7b..433d413 100755
--- a/cli/lmishell
+++ b/cli/lmishell
@@ -47,8 +47,12 @@ if __name__ == "__main__":
else:
script_name = options.script_name
script_argv = options.script_argv
- exit_code = console.interpret(script_name, script_argv)
- if options.interact:
+ interactive = options.interact
+ exit_code = console.interpret(
+ script_name,
+ script_argv,
+ interactive=interactive)
+ if interactive:
console.interact(console.locals)
else:
sys.exit(exit_code)
10 years, 5 months