Skip to content

Commit f5ae23a

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Standardize logger usage"
2 parents a99b54e + 047cb68 commit f5ae23a

26 files changed

Lines changed: 206 additions & 116 deletions

openstackclient/common/availability_zone.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""Availability Zone action implementations"""
1515

1616
import copy
17+
import logging
1718

1819
from novaclient import exceptions as nova_exceptions
1920
from osc_lib.command import command
@@ -23,6 +24,9 @@
2324
from openstackclient.i18n import _
2425

2526

27+
LOG = logging.getLogger(__name__)
28+
29+
2630
def _xform_common_availability_zone(az, zone_info):
2731
if hasattr(az, 'zoneState'):
2832
zone_info['zone_status'] = ('available' if az.zoneState['available']
@@ -136,11 +140,11 @@ def _get_volume_availability_zones(self, parsed_args):
136140
try:
137141
data = volume_client.availability_zones.list()
138142
except Exception as e:
139-
self.log.debug('Volume availability zone exception: ' + str(e))
143+
LOG.debug('Volume availability zone exception: %s', e)
140144
if parsed_args.volume:
141-
message = "Availability zones list not supported by " \
142-
"Block Storage API"
143-
self.log.warning(message)
145+
message = _("Availability zones list not supported by "
146+
"Block Storage API")
147+
LOG.warning(message)
144148

145149
result = []
146150
for zone in data:
@@ -154,11 +158,11 @@ def _get_network_availability_zones(self, parsed_args):
154158
network_client.find_extension('Availability Zone',
155159
ignore_missing=False)
156160
except Exception as e:
157-
self.log.debug('Network availability zone exception: ' + str(e))
161+
LOG.debug('Network availability zone exception: ', e)
158162
if parsed_args.network:
159-
message = "Availability zones list not supported by " \
160-
"Network API"
161-
self.log.warning(message)
163+
message = _("Availability zones list not supported by "
164+
"Network API")
165+
LOG.warning(message)
162166
return []
163167

164168
result = []

openstackclient/common/extension.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
"""Extension action implementations"""
1717

1818
import itertools
19+
import logging
1920

2021
from osc_lib.command import command
2122
from osc_lib import utils
2223

2324
from openstackclient.i18n import _
2425

2526

27+
LOG = logging.getLogger(__name__)
28+
29+
2630
class ListExtension(command.Lister):
2731
"""List API extensions"""
2832

@@ -80,24 +84,25 @@ def take_action(self, parsed_args):
8084
try:
8185
data += identity_client.extensions.list()
8286
except Exception:
83-
message = "Extensions list not supported by Identity API"
84-
self.log.warning(message)
87+
message = _("Extensions list not supported by Identity API")
88+
LOG.warning(message)
8589

8690
if parsed_args.compute or show_all:
8791
compute_client = self.app.client_manager.compute
8892
try:
8993
data += compute_client.list_extensions.show_all()
9094
except Exception:
91-
message = "Extensions list not supported by Compute API"
92-
self.log.warning(message)
95+
message = _("Extensions list not supported by Compute API")
96+
LOG.warning(message)
9397

9498
if parsed_args.volume or show_all:
9599
volume_client = self.app.client_manager.volume
96100
try:
97101
data += volume_client.list_extensions.show_all()
98102
except Exception:
99-
message = "Extensions list not supported by Block Storage API"
100-
self.log.warning(message)
103+
message = _("Extensions list not supported by "
104+
"Block Storage API")
105+
LOG.warning(message)
101106

102107
# Resource classes for the above
103108
extension_tuples = (
@@ -125,7 +130,7 @@ def take_action(self, parsed_args):
125130
dict_tuples
126131
)
127132
except Exception:
128-
message = "Extensions list not supported by Network API"
129-
self.log.warning(message)
133+
message = _("Extensions list not supported by Network API")
134+
LOG.warning(message)
130135

131136
return (columns, extension_tuples)

openstackclient/compute/v2/agent.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
"""Agent action implementations"""
1717

18+
import logging
19+
1820
from osc_lib.command import command
1921
from osc_lib import exceptions
2022
from osc_lib import utils
@@ -23,6 +25,9 @@
2325
from openstackclient.i18n import _
2426

2527

28+
LOG = logging.getLogger(__name__)
29+
30+
2631
class CreateAgent(command.ShowOne):
2732
"""Create compute agent command"""
2833

@@ -96,14 +101,13 @@ def take_action(self, parsed_args):
96101
compute_client.agents.delete(id)
97102
except Exception as e:
98103
result += 1
99-
self.app.log.error(_("Failed to delete agent with "
100-
"ID '%(id)s': %(e)s")
101-
% {'id': id, 'e': e})
104+
LOG.error(_("Failed to delete agent with ID '%(id)s': %(e)s"),
105+
{'id': id, 'e': e})
102106

103107
if result > 0:
104108
total = len(parsed_args.id)
105109
msg = (_("%(result)s of %(total)s agents failed "
106-
"to delete.") % {'result': result, 'total': total})
110+
"to delete.") % {'result': result, 'total': total})
107111
raise exceptions.CommandError(msg)
108112

109113

openstackclient/compute/v2/flavor.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
"""Flavor action implementations"""
1717

18+
import logging
19+
1820
from osc_lib.cli import parseractions
1921
from osc_lib.command import command
2022
from osc_lib import exceptions
@@ -25,6 +27,9 @@
2527
from openstackclient.identity import common as identity_common
2628

2729

30+
LOG = logging.getLogger(__name__)
31+
32+
2833
def _find_flavor(compute_client, flavor):
2934
try:
3035
return compute_client.flavors.get(flavor)
@@ -282,8 +287,7 @@ def take_action(self, parsed_args):
282287
try:
283288
flavor.set_keys(parsed_args.property)
284289
except Exception as e:
285-
self.app.log.error(
286-
_("Failed to set flavor property: %s") % str(e))
290+
LOG.error(_("Failed to set flavor property: %s"), e)
287291
result += 1
288292

289293
if parsed_args.project:
@@ -300,13 +304,12 @@ def take_action(self, parsed_args):
300304
compute_client.flavor_access.add_tenant_access(
301305
flavor.id, project_id)
302306
except Exception as e:
303-
self.app.log.error(_("Failed to set flavor access to"
304-
" project: %s") % str(e))
307+
LOG.error(_("Failed to set flavor access to project: %s"), e)
305308
result += 1
306309

307310
if result > 0:
308311
raise exceptions.CommandError(_("Command Failed: One or more of"
309-
" the operations failed"))
312+
" the operations failed"))
310313

311314

312315
class ShowFlavor(command.ShowOne):
@@ -373,8 +376,7 @@ def take_action(self, parsed_args):
373376
try:
374377
flavor.unset_keys(parsed_args.property)
375378
except Exception as e:
376-
self.app.log.error(
377-
_("Failed to unset flavor property: %s") % str(e))
379+
LOG.error(_("Failed to unset flavor property: %s"), e)
378380
result += 1
379381

380382
if parsed_args.project:
@@ -391,10 +393,10 @@ def take_action(self, parsed_args):
391393
compute_client.flavor_access.remove_tenant_access(
392394
flavor.id, project_id)
393395
except Exception as e:
394-
self.app.log.error(_("Failed to remove flavor access from"
395-
" project: %s") % str(e))
396+
LOG.error(_("Failed to remove flavor access from project: %s"),
397+
e)
396398
result += 1
397399

398400
if result > 0:
399401
raise exceptions.CommandError(_("Command Failed: One or more of"
400-
" the operations failed"))
402+
" the operations failed"))

openstackclient/compute/v2/server.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import argparse
1919
import getpass
2020
import io
21+
import logging
2122
import os
2223
import sys
2324

@@ -36,6 +37,9 @@
3637
from openstackclient.identity import common as identity_common
3738

3839

40+
LOG = logging.getLogger(__name__)
41+
42+
3943
def _format_servers_list_networks(networks):
4044
"""Return a formatted string of a server's networks
4145
@@ -521,8 +525,8 @@ def take_action(self, parsed_args):
521525
scheduler_hints=hints,
522526
config_drive=config_drive)
523527

