Skip to content

Commit 0daa096

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Use a common decorator to log 'take_action' activation"
2 parents fa4b11a + e3c46ec commit 0daa096

50 files changed

Lines changed: 242 additions & 212 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

openstackclient/common/configuration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from cliff import show
1919
import six
2020

21+
from openstackclient.common import utils
22+
2123
REDACTED = "<redacted>"
2224

2325

@@ -44,8 +46,8 @@ def get_parser(self, prog_name):
4446
)
4547
return parser
4648

49+
@utils.log_method(log)
4750
def take_action(self, parsed_args):
48-
self.log.debug('take_action(%s)', parsed_args)
4951

5052
info = self.app.client_manager.get_configuration()
5153
for key, value in six.iteritems(info.pop('auth', {})):

openstackclient/common/limits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def get_parser(self, prog_name):
6464
)
6565
return parser
6666

67+
@utils.log_method(log)
6768
def take_action(self, parsed_args):
68-
self.log.debug('take_action(%s)', parsed_args)
6969

7070
compute_client = self.app.client_manager.compute
7171
volume_client = self.app.client_manager.volume

openstackclient/common/module.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@
2222
from cliff import lister
2323
from cliff import show
2424

25+
from openstackclient.common import utils
26+
2527

2628
class ListCommand(lister.Lister):
2729
"""List recognized commands by group"""
2830

2931
auth_required = False
3032
log = logging.getLogger(__name__ + '.ListCommand')
3133

34+
@utils.log_method(log)
3235
def take_action(self, parsed_args):
33-
self.log.debug('take_action(%s)', parsed_args)
3436
cm = self.app.command_manager
3537
groups = cm.get_command_groups()
3638

@@ -54,8 +56,8 @@ def get_parser(self, prog_name):
5456
)
5557
return parser
5658

59+
@utils.log_method(log)
5760
def take_action(self, parsed_args):
58-
self.log.debug('take_action(%s)', parsed_args)
5961

6062
data = {}
6163
# Get module versions

openstackclient/common/quota.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from cliff import command
2424
from cliff import show
2525

26+
from openstackclient.common import utils
27+
2628

2729
# List the quota items, map the internal argument name to the option
2830
# name that the user sees.
@@ -89,8 +91,8 @@ def get_parser(self, prog_name):
8991
)
9092
return parser
9193

94+
@utils.log_method(log)
9295
def take_action(self, parsed_args):
93-
self.log.debug('take_action(%s)', parsed_args)
9496

9597
compute_client = self.app.client_manager.compute
9698
volume_client = self.app.client_manager.volume
@@ -188,8 +190,8 @@ def get_network_quota(self, parsed_args):
188190
else:
189191
return {}
190192

193+
@utils.log_method(log)
191194
def take_action(self, parsed_args):
192-
self.log.debug('take_action(%s)', parsed_args)
193195

194196
compute_client = self.app.client_manager.compute
195197
volume_client = self.app.client_manager.volume

openstackclient/common/utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,29 @@
2626
from openstackclient.common import exceptions
2727

2828

29+
def log_method(log, level=logging.DEBUG):
30+
"""Logs a method and its arguments when entered."""
31+
32+
def decorator(func):
33+
func_name = func.__name__
34+
35+
@six.wraps(func)
36+
def wrapper(self, *args, **kwargs):
37+
if log.isEnabledFor(level):
38+
pretty_args = []
39+
if args:
40+
pretty_args.extend(str(a) for a in args)
41+
if kwargs:
42+
pretty_args.extend(
43+
"%s=%s" % (k, v) for k, v in six.iteritems(kwargs))
44+
log.log(level, "%s(%s)", func_name, ", ".join(pretty_args))
45+
return func(self, *args, **kwargs)
46+
47+
return wrapper
48+
49+
return decorator
50+
51+
2952
def find_resource(manager, name_or_id, **kwargs):
3053
"""Helper for the _find_* methods.
3154

openstackclient/compute/v2/aggregate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def get_parser(self, prog_name):
123123
)
124124
return parser
125125

126+
@utils.log_method(log)
126127
def take_action(self, parsed_args):
127-
self.log.debug('take_action(%s)', parsed_args)
128128

129129
compute_client = self.app.client_manager.compute
130130
data = utils.find_resource(
@@ -256,8 +256,8 @@ def get_parser(self, prog_name):
256256
)
257257
return parser
258258

259+
@utils.log_method(log)
259260
def take_action(self, parsed_args):
260-
self.log.debug('take_action(%s)', parsed_args)
261261

262262
compute_client = self.app.client_manager.compute
263263
aggregate = utils.find_resource(
@@ -303,8 +303,8 @@ def get_parser(self, prog_name):
303303
)
304304
return parser
305305

306+
@utils.log_method(log)
306307
def take_action(self, parsed_args):
307-
self.log.debug('take_action(%s)', parsed_args)
308308

309309
compute_client = self.app.client_manager.compute
310310
data = utils.find_resource(

openstackclient/compute/v2/availability_zone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def get_parser(self, prog_name):
7373
)
7474
return parser
7575

76+
@utils.log_method(log)
7677
def take_action(self, parsed_args):
77-
self.log.debug('take_action(%s)', parsed_args)
7878

7979
if parsed_args.long:
8080
columns = ('Zone Name', 'Zone Status',

openstackclient/compute/v2/console.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def get_parser(self, prog_name):
4747
)
4848
return parser
4949

50+
@utils.log_method(log)
5051
def take_action(self, parsed_args):
51-
self.log.debug('take_action(%s)', parsed_args)
5252
compute_client = self.app.client_manager.compute
5353

5454
server = utils.find_resource(
@@ -103,8 +103,8 @@ def get_parser(self, prog_name):
103103
)
104104
return parser
105105

106+
@utils.log_method(log)
106107
def take_action(self, parsed_args):
107-
self.log.debug('take_action(%s)', parsed_args)
108108
compute_client = self.app.client_manager.compute
109109
server = utils.find_resource(
110110
compute_client.servers,

openstackclient/compute/v2/floatingip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def get_parser(self, prog_name):
6969
)
7070
return parser
7171

72+
@utils.log_method(log)
7273
def take_action(self, parsed_args):
73-
self.log.debug('take_action(%s)', parsed_args)
7474
compute_client = self.app.client_manager.compute
7575
floating_ip = compute_client.floating_ips.create(parsed_args.pool)
7676

@@ -93,8 +93,8 @@ def get_parser(self, prog_name):
9393
)
9494
return parser
9595

96+
@utils.log_method(log)
9697
def take_action(self, parsed_args):
97-
self.log.debug('take_action(%s)', parsed_args)
9898
compute_client = self.app.client_manager.compute
9999

100100
floating_ip = utils.find_resource(
@@ -111,8 +111,8 @@ class ListFloatingIP(lister.Lister):
111111

112112
log = logging.getLogger(__name__ + '.ListFloatingIP')
113113

114+
@utils.log_method(log)
114115
def take_action(self, parsed_args):
115-
self.log.debug('take_action(%s)', parsed_args)
116116
compute_client = self.app.client_manager.compute
117117

118118
columns = ('ID', 'Pool', 'IP', 'Fixed IP', 'Instance ID')

openstackclient/compute/v2/floatingippool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class ListFloatingIPPool(lister.Lister):
2727

2828
log = logging.getLogger(__name__ + '.ListFloatingIPPool')
2929

30+
@utils.log_method(log)
3031
def take_action(self, parsed_args):
31-
self.log.debug('take_action(%s)', parsed_args)
3232
compute_client = self.app.client_manager.compute
3333

3434
columns = ('Name',)

0 commit comments

Comments
 (0)