diff options
Diffstat (limited to 'openstackclient/compute')
| -rw-r--r-- | openstackclient/compute/v2/aggregate.py | 2 | ||||
| -rw-r--r-- | openstackclient/compute/v2/fixedip.py | 100 | ||||
| -rw-r--r-- | openstackclient/compute/v2/flavor.py | 2 | ||||
| -rw-r--r-- | openstackclient/compute/v2/floatingip.py | 97 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server.py | 226 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server_event.py | 12 |
6 files changed, 223 insertions, 216 deletions
diff --git a/openstackclient/compute/v2/aggregate.py b/openstackclient/compute/v2/aggregate.py index 7f9161a9..fa646478 100644 --- a/openstackclient/compute/v2/aggregate.py +++ b/openstackclient/compute/v2/aggregate.py @@ -101,6 +101,8 @@ class CreateAggregate(command.ShowOne): parsed_args.property, )._info) + # TODO(dtroyer): re-format metadata field to properites as + # in the set command return zip(*sorted(six.iteritems(info))) diff --git a/openstackclient/compute/v2/fixedip.py b/openstackclient/compute/v2/fixedip.py deleted file mode 100644 index 0c0b619e..00000000 --- a/openstackclient/compute/v2/fixedip.py +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright 2013 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# - -"""Fixed IP action implementations""" - -import logging - -from osc_lib.command import command -from osc_lib import utils - -from openstackclient.i18n import _ - - -class AddFixedIP(command.Command): - _description = _("Add fixed IP address to server") - - # TODO(tangchen): Remove this class and ``ip fixed add`` command - # two cycles after Mitaka. - - # This notifies cliff to not display the help for this command - deprecated = True - - log = logging.getLogger('deprecated') - - def get_parser(self, prog_name): - parser = super(AddFixedIP, self).get_parser(prog_name) - parser.add_argument( - "network", - metavar="<network>", - help=_("Network to fetch an IP address from (name or ID)"), - ) - parser.add_argument( - "server", - metavar="<server>", - help=_("Server to receive the IP address (name or ID)"), - ) - return parser - - def take_action(self, parsed_args): - self.log.warning(_('This command has been deprecated. ' - 'Please use "server add fixed ip" instead.')) - - compute_client = self.app.client_manager.compute - - network = utils.find_resource( - compute_client.networks, parsed_args.network) - - server = utils.find_resource( - compute_client.servers, parsed_args.server) - - server.add_fixed_ip(network.id) - - -class RemoveFixedIP(command.Command): - _description = _("Remove fixed IP address from server") - - # TODO(tangchen): Remove this class and ``ip fixed remove`` command - # two cycles after Mitaka. - - # This notifies cliff to not display the help for this command - deprecated = True - - log = logging.getLogger('deprecated') - - def get_parser(self, prog_name): - parser = super(RemoveFixedIP, self).get_parser(prog_name) - parser.add_argument( - "ip_address", - metavar="<ip-address>", - help=_("IP address to remove from server (name only)"), - ) - parser.add_argument( - "server", - metavar="<server>", - help=_("Server to remove the IP address from (name or ID)"), - ) - return parser - - def take_action(self, parsed_args): - self.log.warning(_('This command has been deprecated. ' - 'Please use "server remove fixed ip" instead.')) - - compute_client = self.app.client_manager.compute - - server = utils.find_resource( - compute_client.servers, parsed_args.server) - - server.remove_fixed_ip(parsed_args.ip_address) diff --git a/openstackclient/compute/v2/flavor.py b/openstackclient/compute/v2/flavor.py index 2cc5f1e8..4f1e48af 100644 --- a/openstackclient/compute/v2/flavor.py +++ b/openstackclient/compute/v2/flavor.py @@ -432,7 +432,7 @@ class ShowFlavor(command.ShowOne): projects = [utils.get_field(access, 'tenant_id') for access in flavor_access] # TODO(Huanxuan Ao): This format case can be removed after - # patch https://review.openstack.org/#/c/330223/ merged. + # patch https://review.opendev.org/#/c/330223/ merged. access_projects = utils.format_list(projects) except Exception as e: msg = _("Failed to get access projects list " diff --git a/openstackclient/compute/v2/floatingip.py b/openstackclient/compute/v2/floatingip.py deleted file mode 100644 index 69595bed..00000000 --- a/openstackclient/compute/v2/floatingip.py +++ /dev/null @@ -1,97 +0,0 @@ -# Copyright 2013 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# - -"""Floating IP action implementations""" - -import logging - -from osc_lib.command import command -from osc_lib import utils - -from openstackclient.i18n import _ - - -class AddFloatingIP(command.Command): - _description = _("Add floating IP address to server") - - # TODO(tangchen): Remove this class and ``ip floating add`` command - # two cycles after Mitaka. - - # This notifies cliff to not display the help for this command - deprecated = True - - log = logging.getLogger('deprecated') - - def get_parser(self, prog_name): - parser = super(AddFloatingIP, self).get_parser(prog_name) - parser.add_argument( - "ip_address", - metavar="<ip-address>", - help=_("IP address to add to server (name only)"), - ) - parser.add_argument( - "server", - metavar="<server>", - help=_("Server to receive the IP address (name or ID)"), - ) - return parser - - def take_action(self, parsed_args): - self.log.warning(_('This command has been deprecated. ' - 'Please use "server add floating ip" instead.')) - - compute_client = self.app.client_manager.compute - - server = utils.find_resource( - compute_client.servers, parsed_args.server) - - server.add_floating_ip(parsed_args.ip_address) - - -class RemoveFloatingIP(command.Command): - _description = _("Remove floating IP address from server") - - # TODO(tangchen): Remove this class and ``ip floating remove`` command - # two cycles after Mitaka. - - # This notifies cliff to not display the help for this command - deprecated = True - - log = logging.getLogger('deprecated') - - def get_parser(self, prog_name): - parser = super(RemoveFloatingIP, self).get_parser(prog_name) - parser.add_argument( - "ip_address", - metavar="<ip-address>", - help=_("IP address to remove from server (name only)"), - ) - parser.add_argument( - "server", - metavar="<server>", - help=_("Server to remove the IP address from (name or ID)"), - ) - return parser - - def take_action(self, parsed_args): - self.log.warning(_('This command has been deprecated. ' - 'Please use "server remove floating ip" instead.')) - - compute_client = self.app.client_manager.compute - - server = utils.find_resource( - compute_client.servers, parsed_args.server) - - server.remove_floating_ip(parsed_args.ip_address) diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index cb9f8d43..2792e315 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -424,7 +424,10 @@ class AddServerSecurityGroup(command.Command): class AddServerVolume(command.Command): - _description = _("Add volume to server") + _description = _( + "Add volume to server. " + "Specify ``--os-compute-api-version 2.20`` or higher to add a volume " + "to a server with status ``SHELVED`` or ``SHELVED_OFFLOADED``.") def get_parser(self, prog_name): parser = super(AddServerVolume, self).get_parser(prog_name) @@ -540,6 +543,12 @@ class CreateServer(command.ShowOne): help=_('User data file to serve from the metadata server'), ) parser.add_argument( + '--description', + metavar='<description>', + help=_('Set description for the server (supported by ' + '--os-compute-api-version 2.19 or above)'), + ) + parser.add_argument( '--availability-zone', metavar='<zone-name>', help=_('Select an availability zone for the server'), @@ -749,6 +758,12 @@ class CreateServer(command.ShowOne): "exception": e} ) + if parsed_args.description: + if compute_client.api_version < api_versions.APIVersion("2.19"): + msg = _("Description is not supported for " + "--os-compute-api-version less than 2.19") + raise exceptions.CommandError(msg) + block_device_mapping_v2 = [] if volume: block_device_mapping_v2 = [{'uuid': volume, @@ -909,6 +924,9 @@ class CreateServer(command.ShowOne): scheduler_hints=hints, config_drive=config_drive) + if parsed_args.description: + boot_kwargs['description'] = parsed_args.description + LOG.debug('boot_args: %s', boot_args) LOG.debug('boot_kwargs: %s', boot_kwargs) @@ -1129,12 +1147,36 @@ class ListServer(command.Lister): help=_('Only display deleted servers (Admin only).') ) parser.add_argument( + '--changes-before', + metavar='<changes-before>', + default=None, + help=_("List only servers changed before a certain point of time. " + "The provided time should be an ISO 8061 formatted time " + "(e.g., 2016-03-05T06:27:59Z). " + "(Supported by API versions '2.66' - '2.latest')") + ) + parser.add_argument( '--changes-since', metavar='<changes-since>', default=None, help=_("List only servers changed after a certain point of time." - " The provided time should be an ISO 8061 formatted time." - " ex 2016-03-04T06:27:59Z .") + " The provided time should be an ISO 8061 formatted time" + " (e.g., 2016-03-04T06:27:59Z).") + ) + lock_group = parser.add_mutually_exclusive_group() + lock_group.add_argument( + '--locked', + action='store_true', + default=False, + help=_('Only display locked servers. ' + 'Requires ``--os-compute-api-version`` 2.73 or greater.'), + ) + lock_group.add_argument( + '--unlocked', + action='store_true', + default=False, + help=_('Only display unlocked servers. ' + 'Requires ``--os-compute-api-version`` 2.73 or greater.'), ) return parser @@ -1188,10 +1230,36 @@ class ListServer(command.Lister): 'all_tenants': parsed_args.all_projects, 'user_id': user_id, 'deleted': parsed_args.deleted, + 'changes-before': parsed_args.changes_before, 'changes-since': parsed_args.changes_since, } + support_locked = (compute_client.api_version >= + api_versions.APIVersion('2.73')) + if not support_locked and (parsed_args.locked or parsed_args.unlocked): + msg = _('--os-compute-api-version 2.73 or greater is required to ' + 'use the (un)locked filter option.') + raise exceptions.CommandError(msg) + elif support_locked: + # Only from 2.73. + if parsed_args.locked: + search_opts['locked'] = True + if parsed_args.unlocked: + search_opts['locked'] = False LOG.debug('search options: %s', search_opts) + if search_opts['changes-before']: + if compute_client.api_version < api_versions.APIVersion('2.66'): + msg = _('--os-compute-api-version 2.66 or later is required') + raise exceptions.CommandError(msg) + + try: + timeutils.parse_isotime(search_opts['changes-before']) + except ValueError: + raise exceptions.CommandError( + _('Invalid changes-before value: %s') % + search_opts['changes-before'] + ) + if search_opts['changes-since']: try: timeutils.parse_isotime(search_opts['changes-since']) @@ -1374,16 +1442,28 @@ class LockServer(command.Command): nargs='+', help=_('Server(s) to lock (name or ID)'), ) + parser.add_argument( + '--reason', + metavar='<reason>', + default=None, + help=_("Reason for locking the server(s). Requires " + "``--os-compute-api-version`` 2.73 or greater.") + ) return parser def take_action(self, parsed_args): compute_client = self.app.client_manager.compute + support_reason = compute_client.api_version >= api_versions.APIVersion( + '2.73') + if not support_reason and parsed_args.reason: + msg = _('--os-compute-api-version 2.73 or greater is required to ' + 'use the --reason option.') + raise exceptions.CommandError(msg) for server in parsed_args.server: - utils.find_resource( - compute_client.servers, - server, - ).lock() + serv = utils.find_resource(compute_client.servers, server) + (serv.lock(reason=parsed_args.reason) if support_reason + else serv.lock()) # FIXME(dtroyer): Here is what I want, how with argparse/cliff? @@ -1407,9 +1487,38 @@ class MigrateServer(command.Command): help=_('Server (name or ID)'), ) parser.add_argument( + '--live-migration', + dest='live_migration', + action='store_true', + help=_('Live migrate the server. Use the ``--host`` option to ' + 'specify a target host for the migration which will be ' + 'validated by the scheduler.'), + ) + # The --live and --host options are mutually exclusive ways of asking + # for a target host during a live migration. + host_group = parser.add_mutually_exclusive_group() + # TODO(mriedem): Remove --live in the next major version bump after + # the Train release. + host_group.add_argument( '--live', metavar='<hostname>', - help=_('Target hostname'), + help=_('**Deprecated** This option is problematic in that it ' + 'requires a host and prior to compute API version 2.30, ' + 'specifying a host during live migration will bypass ' + 'validation by the scheduler which could result in ' + 'failures to actually migrate the server to the specified ' + 'host or over-subscribe the host. Use the ' + '``--live-migration`` option instead. If both this option ' + 'and ``--live-migration`` are used, ``--live-migration`` ' + 'takes priority.'), + ) + host_group.add_argument( + '--host', + metavar='<hostname>', + help=_('Migrate the server to the specified host. Requires ' + '``--os-compute-api-version`` 2.30 or greater when used ' + 'with the ``--live-migration`` option, otherwise requires ' + '``--os-compute-api-version`` 2.56 or greater.'), ) migration_group = parser.add_mutually_exclusive_group() migration_group.add_argument( @@ -1447,6 +1556,15 @@ class MigrateServer(command.Command): ) return parser + def _log_warning_for_live(self, parsed_args): + if parsed_args.live: + # NOTE(mriedem): The --live option requires a host and if + # --os-compute-api-version is less than 2.30 it will forcefully + # bypass the scheduler which is dangerous. + self.log.warning(_( + 'The --live option has been deprecated. Please use the ' + '--live-migration option instead.')) + def take_action(self, parsed_args): def _show_progress(progress): @@ -1460,20 +1578,52 @@ class MigrateServer(command.Command): compute_client.servers, parsed_args.server, ) - if parsed_args.live: + # Check for live migration. + if parsed_args.live or parsed_args.live_migration: + # Always log a warning if --live is used. + self._log_warning_for_live(parsed_args) kwargs = { - 'host': parsed_args.live, 'block_migration': parsed_args.block_migration } + # Prefer --live-migration over --live if both are specified. + if parsed_args.live_migration: + # Technically we could pass a non-None host with + # --os-compute-api-version < 2.30 but that is the same thing + # as the --live option bypassing the scheduler which we don't + # want to support, so if the user is using --live-migration + # and --host, we want to enforce that they are using version + # 2.30 or greater. + if (parsed_args.host and + compute_client.api_version < + api_versions.APIVersion('2.30')): + raise exceptions.CommandError( + '--os-compute-api-version 2.30 or greater is required ' + 'when using --host') + # The host parameter is required in the API even if None. + kwargs['host'] = parsed_args.host + else: + kwargs['host'] = parsed_args.live + if compute_client.api_version < api_versions.APIVersion('2.25'): kwargs['disk_over_commit'] = parsed_args.disk_overcommit server.live_migrate(**kwargs) else: if parsed_args.block_migration or parsed_args.disk_overcommit: - raise exceptions.CommandError("--live must be specified if " - "--block-migration or " - "--disk-overcommit is specified") - server.migrate() + raise exceptions.CommandError( + "--live-migration must be specified if " + "--block-migration or --disk-overcommit is " + "specified") + if parsed_args.host: + if (compute_client.api_version < + api_versions.APIVersion('2.56')): + msg = _( + '--os-compute-api-version 2.56 or greater is ' + 'required to use --host without --live-migration.' + ) + raise exceptions.CommandError(msg) + + kwargs = {'host': parsed_args.host} if parsed_args.host else {} + server.migrate(**kwargs) if parsed_args.wait: if utils.wait_for_status( @@ -1601,6 +1751,12 @@ class RebuildServer(command.ShowOne): '(repeat option to set multiple values)'), ) parser.add_argument( + '--description', + metavar='<description>', + help=_('New description for the server (supported by ' + '--os-compute-api-version 2.19 or above'), + ) + parser.add_argument( '--wait', action='store_true', help=_('Wait for rebuild to complete'), @@ -1644,6 +1800,12 @@ class RebuildServer(command.ShowOne): kwargs = {} if parsed_args.property: kwargs['meta'] = parsed_args.property + if parsed_args.description: + if server.api_version < api_versions.APIVersion("2.19"): + msg = _("Description is not supported for " + "--os-compute-api-version less than 2.19") + raise exceptions.CommandError(msg) + kwargs['description'] = parsed_args.description if parsed_args.key_name or parsed_args.key_unset: if compute_client.api_version < api_versions.APIVersion('2.54'): @@ -1835,7 +1997,11 @@ class RemoveServerSecurityGroup(command.Command): class RemoveServerVolume(command.Command): - _description = _("Remove volume from server") + _description = _( + "Remove volume from server. " + "Specify ``--os-compute-api-version 2.20`` or higher to remove a " + "volume from a server with status ``SHELVED`` or " + "``SHELVED_OFFLOADED``.") def get_parser(self, prog_name): parser = super(RemoveServerVolume, self).get_parser(prog_name) @@ -2065,6 +2231,12 @@ class SetServer(command.Command): choices=['active', 'error'], help=_('New server state (valid value: active, error)'), ) + parser.add_argument( + '--description', + metavar='<description>', + help=_('New server description (supported by ' + '--os-compute-api-version 2.19 or above)'), + ) return parser def take_action(self, parsed_args): @@ -2096,6 +2268,13 @@ class SetServer(command.Command): msg = _("Passwords do not match, password unchanged") raise exceptions.CommandError(msg) + if parsed_args.description: + if server.api_version < api_versions.APIVersion("2.19"): + msg = _("Description is not supported for " + "--os-compute-api-version less than 2.19") + raise exceptions.CommandError(msg) + server.update(description=parsed_args.description) + class ShelveServer(command.Command): _description = _("Shelve server(s)") @@ -2455,6 +2634,13 @@ class UnsetServer(command.Command): help=_('Property key to remove from server ' '(repeat option to remove multiple values)'), ) + parser.add_argument( + '--description', + dest='description', + action='store_true', + help=_('Unset server description (supported by ' + '--os-compute-api-version 2.19 or above)'), + ) return parser def take_action(self, parsed_args): @@ -2470,6 +2656,16 @@ class UnsetServer(command.Command): parsed_args.property, ) + if parsed_args.description: + if compute_client.api_version < api_versions.APIVersion("2.19"): + msg = _("Description is not supported for " + "--os-compute-api-version less than 2.19") + raise exceptions.CommandError(msg) + compute_client.servers.update( + server, + description="", + ) + class UnshelveServer(command.Command): _description = _("Unshelve server(s)") diff --git a/openstackclient/compute/v2/server_event.py b/openstackclient/compute/v2/server_event.py index c7d2e2e3..6d33d02d 100644 --- a/openstackclient/compute/v2/server_event.py +++ b/openstackclient/compute/v2/server_event.py @@ -28,7 +28,10 @@ LOG = logging.getLogger(__name__) class ListServerEvent(command.Lister): - _description = _("List recent events of a server") + _description = _( + "List recent events of a server. " + "Specify ``--os-compute-api-version 2.21`` " + "or higher to show events for a deleted server.") def get_parser(self, prog_name): parser = super(ListServerEvent, self).get_parser(prog_name) @@ -92,8 +95,11 @@ class ListServerEvent(command.Lister): class ShowServerEvent(command.ShowOne): _description = _( - "Show server event details. Specify ``--os-compute-api-version 2.51`` " - "or higher to show events for non-admin users.") + "Show server event details. " + "Specify ``--os-compute-api-version 2.21`` " + "or higher to show event details for a deleted server. " + "Specify ``--os-compute-api-version 2.51`` " + "or higher to show event details for non-admin users.") def get_parser(self, prog_name): parser = super(ShowServerEvent, self).get_parser(prog_name) |
