summaryrefslogtreecommitdiff
path: root/openstackclient/common/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/common/utils.py')
-rw-r--r--openstackclient/common/utils.py45
1 files changed, 16 insertions, 29 deletions
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py
index 3ae30c8f..4142f830 100644
--- a/openstackclient/common/utils.py
+++ b/openstackclient/common/utils.py
@@ -26,33 +26,6 @@ from oslo_utils import importutils
from openstackclient.common import exceptions
-class log_method(object):
-
- def __init__(self, log=None, level=logging.DEBUG):
- self._log = log
- self._level = level
-
- def __call__(self, func):
- func_name = func.__name__
- if not self._log:
- self._log = logging.getLogger(func.__class__.__name__)
-
- @six.wraps(func)
- def wrapper(*args, **kwargs):
- if self._log.isEnabledFor(self._level):
- pretty_args = []
- if args:
- pretty_args.extend(str(a) for a in args)
- if kwargs:
- pretty_args.extend(
- "%s=%s" % (k, v) for k, v in six.iteritems(kwargs))
- self._log.log(self._level, "%s(%s)",
- func_name, ", ".join(pretty_args))
- return func(*args, **kwargs)
-
- return wrapper
-
-
def find_resource(manager, name_or_id, **kwargs):
"""Helper for the _find_* methods.
@@ -169,6 +142,16 @@ def format_list(data, separator=', '):
return separator.join(sorted(data))
+def format_list_of_dicts(data):
+ """Return a formatted string of key value pairs for each dict
+
+ :param data: a list of dicts
+ :rtype: a string formatted to key='value' with dicts separated by new line
+ """
+
+ return '\n'.join(format_dict(i) for i in data)
+
+
def get_field(item, field):
try:
if isinstance(item, dict):
@@ -331,6 +314,8 @@ def wait_for_status(status_f,
def wait_for_delete(manager,
res_id,
status_field='status',
+ error_status=['error'],
+ exception_name=['NotFound'],
sleep_time=5,
timeout=300,
callback=None):
@@ -341,6 +326,8 @@ def wait_for_delete(manager,
:param status_field: the status attribute in the returned resource object,
this is used to check for error states while the resource is being
deleted
+ :param error_status: a list of status strings for error
+ :param exception_name: a list of exception strings for deleted case
:param sleep_time: wait this long between checks (seconds)
:param timeout: check until this long (seconds)
:param callback: called per sleep cycle, useful to display progress; this
@@ -357,12 +344,12 @@ def wait_for_delete(manager,
# handle a NotFound exception here without parsing the message
res = manager.get(res_id)
except Exception as ex:
- if type(ex).__name__ == 'NotFound':
+ if type(ex).__name__ in exception_name:
return True
raise
status = getattr(res, status_field, '').lower()
- if status == 'error':
+ if status in error_status:
return False
if callback: