diff options
Diffstat (limited to 'openstackclient/compute')
| -rw-r--r-- | openstackclient/compute/v2/host.py | 60 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server.py | 42 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server_migration.py | 82 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server_volume.py | 73 | ||||
| -rw-r--r-- | openstackclient/compute/v2/service.py | 10 |
5 files changed, 155 insertions, 112 deletions
diff --git a/openstackclient/compute/v2/host.py b/openstackclient/compute/v2/host.py index 07c92a8c..e6dd3a6f 100644 --- a/openstackclient/compute/v2/host.py +++ b/openstackclient/compute/v2/host.py @@ -22,10 +22,10 @@ from openstackclient.i18n import _ class ListHost(command.Lister): - _description = _("List hosts") + _description = _("DEPRECATED: List hosts") def get_parser(self, prog_name): - parser = super(ListHost, self).get_parser(prog_name) + parser = super().get_parser(prog_name) parser.add_argument( "--zone", metavar="<zone>", @@ -34,17 +34,33 @@ class ListHost(command.Lister): return parser def take_action(self, parsed_args): - compute_client = self.app.client_manager.compute + compute_client = self.app.client_manager.sdk_connection.compute columns = ( "Host Name", "Service", "Zone" ) - data = compute_client.api.host_list(parsed_args.zone) - return (columns, - (utils.get_dict_properties( - s, columns, - ) for s in data)) + + self.log.warning( + "API has been deprecated. " + "Please consider using 'hypervisor list' instead." + ) + + # doing this since openstacksdk has decided not to support this + # deprecated command + hosts = compute_client.get( + '/os-hosts', microversion='2.1' + ).json().get('hosts') + + if parsed_args.zone is not None: + filtered_hosts = [] + for host in hosts: + if host['zone'] == parsed_args.zone: + filtered_hosts.append(host) + + hosts = filtered_hosts + + return columns, (utils.get_dict_properties(s, columns) for s in hosts) class SetHost(command.Command): @@ -102,10 +118,10 @@ class SetHost(command.Command): class ShowHost(command.Lister): - _description = _("Display host details") + _description = _("DEPRECATED: Display host details") def get_parser(self, prog_name): - parser = super(ShowHost, self).get_parser(prog_name) + parser = super().get_parser(prog_name) parser.add_argument( "host", metavar="<host>", @@ -114,7 +130,7 @@ class ShowHost(command.Lister): return parser def take_action(self, parsed_args): - compute_client = self.app.client_manager.compute + compute_client = self.app.client_manager.sdk_connection.compute columns = ( "Host", "Project", @@ -123,9 +139,21 @@ class ShowHost(command.Lister): "Disk GB" ) - data = compute_client.api.host_show(parsed_args.host) + self.log.warning( + "API has been deprecated. " + "Please consider using 'hypervisor show' instead." + ) + + # doing this since openstacksdk has decided not to support this + # deprecated command + resources = compute_client.get( + '/os-hosts/' + parsed_args.host, + microversion='2.1' + ).json().get('host') + + data = [] + if resources is not None: + for resource in resources: + data.append(resource['resource']) - return (columns, - (utils.get_dict_properties( - s, columns, - ) for s in data)) + return columns, (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 156f855f..0c062a9e 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -608,10 +608,10 @@ class AddServerSecurityGroup(command.Command): class AddServerVolume(command.ShowOne): - _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``.") + _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) @@ -3766,11 +3766,10 @@ class RemoveServerSecurityGroup(command.Command): class RemoveServerVolume(command.Command): - _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``.") + _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) @@ -3807,11 +3806,10 @@ class RemoveServerVolume(command.Command): class RescueServer(command.Command): - _description = _( - "Put server in rescue mode. " - "Specify ``--os-compute-api-version 2.87`` or higher to rescue a " - "server booted from a volume." - ) + _description = _("""Put server in rescue mode. + +Specify ``--os-compute-api-version 2.87`` or higher to rescue a +server booted from a volume.""") def get_parser(self, prog_name): parser = super(RescueServer, self).get_parser(prog_name) @@ -3967,9 +3965,7 @@ Confirm (verify) success of resize operation and release the old server.""") # TODO(stephenfin): Remove in OSC 7.0 class MigrateConfirm(ResizeConfirm): - _description = _("""DEPRECATED: Confirm server migration. - -Use 'server migration confirm' instead.""") + _description = _("DEPRECATED: Use 'server migration confirm' instead.") def take_action(self, parsed_args): msg = _( @@ -4015,9 +4011,7 @@ one.""") # TODO(stephenfin): Remove in OSC 7.0 class MigrateRevert(ResizeRevert): - _description = _("""Revert server migration. - -Use 'server migration revert' instead.""") + _description = _("DEPRECATED: Use 'server migration revert' instead.") def take_action(self, parsed_args): msg = _( @@ -4362,10 +4356,10 @@ class ShelveServer(command.Command): class ShowServer(command.ShowOne): - _description = _( - "Show server details. Specify ``--os-compute-api-version 2.47`` " - "or higher to see the embedded flavor information for the server." - ) + _description = _("""Show server details. + +Specify ``--os-compute-api-version 2.47`` or higher to see the embedded flavor +information for the server.""") def get_parser(self, prog_name): parser = super(ShowServer, self).get_parser(prog_name) diff --git a/openstackclient/compute/v2/server_migration.py b/openstackclient/compute/v2/server_migration.py index 016d15d7..91575c1e 100644 --- a/openstackclient/compute/v2/server_migration.py +++ b/openstackclient/compute/v2/server_migration.py @@ -14,7 +14,6 @@ import uuid -from novaclient import api_versions from openstack import utils as sdk_utils from osc_lib.command import command from osc_lib import exceptions @@ -256,7 +255,7 @@ class ListMigration(command.Lister): def _get_migration_by_uuid(compute_client, server_id, migration_uuid): - for migration in compute_client.server_migrations.list(server_id): + for migration in compute_client.server_migrations(server_id): if migration.uuid == migration_uuid: return migration break @@ -290,9 +289,9 @@ class ShowMigration(command.ShowOne): return parser def take_action(self, parsed_args): - compute_client = self.app.client_manager.compute + compute_client = self.app.client_manager.sdk_connection.compute - if compute_client.api_version < api_versions.APIVersion('2.24'): + if not sdk_utils.supports_microversion(compute_client, '2.24'): msg = _( '--os-compute-api-version 2.24 or greater is required to ' 'support the server migration show command' @@ -308,16 +307,16 @@ class ShowMigration(command.ShowOne): ) raise exceptions.CommandError(msg) - if compute_client.api_version < api_versions.APIVersion('2.59'): + if not sdk_utils.supports_microversion(compute_client, '2.59'): msg = _( '--os-compute-api-version 2.59 or greater is required to ' 'retrieve server migrations by UUID' ) raise exceptions.CommandError(msg) - server = utils.find_resource( - compute_client.servers, + server = compute_client.find_server( parsed_args.server, + ignore_missing=False, ) # the nova API doesn't currently allow retrieval by UUID but it's a @@ -328,11 +327,13 @@ class ShowMigration(command.ShowOne): compute_client, server.id, parsed_args.migration, ) else: - server_migration = compute_client.server_migrations.get( - server.id, parsed_args.migration, + server_migration = compute_client.get_server_migration( + server.id, + parsed_args.migration, + ignore_missing=False, ) - columns = ( + column_headers = ( 'ID', 'Server UUID', 'Status', @@ -351,14 +352,35 @@ class ShowMigration(command.ShowOne): 'Updated At', ) - if compute_client.api_version >= api_versions.APIVersion('2.59'): - columns += ('UUID',) + columns = ( + 'id', + 'server_id', + 'status', + 'source_compute', + 'source_node', + 'dest_compute', + 'dest_host', + 'dest_node', + 'memory_total_bytes', + 'memory_processed_bytes', + 'memory_remaining_bytes', + 'disk_total_bytes', + 'disk_processed_bytes', + 'disk_remaining_bytes', + 'created_at', + 'updated_at', + ) - if compute_client.api_version >= api_versions.APIVersion('2.80'): - columns += ('User ID', 'Project ID') + if sdk_utils.supports_microversion(compute_client, '2.59'): + column_headers += ('UUID',) + columns += ('uuid',) + + if sdk_utils.supports_microversion(compute_client, '2.80'): + column_headers += ('User ID', 'Project ID') + columns += ('user_id', 'project_id') data = utils.get_item_properties(server_migration, columns) - return columns, data + return column_headers, data class AbortMigration(command.Command): @@ -382,9 +404,9 @@ class AbortMigration(command.Command): return parser def take_action(self, parsed_args): - compute_client = self.app.client_manager.compute + compute_client = self.app.client_manager.sdk_connection.compute - if compute_client.api_version < api_versions.APIVersion('2.24'): + if not sdk_utils.supports_microversion(compute_client, '2.24'): msg = _( '--os-compute-api-version 2.24 or greater is required to ' 'support the server migration abort command' @@ -400,16 +422,16 @@ class AbortMigration(command.Command): ) raise exceptions.CommandError(msg) - if compute_client.api_version < api_versions.APIVersion('2.59'): + if not sdk_utils.supports_microversion(compute_client, '2.59'): msg = _( '--os-compute-api-version 2.59 or greater is required to ' 'abort server migrations by UUID' ) raise exceptions.CommandError(msg) - server = utils.find_resource( - compute_client.servers, + server = compute_client.find_server( parsed_args.server, + ignore_missing=False, ) # the nova API doesn't currently allow retrieval by UUID but it's a @@ -421,8 +443,10 @@ class AbortMigration(command.Command): compute_client, server.id, parsed_args.migration, ).id - compute_client.server_migrations.live_migration_abort( - server.id, migration_id, + compute_client.abort_server_migration( + migration_id, + server.id, + ignore_missing=False, ) @@ -447,9 +471,9 @@ class ForceCompleteMigration(command.Command): return parser def take_action(self, parsed_args): - compute_client = self.app.client_manager.compute + compute_client = self.app.client_manager.sdk_connection.compute - if compute_client.api_version < api_versions.APIVersion('2.22'): + if not sdk_utils.supports_microversion(compute_client, '2.22'): msg = _( '--os-compute-api-version 2.22 or greater is required to ' 'support the server migration force complete command' @@ -465,16 +489,16 @@ class ForceCompleteMigration(command.Command): ) raise exceptions.CommandError(msg) - if compute_client.api_version < api_versions.APIVersion('2.59'): + if not sdk_utils.supports_microversion(compute_client, '2.59'): msg = _( '--os-compute-api-version 2.59 or greater is required to ' 'abort server migrations by UUID' ) raise exceptions.CommandError(msg) - server = utils.find_resource( - compute_client.servers, + server = compute_client.find_server( parsed_args.server, + ignore_missing=False, ) # the nova API doesn't currently allow retrieval by UUID but it's a @@ -486,6 +510,6 @@ class ForceCompleteMigration(command.Command): compute_client, server.id, parsed_args.migration, ).id - compute_client.server_migrations.live_migrate_force_complete( - server.id, migration_id, + compute_client.force_complete_server_migration( + migration_id, server.id ) diff --git a/openstackclient/compute/v2/server_volume.py b/openstackclient/compute/v2/server_volume.py index d53cec93..b4322c0b 100644 --- a/openstackclient/compute/v2/server_volume.py +++ b/openstackclient/compute/v2/server_volume.py @@ -14,7 +14,7 @@ """Compute v2 Server action implementations""" -from novaclient import api_versions +from openstack import utils as sdk_utils from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils @@ -34,27 +34,25 @@ class ListServerVolume(command.Lister): return parser def take_action(self, parsed_args): + compute_client = self.app.client_manager.sdk_connection.compute - compute_client = self.app.client_manager.compute - - server = utils.find_resource( - compute_client.servers, + server = compute_client.find_server( parsed_args.server, + ignore_missing=False, ) - - volumes = compute_client.volumes.get_server_volumes(server.id) + volumes = compute_client.volume_attachments(server) columns = () column_headers = () - if compute_client.api_version < api_versions.APIVersion('2.89'): + if not sdk_utils.supports_microversion(compute_client, '2.89'): columns += ('id',) column_headers += ('ID',) columns += ( 'device', - 'serverId', - 'volumeId', + 'server_id', + 'volume_id', ) column_headers += ( 'Device', @@ -62,40 +60,36 @@ class ListServerVolume(command.Lister): 'Volume ID', ) - if compute_client.api_version >= api_versions.APIVersion('2.70'): + if sdk_utils.supports_microversion(compute_client, '2.70'): columns += ('tag',) column_headers += ('Tag',) - if compute_client.api_version >= api_versions.APIVersion('2.79'): + if sdk_utils.supports_microversion(compute_client, '2.79'): columns += ('delete_on_termination',) column_headers += ('Delete On Termination?',) - if compute_client.api_version >= api_versions.APIVersion('2.89'): - columns += ('attachment_id', 'bdm_uuid') + if sdk_utils.supports_microversion(compute_client, '2.89'): + columns += ('attachment_id', 'bdm_id') column_headers += ('Attachment ID', 'BlockDeviceMapping UUID') return ( column_headers, - ( - utils.get_item_properties( - s, columns, mixed_case_fields=('serverId', 'volumeId') - ) for s in volumes - ), + (utils.get_item_properties(s, columns) for s in volumes), ) -class UpdateServerVolume(command.Command): +class SetServerVolume(command.Command): """Update a volume attachment on the server.""" def get_parser(self, prog_name): - parser = super(UpdateServerVolume, self).get_parser(prog_name) + parser = super().get_parser(prog_name) parser.add_argument( 'server', help=_('Server to update volume for (name or ID)'), ) parser.add_argument( 'volume', - help=_('Volume (ID)'), + help=_('Volume to update attachment for (name or ID)'), ) termination_group = parser.add_mutually_exclusive_group() termination_group.add_argument( @@ -120,31 +114,34 @@ class UpdateServerVolume(command.Command): return parser def take_action(self, parsed_args): - - compute_client = self.app.client_manager.compute + compute_client = self.app.client_manager.sdk_connection.compute + volume_client = self.app.client_manager.sdk_connection.volume if parsed_args.delete_on_termination is not None: - if compute_client.api_version < api_versions.APIVersion('2.85'): + if not sdk_utils.supports_microversion(compute_client, '2.85'): msg = _( '--os-compute-api-version 2.85 or greater is required to ' - 'support the --(no-)delete-on-termination option' + 'support the -delete-on-termination or ' + '--preserve-on-termination option' ) raise exceptions.CommandError(msg) - server = utils.find_resource( - compute_client.servers, + server = compute_client.find_server( parsed_args.server, + ignore_missing=False, ) - - # NOTE(stephenfin): This may look silly, and that's because it is. - # This API was originally used only for the swapping volumes, which - # is an internal operation that should only be done by - # orchestration software rather than a human. We're not going to - # expose that, but we are going to expose the ability to change the - # delete on termination behavior. - compute_client.volumes.update_server_volume( - server.id, - parsed_args.volume, + volume = volume_client.find_volume( parsed_args.volume, + ignore_missing=False, + ) + + compute_client.update_volume_attachment( + server, + volume, delete_on_termination=parsed_args.delete_on_termination, ) + + +# Legacy alias +class UpdateServerVolume(SetServerVolume): + """DEPRECATED: Use 'server volume set' instead.""" diff --git a/openstackclient/compute/v2/service.py b/openstackclient/compute/v2/service.py index 8605156c..fad717c9 100644 --- a/openstackclient/compute/v2/service.py +++ b/openstackclient/compute/v2/service.py @@ -71,11 +71,11 @@ class DeleteService(command.Command): class ListService(command.Lister): - _description = _("List compute services. Using " - "``--os-compute-api-version`` 2.53 or greater will " - "return the ID as a UUID value which can be used to " - "uniquely identify the service in a multi-cell " - "deployment.") + _description = _("""List compute services. + +Using ``--os-compute-api-version`` 2.53 or greater will return the ID as a UUID +value which can be used to uniquely identify the service in a multi-cell +deployment.""") def get_parser(self, prog_name): parser = super(ListService, self).get_parser(prog_name) |
