summaryrefslogtreecommitdiff
path: root/openstackclient/compute/v2
diff options
context:
space:
mode:
authorTang Chen <chen.tang@easystack.cn>2016-06-16 20:01:15 +0800
committerSteve Martinelli <s.martinelli@gmail.com>2016-06-20 15:16:51 +0000
commit047cb6849354f4fdf8d365bd109a0ed56a77d200 (patch)
treedc7372f6e90946e82606c2f1a1d974bd02879201 /openstackclient/compute/v2
parentba825a4d5c04e2e6fd8a82ebbfb2f71a85e683aa (diff)
downloadpython-openstackclient-047cb6849354f4fdf8d365bd109a0ed56a77d200.tar.gz
Standardize logger usage
Use file logger for all command specific logs. This patch also fixes some usage that doesn't follow rules in: http://docs.openstack.org/developer/oslo.i18n/guidelines.html After this patch, all self.log and self.app.log will be standardized to LOG(). NOTE: In shell.py, we got the log in class OpenStackShell, which is also known as self.app.log in other classes. This logger is used to record non-command-specific logs. So we leave it as-is. Change-Id: I114f73ee6c7e84593d71e724bc1ad00d343c1896 Implements: blueprint log-usage
Diffstat (limited to 'openstackclient/compute/v2')
-rw-r--r--openstackclient/compute/v2/agent.py12
-rw-r--r--openstackclient/compute/v2/flavor.py22
-rw-r--r--openstackclient/compute/v2/server.py36
-rw-r--r--openstackclient/compute/v2/server_group.py7
-rw-r--r--openstackclient/compute/v2/server_image.py10
-rw-r--r--openstackclient/compute/v2/service.py9
6 files changed, 59 insertions, 37 deletions
diff --git a/openstackclient/compute/v2/agent.py b/openstackclient/compute/v2/agent.py
index ce6898c1..62be2424 100644
--- a/openstackclient/compute/v2/agent.py
+++ b/openstackclient/compute/v2/agent.py
@@ -15,6 +15,8 @@
"""Agent action implementations"""
+import logging
+
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
@@ -23,6 +25,9 @@ import six
from openstackclient.i18n import _
+LOG = logging.getLogger(__name__)
+
+
class CreateAgent(command.ShowOne):
"""Create compute agent command"""
@@ -96,14 +101,13 @@ class DeleteAgent(command.Command):
compute_client.agents.delete(id)
except Exception as e:
result += 1
- self.app.log.error(_("Failed to delete agent with "
- "ID '%(id)s': %(e)s")
- % {'id': id, 'e': e})
+ LOG.error(_("Failed to delete agent with ID '%(id)s': %(e)s"),
+ {'id': id, 'e': e})
if result > 0:
total = len(parsed_args.id)
msg = (_("%(result)s of %(total)s agents failed "
- "to delete.") % {'result': result, 'total': total})
+ "to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
diff --git a/openstackclient/compute/v2/flavor.py b/openstackclient/compute/v2/flavor.py
index ab2bc85d..0a0d25c2 100644
--- a/openstackclient/compute/v2/flavor.py
+++ b/openstackclient/compute/v2/flavor.py
@@ -15,6 +15,8 @@
"""Flavor action implementations"""
+import logging
+
from osc_lib.cli import parseractions
from osc_lib.command import command
from osc_lib import exceptions
@@ -25,6 +27,9 @@ from openstackclient.i18n import _
from openstackclient.identity import common as identity_common
+LOG = logging.getLogger(__name__)
+
+
def _find_flavor(compute_client, flavor):
try:
return compute_client.flavors.get(flavor)
@@ -282,8 +287,7 @@ class SetFlavor(command.Command):
try:
flavor.set_keys(parsed_args.property)
except Exception as e:
- self.app.log.error(
- _("Failed to set flavor property: %s") % str(e))
+ LOG.error(_("Failed to set flavor property: %s"), e)
result += 1
if parsed_args.project:
@@ -300,13 +304,12 @@ class SetFlavor(command.Command):
compute_client.flavor_access.add_tenant_access(
flavor.id, project_id)
except Exception as e:
- self.app.log.error(_("Failed to set flavor access to"
- " project: %s") % str(e))
+ LOG.error(_("Failed to set flavor access to project: %s"), e)
result += 1
if result > 0:
raise exceptions.CommandError(_("Command Failed: One or more of"
- " the operations failed"))
+ " the operations failed"))
class ShowFlavor(command.ShowOne):
@@ -373,8 +376,7 @@ class UnsetFlavor(command.Command):
try:
flavor.unset_keys(parsed_args.property)
except Exception as e:
- self.app.log.error(
- _("Failed to unset flavor property: %s") % str(e))
+ LOG.error(_("Failed to unset flavor property: %s"), e)
result += 1
if parsed_args.project:
@@ -391,10 +393,10 @@ class UnsetFlavor(command.Command):
compute_client.flavor_access.remove_tenant_access(
flavor.id, project_id)
except Exception as e:
- self.app.log.error(_("Failed to remove flavor access from"
- " project: %s") % str(e))
+ LOG.error(_("Failed to remove flavor access from project: %s"),
+ e)
result += 1
if result > 0:
raise exceptions.CommandError(_("Command Failed: One or more of"
- " the operations failed"))
+ " the operations failed"))
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index 42736d66..7e4b0dc1 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -18,6 +18,7 @@
import argparse
import getpass
import io
+import logging
import os
import sys
@@ -36,6 +37,9 @@ from openstackclient.i18n import _
from openstackclient.identity import common as identity_common
+LOG = logging.getLogger(__name__)
+
+
def _format_servers_list_networks(networks):
"""Return a formatted string of a server's networks
@@ -521,8 +525,8 @@ class CreateServer(command.ShowOne):
scheduler_hints=hints,
config_drive=config_drive)
- self.log.debug('boot_args: %s', boot_args)
- self.log.debug('boot_kwargs: %s', boot_kwargs)
+ LOG.debug('boot_args: %s', boot_args)
+ LOG.debug('boot_kwargs: %s', boot_kwargs)
# Wrap the call to catch exceptions in order to close files
try:
@@ -543,8 +547,8 @@ class CreateServer(command.ShowOne):
):
sys.stdout.write('\n')
else:
- self.log.error(_('Error creating server: %s'),
- parsed_args.server_name)
+ LOG.error(_('Error creating server: %s'),
+ parsed_args.server_name)
sys.stdout.write(_('Error creating server\n'))
raise SystemExit
@@ -612,8 +616,8 @@ class DeleteServer(command.Command):
):
sys.stdout.write('\n')
else:
- self.log.error(_('Error deleting server: %s'),
- server_obj.id)
+ LOG.error(_('Error deleting server: %s'),
+ server_obj.id)
sys.stdout.write(_('Error deleting server\n'))
raise SystemExit
@@ -762,7 +766,7 @@ class ListServer(command.Lister):
'all_tenants': parsed_args.all_projects,
'user_id': user_id,
}
- self.log.debug('search options: %s', search_opts)
+ LOG.debug('search options: %s', search_opts)
if parsed_args.long:
columns = (
@@ -939,8 +943,8 @@ class MigrateServer(command.Command):
):
sys.stdout.write(_('Complete\n'))
else:
- self.log.error(_('Error migrating server: %s'),
- server.id)
+ LOG.error(_('Error migrating server: %s'),
+ server.id)
sys.stdout.write(_('Error migrating server\n'))
raise SystemExit
@@ -1015,8 +1019,8 @@ class RebootServer(command.Command):
):
sys.stdout.write(_('Complete\n'))
else:
- self.log.error(_('Error rebooting server: %s'),
- server.id)
+ LOG.error(_('Error rebooting server: %s'),
+ server.id)
sys.stdout.write(_('Error rebooting server\n'))
raise SystemExit
@@ -1068,8 +1072,8 @@ class RebuildServer(command.ShowOne):
):
sys.stdout.write(_('Complete\n'))
else:
- self.log.error(_('Error rebuilding server: %s'),
- server.id)
+ LOG.error(_('Error rebuilding server: %s'),
+ server.id)
sys.stdout.write(_('Error rebuilding server\n'))
raise SystemExit
@@ -1222,8 +1226,8 @@ class ResizeServer(command.Command):
):
sys.stdout.write(_('Complete\n'))
else:
- self.log.error(_('Error resizing server: %s'),
- server.id)
+ LOG.error(_('Error resizing server: %s'),
+ server.id)
sys.stdout.write(_('Error resizing server\n'))
raise SystemExit
elif parsed_args.confirm:
@@ -1538,7 +1542,7 @@ class SshServer(command.Command):
ip_address = _get_ip_address(server.addresses,
parsed_args.address_type,
ip_address_family)
- self.log.debug("ssh command: %s", (cmd % (login, ip_address)))
+ LOG.debug("ssh command: %s", (cmd % (login, ip_address)))
os.system(cmd % (login, ip_address))
diff --git a/openstackclient/compute/v2/server_group.py b/openstackclient/compute/v2/server_group.py
index 955b147e..d51b1ec2 100644
--- a/openstackclient/compute/v2/server_group.py
+++ b/openstackclient/compute/v2/server_group.py
@@ -15,6 +15,8 @@
"""Compute v2 Server Group action implementations"""
+import logging
+
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
@@ -22,6 +24,9 @@ from osc_lib import utils
from openstackclient.i18n import _
+LOG = logging.getLogger(__name__)
+
+
_formatters = {
'policies': utils.format_list,
'members': utils.format_list,
@@ -95,7 +100,7 @@ class DeleteServerGroup(command.Command):
# Catch all exceptions in order to avoid to block the next deleting
except Exception as e:
result += 1
- self.app.log.error(e)
+ LOG.error(e)
if result > 0:
total = len(parsed_args.server_group)
diff --git a/openstackclient/compute/v2/server_image.py b/openstackclient/compute/v2/server_image.py
index 85ee7f2d..6f5a7546 100644
--- a/openstackclient/compute/v2/server_image.py
+++ b/openstackclient/compute/v2/server_image.py
@@ -15,6 +15,7 @@
"""Compute v2 Server action implementations"""
+import logging
import sys
from oslo_utils import importutils
@@ -26,6 +27,9 @@ from openstackclient.common import utils
from openstackclient.i18n import _
+LOG = logging.getLogger(__name__)
+
+
def _show_progress(progress):
if progress:
sys.stdout.write('\rProgress: %s' % progress)
@@ -90,10 +94,8 @@ class CreateServerImage(command.ShowOne):
):
sys.stdout.write('\n')
else:
- self.log.error(
- _('Error creating server image: %s') %
- parsed_args.server,
- )
+ LOG.error(_('Error creating server image: %s'),
+ parsed_args.server)
raise exceptions.CommandError
if self.app.client_manager._api_version['image'] == '1':
diff --git a/openstackclient/compute/v2/service.py b/openstackclient/compute/v2/service.py
index d10af2ca..36917e20 100644
--- a/openstackclient/compute/v2/service.py
+++ b/openstackclient/compute/v2/service.py
@@ -15,6 +15,8 @@
"""Service action implementations"""
+import logging
+
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
@@ -23,6 +25,9 @@ from openstackclient.i18n import _
from openstackclient.i18n import _LE
+LOG = logging.getLogger(__name__)
+
+
class DeleteService(command.Command):
"""Delete service command"""
@@ -171,7 +176,7 @@ class SetService(command.Command):
cs.disable(parsed_args.host, parsed_args.service)
except Exception:
status = "enabled" if enabled else "disabled"
- self.log.error(_LE("Failed to set service status to %s"), status)
+ LOG.error(_LE("Failed to set service status to %s"), status)
result += 1
force_down = None
@@ -185,7 +190,7 @@ class SetService(command.Command):
force_down=force_down)
except Exception:
state = "down" if force_down else "up"
- self.log.error(_LE("Failed to set service state to %s"), state)
+ LOG.error(_LE("Failed to set service state to %s"), state)
result += 1
if result > 0: