summaryrefslogtreecommitdiffstats
path: root/openstack/common
diff options
context:
space:
mode:
Diffstat (limited to 'openstack/common')
-rw-r--r--openstack/common/cfg.py22
-rw-r--r--openstack/common/processutils.py43
-rw-r--r--openstack/common/rpc/dispatcher.py10
-rw-r--r--openstack/common/threadgroup.py24
-rw-r--r--openstack/common/utils.py4
-rw-r--r--openstack/common/wsgi.py6
6 files changed, 62 insertions, 47 deletions
diff --git a/openstack/common/cfg.py b/openstack/common/cfg.py
index af03f10..e967c61 100644
--- a/openstack/common/cfg.py
+++ b/openstack/common/cfg.py
@@ -211,7 +211,7 @@ Options may be declared as required so that an error is raised if the user
does not supply a value for the option.
Options may be declared as secret so that their values are not leaked into
-log files:
+log files::
opts = [
cfg.StrOpt('s3_store_access_key', secret=True),
@@ -220,20 +220,20 @@ log files:
]
This module also contains a global instance of the CommonConfigOpts class
-in order to support a common usage pattern in OpenStack:
+in order to support a common usage pattern in OpenStack::
- from openstack.common import cfg
+ from openstack.common import cfg
- opts = [
- cfg.StrOpt('bind_host', default='0.0.0.0'),
- cfg.IntOpt('bind_port', default=9292),
- ]
+ opts = [
+ cfg.StrOpt('bind_host', default='0.0.0.0'),
+ cfg.IntOpt('bind_port', default=9292),
+ ]
- CONF = cfg.CONF
- CONF.register_opts(opts)
+ CONF = cfg.CONF
+ CONF.register_opts(opts)
- def start(server, app):
- server.start(app, CONF.bind_port, CONF.bind_host)
+ def start(server, app):
+ server.start(app, CONF.bind_port, CONF.bind_host)
"""
diff --git a/openstack/common/processutils.py b/openstack/common/processutils.py
index a21db01..578a660 100644
--- a/openstack/common/processutils.py
+++ b/openstack/common/processutils.py
@@ -51,22 +51,33 @@ class ProcessExecutionError(Exception):
def execute(*cmd, **kwargs):
"""
- Helper method to execute command with optional retry.
-
- :cmd Passed to subprocess.Popen.
- :process_input Send to opened process.
- :check_exit_code Defaults to 0. Raise executils.ProcessExecutionError
- unless program exits with this code.
- :delay_on_retry True | False. Defaults to True. If set to True, wait a
- short amount of time before retrying.
- :attempts How many times to retry cmd.
- :run_as_root True | False. Defaults to False. If set to True,
- the command is prefixed by the command specified
- in the root_helper kwarg.
- :root_helper command to prefix all cmd's with
-
- :raises executils.UnknownArgumentError on receiving unknown arguments
- :raises executils.ProcessExecutionError
+ Helper method to shell out and execute a command through subprocess with
+ optional retry.
+
+ :param cmd: Passed to subprocess.Popen.
+ :type cmd: string
+ :param process_input: Send to opened process.
+ :type proces_input: string
+ :param check_exit_code: Defaults to 0. Will raise
+ :class:`ProcessExecutionError`
+ if the command exits without returning this value
+ as a returncode
+ :type check_exit_code: int
+ :param delay_on_retry: True | False. Defaults to True. If set to True,
+ wait a short amount of time before retrying.
+ :type delay_on_retry: boolean
+ :param attempts: How many times to retry cmd.
+ :type attempts: int
+ :param run_as_root: True | False. Defaults to False. If set to True,
+ the command is prefixed by the command specified
+ in the root_helper kwarg.
+ :type run_as_root: boolean
+ :param root_helper: command to prefix all cmd's with
+ :type root_helper: string
+ :returns: (stdout, stderr) from process execution
+ :raises: :class:`UnknownArgumentError` on
+ receiving unknown arguments
+ :raises: :class:`ProcessExecutionError`
"""
process_input = kwargs.pop('process_input', None)
diff --git a/openstack/common/rpc/dispatcher.py b/openstack/common/rpc/dispatcher.py
index 965aedc..f09879c 100644
--- a/openstack/common/rpc/dispatcher.py
+++ b/openstack/common/rpc/dispatcher.py
@@ -41,8 +41,8 @@ server side of the API at the same time. However, as the code stands today,
there can be both versioned and unversioned APIs implemented in the same code
base.
-
-EXAMPLES:
+EXAMPLES
+========
Nova was the first project to use versioned rpc APIs. Consider the compute rpc
API as an example. The client side is in nova/compute/rpcapi.py and the server
@@ -50,12 +50,13 @@ side is in nova/compute/manager.py.
Example 1) Adding a new method.
+-------------------------------
Adding a new method is a backwards compatible change. It should be added to
nova/compute/manager.py, and RPC_API_VERSION should be bumped from X.Y to
X.Y+1. On the client side, the new method in nova/compute/rpcapi.py should
have a specific version specified to indicate the minimum API version that must
-be implemented for the method to be supported. For example:
+be implemented for the method to be supported. For example::
def get_host_uptime(self, ctxt, host):
topic = _compute_topic(self.topic, ctxt, host, None)
@@ -67,10 +68,11 @@ get_host_uptime() method.
Example 2) Adding a new parameter.
+----------------------------------
Adding a new parameter to an rpc method can be made backwards compatible. The
RPC_API_VERSION on the server side (nova/compute/manager.py) should be bumped.
-The implementation of the method must not expect the parameter to be present.
+The implementation of the method must not expect the parameter to be present.::
def some_remote_method(self, arg1, arg2, newarg=None):
# The code needs to deal with newarg=None for cases
diff --git a/openstack/common/threadgroup.py b/openstack/common/threadgroup.py
index f6fe50e..27b3c4c 100644
--- a/openstack/common/threadgroup.py
+++ b/openstack/common/threadgroup.py
@@ -27,19 +27,17 @@ LOG = logging.getLogger(__name__)
def _thread_done(gt, *args, **kwargs):
- '''
- Callback function to be passed to GreenThread.link() when we spawn()
- Calls the ThreadGroup to notify if.
- '''
+ """ Callback function to be passed to GreenThread.link() when we spawn()
+ Calls the :class:`ThreadGroup` to notify if.
+
+ """
kwargs['group'].thread_done(kwargs['thread'])
class Thread(object):
- """
- Wrapper around a greenthread, that holds a reference to
- the ThreadGroup. The Thread will notify the ThreadGroup
- when it has done so it can be removed from the threads
- list.
+ """ Wrapper around a greenthread, that holds a reference to the
+ :class:`ThreadGroup`. The Thread will notify the :class:`ThreadGroup` when
+ it has done so it can be removed from the threads list.
"""
def __init__(self, name, thread, group):
self.name = name
@@ -54,11 +52,11 @@ class Thread(object):
class ThreadGroup(object):
- """
- The point of this class is to:
- - keep track of timers and greenthreads (making it easier to stop them
+ """ The point of the ThreadGroup classis to:
+
+ * keep track of timers and greenthreads (making it easier to stop them
when need be).
- - provide an easy API to add timers.
+ * provide an easy API to add timers.
"""
def __init__(self, name, thread_pool_size=10):
self.name = name
diff --git a/openstack/common/utils.py b/openstack/common/utils.py
index dce62c1..e5e04ba 100644
--- a/openstack/common/utils.py
+++ b/openstack/common/utils.py
@@ -38,7 +38,9 @@ def int_from_bool_as_string(subject):
Interpret a string as a boolean and return either 1 or 0.
Any string value in:
+
('True', 'true', 'On', 'on', '1')
+
is interpreted as a boolean True.
Useful for JSON-decoded stuff and config file parsing
@@ -51,7 +53,9 @@ def bool_from_string(subject):
Interpret a string as a boolean.
Any string value in:
+
('True', 'true', 'On', 'on', 'Yes', 'yes', '1')
+
is interpreted as a boolean True.
Useful for JSON-decoded stuff and config file parsing
diff --git a/openstack/common/wsgi.py b/openstack/common/wsgi.py
index 614a22c..aaeb07b 100644
--- a/openstack/common/wsgi.py
+++ b/openstack/common/wsgi.py
@@ -568,9 +568,9 @@ class RequestDeserializer(object):
"""Extract necessary pieces of the request.
:param request: Request object
- :returns tuple of expected controller action name, dictionary of
- keyword arguments to pass to the controller, the expected
- content type of the response
+ :returns: tuple of (expected controller action name, dictionary of
+ keyword arguments to pass to the controller, the expected
+ content type of the response)
"""
action_args = self.get_action_args(request.environ)