524-
self.log.debug('boot_args: %s', boot_args)
525-
self.log.debug('boot_kwargs: %s', boot_kwargs)
528+
LOG.debug('boot_args: %s', boot_args)
529+
LOG.debug('boot_kwargs: %s', boot_kwargs)
526530

527531
# Wrap the call to catch exceptions in order to close files
528532
try:
@@ -543,8 +547,8 @@ def take_action(self, parsed_args):
543547
):
544548
sys.stdout.write('\n')
545549
else:
546-
self.log.error(_('Error creating server: %s'),
547-
parsed_args.server_name)
550+
LOG.error(_('Error creating server: %s'),
551+
parsed_args.server_name)
548552
sys.stdout.write(_('Error creating server\n'))
549553
raise SystemExit
550554

@@ -612,8 +616,8 @@ def take_action(self, parsed_args):
612616
):
613617
sys.stdout.write('\n')
614618
else:
615-
self.log.error(_('Error deleting server: %s'),
616-
server_obj.id)
619+
LOG.error(_('Error deleting server: %s'),
620+
server_obj.id)
617621
sys.stdout.write(_('Error deleting server\n'))
618622
raise SystemExit
619623

@@ -762,7 +766,7 @@ def take_action(self, parsed_args):
762766
'all_tenants': parsed_args.all_projects,
763767
'user_id': user_id,
764768
}
765-
self.log.debug('search options: %s', search_opts)
769+
LOG.debug('search options: %s', search_opts)
766770

