summaryrefslogtreecommitdiff
path: root/openstackclient/common
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-09-11 02:43:53 +0000
committerGerrit Code Review <review@openstack.org>2015-09-11 02:43:54 +0000
commit0daa0969392dce50266d8dcac31a68d2ba02602f (patch)
treeb064e34392225d0ab144765784f4f171b8760429 /openstackclient/common
parentfa4b11a86f05cbf3b542a795267490a65d477b0e (diff)
parente3c46ece4a496584a54b9d39b55921990db4a7b3 (diff)
downloadpython-openstackclient-0daa0969392dce50266d8dcac31a68d2ba02602f.tar.gz
Merge "Use a common decorator to log 'take_action' activation"
Diffstat (limited to 'openstackclient/common')
-rw-r--r--openstackclient/common/configuration.py4
-rw-r--r--openstackclient/common/limits.py2
-rw-r--r--openstackclient/common/module.py6
-rw-r--r--openstackclient/common/quota.py6
-rw-r--r--openstackclient/common/utils.py23
5 files changed, 35 insertions, 6 deletions
diff --git a/openstackclient/common/configuration.py b/openstackclient/common/configuration.py
index 83df73e2..ac2792dd 100644
--- a/openstackclient/common/configuration.py
+++ b/openstackclient/common/configuration.py
@@ -18,6 +18,8 @@ import logging
from cliff import show
import six
+from openstackclient.common import utils
+
REDACTED = "<redacted>"
@@ -44,8 +46,8 @@ class ShowConfiguration(show.ShowOne):
)
return parser
+ @utils.log_method(log)
def take_action(self, parsed_args):
- self.log.debug('take_action(%s)', parsed_args)
info = self.app.client_manager.get_configuration()
for key, value in six.iteritems(info.pop('auth', {})):
diff --git a/openstackclient/common/limits.py b/openstackclient/common/limits.py
index c738f150..582f70c5 100644
--- a/openstackclient/common/limits.py
+++ b/openstackclient/common/limits.py
@@ -64,8 +64,8 @@ class ShowLimits(lister.Lister):
)
return parser
+ @utils.log_method(log)
def take_action(self, parsed_args):
- self.log.debug('take_action(%s)', parsed_args)
compute_client = self.app.client_manager.compute
volume_client = self.app.client_manager.volume
diff --git a/openstackclient/common/module.py b/openstackclient/common/module.py
index 356cdca3..f0ed23b2 100644
--- a/openstackclient/common/module.py
+++ b/openstackclient/common/module.py
@@ -22,6 +22,8 @@ import sys
from cliff import lister
from cliff import show
+from openstackclient.common import utils
+
class ListCommand(lister.Lister):
"""List recognized commands by group"""
@@ -29,8 +31,8 @@ class ListCommand(lister.Lister):
auth_required = False
log = logging.getLogger(__name__ + '.ListCommand')
+ @utils.log_method(log)
def take_action(self, parsed_args):
- self.log.debug('take_action(%s)', parsed_args)
cm = self.app.command_manager
groups = cm.get_command_groups()
@@ -54,8 +56,8 @@ class ListModule(show.ShowOne):
)
return parser
+ @utils.log_method(log)
def take_action(self, parsed_args):
- self.log.debug('take_action(%s)', parsed_args)
data = {}
# Get module versions
diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py
index e79fd7ed..65367e03 100644
--- a/openstackclient/common/quota.py
+++ b/openstackclient/common/quota.py
@@ -23,6 +23,8 @@ import sys
from cliff import command
from cliff import show
+from openstackclient.common import utils
+
# List the quota items, map the internal argument name to the option
# name that the user sees.
@@ -89,8 +91,8 @@ class SetQuota(command.Command):
)
return parser
+ @utils.log_method(log)
def take_action(self, parsed_args):
- self.log.debug('take_action(%s)', parsed_args)
compute_client = self.app.client_manager.compute
volume_client = self.app.client_manager.volume
@@ -188,8 +190,8 @@ class ShowQuota(show.ShowOne):
else:
return {}
+ @utils.log_method(log)
def take_action(self, parsed_args):
- self.log.debug('take_action(%s)', parsed_args)
compute_client = self.app.client_manager.compute
volume_client = self.app.client_manager.volume
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py
index 2f8419f4..b6726bfa 100644
--- a/openstackclient/common/utils.py
+++ b/openstackclient/common/utils.py
@@ -26,6 +26,29 @@ from oslo_utils import importutils
from openstackclient.common import exceptions
+def log_method(log, level=logging.DEBUG):
+ """Logs a method and its arguments when entered."""
+
+ def decorator(func):
+ func_name = func.__name__
+
+ @six.wraps(func)
+ def wrapper(self, *args, **kwargs):
+ if log.isEnabledFor(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))
+ log.log(level, "%s(%s)", func_name, ", ".join(pretty_args))
+ return func(self, *args, **kwargs)
+
+ return wrapper
+
+ return decorator
+
+
def find_resource(manager, name_or_id, **kwargs):
"""Helper for the _find_* methods.