diff options
Diffstat (limited to 'openstackclient/compute')
| -rw-r--r-- | openstackclient/compute/v2/console.py | 7 | ||||
| -rw-r--r-- | openstackclient/compute/v2/host.py | 18 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server.py | 128 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server_backup.py | 16 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server_image.py | 15 | ||||
| -rw-r--r-- | openstackclient/compute/v2/usage.py | 8 |
6 files changed, 120 insertions, 72 deletions
diff --git a/openstackclient/compute/v2/console.py b/openstackclient/compute/v2/console.py index 25f92108..b2f7288f 100644 --- a/openstackclient/compute/v2/console.py +++ b/openstackclient/compute/v2/console.py @@ -15,8 +15,6 @@ """Compute v2 Console action implementations""" -import sys - from osc_lib.cli import parseractions from osc_lib.command import command from osc_lib import utils @@ -60,7 +58,10 @@ class ShowConsoleLog(command.Command): length += 1 data = server.get_console_output(length=length) - sys.stdout.write(data) + + if data and data[-1] != '\n': + data += '\n' + self.app.stdout.write(data) class ShowConsoleURL(command.ShowOne): diff --git a/openstackclient/compute/v2/host.py b/openstackclient/compute/v2/host.py index a495b367..9fdfd927 100644 --- a/openstackclient/compute/v2/host.py +++ b/openstackclient/compute/v2/host.py @@ -40,9 +40,9 @@ class ListHost(command.Lister): "Service", "Zone" ) - data = compute_client.hosts.list_all(parsed_args.zone) + data = compute_client.api.host_list(parsed_args.zone) return (columns, - (utils.get_item_properties( + (utils.get_dict_properties( s, columns, ) for s in data)) @@ -95,13 +95,7 @@ class SetHost(command.Command): compute_client = self.app.client_manager.compute - # More than one hosts will be returned by using find_resource() - # so that the return value cannot be used in host update() method. - # find_resource() is just used for checking existence of host and - # keeping the exception message consistent with other commands. - utils.find_resource(compute_client.hosts, parsed_args.host) - - compute_client.hosts.update( + compute_client.api.host_set( parsed_args.host, kwargs ) @@ -128,8 +122,10 @@ class ShowHost(command.Lister): "Memory MB", "Disk GB" ) - data = compute_client.hosts.get(parsed_args.host) + + data = compute_client.api.host_show(parsed_args.host) + return (columns, - (utils.get_item_properties( + (utils.get_dict_properties( s, columns, ) for s in data)) diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index c08f5cae..98bb0169 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -20,7 +20,6 @@ import getpass import io import logging import os -import sys from novaclient.v2 import servers from osc_lib.cli import parseractions @@ -32,6 +31,7 @@ import six from openstackclient.i18n import _ from openstackclient.identity import common as identity_common +from openstackclient.network import common as network_common LOG = logging.getLogger(__name__) @@ -189,12 +189,6 @@ def _prep_server_detail(compute_client, image_client, server): return info -def _show_progress(progress): - if progress: - sys.stdout.write('\rProgress: %s' % progress) - sys.stdout.flush() - - class AddFixedIP(command.Command): _description = _("Add fixed IP address to server") @@ -234,11 +228,10 @@ class AddFixedIP(command.Command): ) -class AddFloatingIP(command.Command): +class AddFloatingIP(network_common.NetworkAndComputeCommand): _description = _("Add floating IP address to server") - def get_parser(self, prog_name): - parser = super(AddFloatingIP, self).get_parser(prog_name) + def update_parser_common(self, parser): parser.add_argument( "server", metavar="<server>", @@ -252,19 +245,37 @@ class AddFloatingIP(command.Command): parser.add_argument( "--fixed-ip-address", metavar="<ip-address>", - help=_("Fixed IP address to associate with this floating IP " - "address"), + help=_( + "Fixed IP address to associate with this floating IP address" + ), ) return parser - def take_action(self, parsed_args): + def take_action_network(self, client, parsed_args): compute_client = self.app.client_manager.compute + attrs = {} + obj = client.find_ip( + parsed_args.ip_address, + ignore_missing=False, + ) server = utils.find_resource( - compute_client.servers, parsed_args.server) + compute_client.servers, + parsed_args.server, + ) + port = list(client.ports(device_id=server.id))[0] + attrs['port_id'] = port.id + if parsed_args.fixed_ip_address: + attrs['fixed_ip_address'] = parsed_args.fixed_ip_address + + client.update_ip(obj, **attrs) - server.add_floating_ip(parsed_args.ip_address, - parsed_args.fixed_ip_address) + def take_action_compute(self, client, parsed_args): + client.api.floating_ip_add( + parsed_args.server, + parsed_args.ip_address, + fixed_address=parsed_args.fixed_ip_address, + ) class AddPort(command.Command): @@ -580,6 +591,12 @@ class CreateServer(command.ShowOne): return parser def take_action(self, parsed_args): + + def _show_progress(progress): + if progress: + self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.flush() + compute_client = self.app.client_manager.compute volume_client = self.app.client_manager.volume image_client = self.app.client_manager.image @@ -814,11 +831,11 @@ class CreateServer(command.ShowOne): server.id, callback=_show_progress, ): - sys.stdout.write('\n') + self.app.stdout.write('\n') else: LOG.error(_('Error creating server: %s'), parsed_args.server_name) - sys.stdout.write(_('Error creating server\n')) + self.app.stdout.write(_('Error creating server\n')) raise SystemExit details = _prep_server_detail(compute_client, image_client, server) @@ -872,6 +889,12 @@ class DeleteServer(command.Command): return parser def take_action(self, parsed_args): + + def _show_progress(progress): + if progress: + self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.flush() + compute_client = self.app.client_manager.compute for server in parsed_args.server: server_obj = utils.find_resource( @@ -883,11 +906,11 @@ class DeleteServer(command.Command): server_obj.id, callback=_show_progress, ): - sys.stdout.write('\n') + self.app.stdout.write('\n') else: LOG.error(_('Error deleting server: %s'), server_obj.id) - sys.stdout.write(_('Error deleting server\n')) + self.app.stdout.write(_('Error deleting server\n')) raise SystemExit @@ -1290,6 +1313,11 @@ class MigrateServer(command.Command): def take_action(self, parsed_args): + def _show_progress(progress): + if progress: + self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.flush() + compute_client = self.app.client_manager.compute server = utils.find_resource( @@ -1315,11 +1343,11 @@ class MigrateServer(command.Command): server.id, callback=_show_progress, ): - sys.stdout.write(_('Complete\n')) + self.app.stdout.write(_('Complete\n')) else: LOG.error(_('Error migrating server: %s'), server.id) - sys.stdout.write(_('Error migrating server\n')) + self.app.stdout.write(_('Error migrating server\n')) raise SystemExit @@ -1380,6 +1408,12 @@ class RebootServer(command.Command): return parser def take_action(self, parsed_args): + + def _show_progress(progress): + if progress: + self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.flush() + compute_client = self.app.client_manager.compute server = utils.find_resource( compute_client.servers, parsed_args.server) @@ -1391,11 +1425,11 @@ class RebootServer(command.Command): server.id, callback=_show_progress, ): - sys.stdout.write(_('Complete\n')) + self.app.stdout.write(_('Complete\n')) else: LOG.error(_('Error rebooting server: %s'), server.id) - sys.stdout.write(_('Error rebooting server\n')) + self.app.stdout.write(_('Error rebooting server\n')) raise SystemExit @@ -1428,6 +1462,12 @@ class RebuildServer(command.ShowOne): return parser def take_action(self, parsed_args): + + def _show_progress(progress): + if progress: + self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.flush() + compute_client = self.app.client_manager.compute image_client = self.app.client_manager.image @@ -1445,11 +1485,11 @@ class RebuildServer(command.ShowOne): server.id, callback=_show_progress, ): - sys.stdout.write(_('Complete\n')) + self.app.stdout.write(_('Complete\n')) else: LOG.error(_('Error rebuilding server: %s'), server.id) - sys.stdout.write(_('Error rebuilding server\n')) + self.app.stdout.write(_('Error rebuilding server\n')) raise SystemExit details = _prep_server_detail(compute_client, image_client, server) @@ -1482,11 +1522,10 @@ class RemoveFixedIP(command.Command): server.remove_fixed_ip(parsed_args.ip_address) -class RemoveFloatingIP(command.Command): +class RemoveFloatingIP(network_common.NetworkAndComputeCommand): _description = _("Remove floating IP address from server") - def get_parser(self, prog_name): - parser = super(RemoveFloatingIP, self).get_parser(prog_name) + def update_parser_common(self, parser): parser.add_argument( "server", metavar="<server>", @@ -1501,13 +1540,21 @@ class RemoveFloatingIP(command.Command): ) return parser - def take_action(self, parsed_args): - compute_client = self.app.client_manager.compute + def take_action_network(self, client, parsed_args): + attrs = {} + obj = client.find_ip( + parsed_args.ip_address, + ignore_missing=False, + ) + attrs['port_id'] = None - server = utils.find_resource( - compute_client.servers, parsed_args.server) + client.update_ip(obj, **attrs) - server.remove_floating_ip(parsed_args.ip_address) + def take_action_compute(self, client, parsed_args): + client.api.floating_ip_remove( + parsed_args.server, + parsed_args.ip_address, + ) class RemovePort(command.Command): @@ -1727,6 +1774,11 @@ the new server and restart the old one.""") def take_action(self, parsed_args): + def _show_progress(progress): + if progress: + self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.flush() + compute_client = self.app.client_manager.compute server = utils.find_resource( compute_client.servers, @@ -1745,11 +1797,11 @@ the new server and restart the old one.""") success_status=['active', 'verify_resize'], callback=_show_progress, ): - sys.stdout.write(_('Complete\n')) + self.app.stdout.write(_('Complete\n')) else: LOG.error(_('Error resizing server: %s'), server.id) - sys.stdout.write(_('Error resizing server\n')) + self.app.stdout.write(_('Error resizing server\n')) raise SystemExit elif parsed_args.confirm: compute_client.servers.confirm_resize(server) @@ -1915,7 +1967,9 @@ class ShowServer(command.ShowOne): if parsed_args.diagnostics: (resp, data) = server.diagnostics() if not resp.status_code == 200: - sys.stderr.write(_("Error retrieving diagnostics data\n")) + self.app.stderr.write(_( + "Error retrieving diagnostics data\n" + )) return ({}, {}) else: data = _prep_server_detail(compute_client, diff --git a/openstackclient/compute/v2/server_backup.py b/openstackclient/compute/v2/server_backup.py index ddcf9101..a79f5f70 100644 --- a/openstackclient/compute/v2/server_backup.py +++ b/openstackclient/compute/v2/server_backup.py @@ -15,8 +15,6 @@ """Compute v2 Server action implementations""" -import sys - from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils @@ -26,12 +24,6 @@ import six from openstackclient.i18n import _ -def _show_progress(progress): - if progress: - sys.stderr.write('\rProgress: %s' % progress) - sys.stderr.flush() - - class CreateServerBackup(command.ShowOne): _description = _("Create a server backup image") @@ -74,6 +66,12 @@ class CreateServerBackup(command.ShowOne): return parser def take_action(self, parsed_args): + + def _show_progress(progress): + if progress: + self.app.stderr.write('\rProgress: %s' % progress) + self.app.stderr.flush() + compute_client = self.app.client_manager.compute server = utils.find_resource( @@ -114,7 +112,7 @@ class CreateServerBackup(command.ShowOne): image.id, callback=_show_progress, ): - sys.stdout.write('\n') + self.app.stdout.write('\n') else: msg = _('Error creating server backup: %s') % parsed_args.name raise exceptions.CommandError(msg) diff --git a/openstackclient/compute/v2/server_image.py b/openstackclient/compute/v2/server_image.py index c66e0674..3bc5d94a 100644 --- a/openstackclient/compute/v2/server_image.py +++ b/openstackclient/compute/v2/server_image.py @@ -16,7 +16,6 @@ """Compute v2 Server action implementations""" import logging -import sys from osc_lib.command import command from osc_lib import exceptions @@ -30,12 +29,6 @@ from openstackclient.i18n import _ LOG = logging.getLogger(__name__) -def _show_progress(progress): - if progress: - sys.stdout.write('\rProgress: %s' % progress) - sys.stdout.flush() - - class CreateServerImage(command.ShowOne): _description = _("Create a new server disk image from an existing server") @@ -64,6 +57,12 @@ class CreateServerImage(command.ShowOne): return parser def take_action(self, parsed_args): + + def _show_progress(progress): + if progress: + self.app.stdout.write('\rProgress: %s' % progress) + self.app.stdout.flush() + compute_client = self.app.client_manager.compute server = utils.find_resource( @@ -92,7 +91,7 @@ class CreateServerImage(command.ShowOne): image_id, callback=_show_progress, ): - sys.stdout.write('\n') + self.app.stdout.write('\n') else: LOG.error(_('Error creating server image: %s'), parsed_args.server) diff --git a/openstackclient/compute/v2/usage.py b/openstackclient/compute/v2/usage.py index 3edcffe4..4320bf90 100644 --- a/openstackclient/compute/v2/usage.py +++ b/openstackclient/compute/v2/usage.py @@ -16,7 +16,6 @@ """Usage action implementations""" import datetime -import sys from osc_lib.command import command from osc_lib import utils @@ -96,7 +95,7 @@ class ListUsage(command.Lister): pass if parsed_args.formatter == 'table' and len(usage_list) > 0: - sys.stdout.write(_("Usage from %(start)s to %(end)s: \n") % { + self.app.stdout.write(_("Usage from %(start)s to %(end)s: \n") % { "start": start.strftime(dateformat), "end": end.strftime(dateformat), }) @@ -168,8 +167,9 @@ class ShowUsage(command.ShowOne): usage = compute_client.usage.get(project, start, end) if parsed_args.formatter == 'table': - sys.stdout.write(_("Usage from %(start)s to %(end)s on " - "project %(project)s: \n") % { + self.app.stdout.write(_( + "Usage from %(start)s to %(end)s on project %(project)s: \n" + ) % { "start": start.strftime(dateformat), "end": end.strftime(dateformat), "project": project, |