767771
if parsed_args.long:
768772
columns = (
@@ -939,8 +943,8 @@ def take_action(self, parsed_args):
939943
):
940944
sys.stdout.write(_('Complete\n'))
941945
else:
942-
self.log.error(_('Error migrating server: %s'),
943-
server.id)
946+
LOG.error(_('Error migrating server: %s'),
947+
server.id)
944948
sys.stdout.write(_('Error migrating server\n'))
945949
raise SystemExit
946950

@@ -1015,8 +1019,8 @@ def take_action(self, parsed_args):
10151019
):
10161020
sys.stdout.write(_('Complete\n'))
10171021
else:
1018-
self.log.error(_('Error rebooting server: %s'),
1019-
server.id)
1022+
LOG.error(_('Error rebooting server: %s'),
1023+
server.id)
10201024
sys.stdout.write(_('Error rebooting server\n'))
10211025
raise SystemExit
10221026

@@ -1068,8 +1072,8 @@ def take_action(self, parsed_args):
10681072
):
10691073
sys.stdout.write(_('Complete\n'))
10701074
else:
1071-
self.log.error(_('Error rebuilding server: %s'),
1072-
server.id)
1075+
LOG.error(_('Error rebuilding server: %s'),
1076+
server.id)
10731077
sys.stdout.write(_('Error rebuilding server\n'))
10741078
raise SystemExit
10751079

@@ -1222,8 +1226,8 @@ def take_action(self, parsed_args):
12221226
):
12231227
sys.stdout.write(_('Complete\n'))
12241228
else:
1225-
self.log.error(_('Error resizing server: %s'),
1226-
server.id)
1229+
LOG.error(_('Error resizing server: %s'),
1230+
server.id)
12271231
sys.stdout.write(_('Error resizing server\n'))
12281232
raise SystemExit
12291233
elif parsed_args.confirm:
@@ -1538,7 +1542,7 @@ def take_action(self, parsed_args):
15381542
ip_address = _get_ip_address(server.addresses,
15391543
parsed_args.address_type,
15401544
ip_address_family)
1541-
self.log.debug("ssh command: %s", (cmd % (login, ip_address)))
1545+
LOG.debug("ssh command: %s", (cmd % (login, ip_address)))
15421546
os.system(cmd % (login, ip_address))
15431547

15441548

openstackclient/compute/v2/server_group.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515

1616
"""Compute v2 Server Group action implementations"""
1717

18+
import logging
19+
1820
from osc_lib.command import command
1921
from osc_lib import exceptions
2022
from osc_lib import utils
2123

2224
from openstackclient.i18n import _
2325

2426

27+
LOG = logging.getLogger(__name__)
28+
29+
2530
_formatters = {
2631
'policies': utils.format_list,
2732
'members': utils.format_list,
@@ -95,7 +100,7 @@ def take_action(self, parsed_args):
95100
# Catch all exceptions in order to avoid to block the next deleting
96101
except Exception as e:
97102
result += 1
98-
self.app.log.error(e)
103+
LOG.error(e)
99104

100105
if result > 0:
101106
total = len(parsed_args.server_group)

openstackclient/compute/v2/server_image.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
"""Compute v2 Server action implementations"""
1717

18+
import logging
1819
import sys
1920

2021
from osc_lib.command import command
@@ -26,6 +27,9 @@
2627
from openstackclient.i18n import _
2728

2829

30+
LOG = logging.getLogger(__name__)
31+
32+
2933
def _show_progress(progress):
3034
if progress:
3135
sys.stdout.write('\rProgress: %s' % progress)
@@ -90,10 +94,8 @@ def take_action(self, parsed_args):
9094
):
9195
sys.stdout.write('\n')
9296
else:
93-
self.log.error(
94-
_('Error creating server image: %s') %
95-
parsed_args.server,
96-
)
97+
LOG.error(_('Error creating server image: %s'),
98+
parsed_args.server)
9799
raise exceptions.CommandError
98100

99101
if self.app.client_manager._api_version['image'] == '1':

0 commit comments

Comments
 (0)