diff options
| author | Stephen Finucane <sfinucan@redhat.com> | 2023-05-08 10:54:22 +0100 |
|---|---|---|
| committer | Stephen Finucane <sfinucan@redhat.com> | 2023-05-10 10:51:30 +0100 |
| commit | 35ba1d8f1304d3255b96b704d524666ec5b6fea2 (patch) | |
| tree | 6d4ab560d4086e8b1a1f935b8531d7e85550cc36 /openstackclient/volume | |
| parent | 28ffa2bf9f017212da5eb84b0cf74df62e2f5eb9 (diff) | |
| download | python-openstackclient-35ba1d8f1304d3255b96b704d524666ec5b6fea2.tar.gz | |
Blacken openstackclient.volume
Black used with the '-l 79 -S' flags.
A future change will ignore this commit in git-blame history by adding a
'git-blame-ignore-revs' file.
Change-Id: Ic318617c67ab7ce6527f9016b759a1d4b0b80802
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/volume')
31 files changed, 1964 insertions, 1175 deletions
diff --git a/openstackclient/volume/client.py b/openstackclient/volume/client.py index 0712fa7b..4615184e 100644 --- a/openstackclient/volume/client.py +++ b/openstackclient/volume/client.py @@ -60,6 +60,7 @@ def make_client(instance): else: version = instance._api_version[API_NAME] from cinderclient import api_versions + # convert to APIVersion object version = api_versions.get_api_version(version) @@ -69,9 +70,7 @@ def make_client(instance): volume_snapshots.Snapshot.NAME_ATTR = 'display_name' volume_client = utils.get_client_class( - API_NAME, - version.ver_major, - API_VERSIONS + API_NAME, version.ver_major, API_VERSIONS ) LOG.debug('Instantiating volume client: %s', volume_client) @@ -84,7 +83,8 @@ def make_client(instance): kwargs = utils.build_kwargs_dict('endpoint_type', instance.interface) endpoint_override = instance.sdk_connection.config.get_endpoint( - 'block-storage') + 'block-storage' + ) client = volume_client( session=instance.session, @@ -105,8 +105,10 @@ def build_option_parser(parser): '--os-volume-api-version', metavar='<volume-api-version>', default=utils.env('OS_VOLUME_API_VERSION'), - help=_('Volume API version, default=%s ' - '(Env: OS_VOLUME_API_VERSION)') % DEFAULT_API_VERSION + help=_( + 'Volume API version, default=%s ' '(Env: OS_VOLUME_API_VERSION)' + ) + % DEFAULT_API_VERSION, ) return parser diff --git a/openstackclient/volume/v1/qos_specs.py b/openstackclient/volume/v1/qos_specs.py index 79dff1c6..87e32ff4 100644 --- a/openstackclient/volume/v1/qos_specs.py +++ b/openstackclient/volume/v1/qos_specs.py @@ -48,10 +48,12 @@ class AssociateQos(command.Command): def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - qos_spec = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_spec) - volume_type = utils.find_resource(volume_client.volume_types, - parsed_args.volume_type) + qos_spec = utils.find_resource( + volume_client.qos_specs, parsed_args.qos_spec + ) + volume_type = utils.find_resource( + volume_client.volume_types, parsed_args.volume_type + ) volume_client.qos_specs.associate(qos_spec.id, volume_type.id) @@ -72,16 +74,22 @@ class CreateQos(command.ShowOne): metavar='<consumer>', choices=consumer_choices, default='both', - help=(_('Consumer of the QoS. Valid consumers: %s ' - "(defaults to 'both')") % - utils.format_list(consumer_choices)) + help=( + _( + 'Consumer of the QoS. Valid consumers: %s ' + "(defaults to 'both')" + ) + % utils.format_list(consumer_choices) + ), ) parser.add_argument( '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set a QoS specification property ' - '(repeat option to set multiple properties)'), + help=_( + 'Set a QoS specification property ' + '(repeat option to set multiple properties)' + ), ) return parser @@ -95,8 +103,11 @@ class CreateQos(command.ShowOne): qos_spec = volume_client.qos_specs.create(parsed_args.name, specs) qos_spec._info.update( - {'properties': - format_columns.DictColumn(qos_spec._info.pop('specs'))} + { + 'properties': format_columns.DictColumn( + qos_spec._info.pop('specs') + ) + } ) return zip(*sorted(qos_spec._info.items())) @@ -116,7 +127,7 @@ class DeleteQos(command.Command): '--force', action='store_true', default=False, - help=_("Allow to delete in-use QoS specification(s)") + help=_("Allow to delete in-use QoS specification(s)"), ) return parser @@ -130,14 +141,20 @@ class DeleteQos(command.Command): volume_client.qos_specs.delete(qos_spec.id, parsed_args.force) except Exception as e: result += 1 - LOG.error(_("Failed to delete QoS specification with " - "name or ID '%(qos)s': %(e)s"), - {'qos': i, 'e': e}) + LOG.error( + _( + "Failed to delete QoS specification with " + "name or ID '%(qos)s': %(e)s" + ), + {'qos': i, 'e': e}, + ) if result > 0: total = len(parsed_args.qos_specs) - msg = (_("%(result)s of %(total)s QoS specifications failed" - " to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s QoS specifications failed" + " to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -168,12 +185,14 @@ class DisassociateQos(command.Command): def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - qos_spec = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_spec) + qos_spec = utils.find_resource( + volume_client.qos_specs, parsed_args.qos_spec + ) if parsed_args.volume_type: - volume_type = utils.find_resource(volume_client.volume_types, - parsed_args.volume_type) + volume_type = utils.find_resource( + volume_client.volume_types, parsed_args.volume_type + ) volume_client.qos_specs.disassociate(qos_spec.id, volume_type.id) elif parsed_args.all: volume_client.qos_specs.disassociate_all(qos_spec.id) @@ -203,16 +222,27 @@ class ListQos(command.Lister): raise display_columns = ( - 'ID', 'Name', 'Consumer', 'Associations', 'Properties') + 'ID', + 'Name', + 'Consumer', + 'Associations', + 'Properties', + ) columns = ('ID', 'Name', 'Consumer', 'Associations', 'Specs') - return (display_columns, - (utils.get_dict_properties( - s._info, columns, + return ( + display_columns, + ( + utils.get_dict_properties( + s._info, + columns, formatters={ 'Specs': format_columns.DictColumn, - 'Associations': format_columns.ListColumn + 'Associations': format_columns.ListColumn, }, - ) for s in qos_specs_list)) + ) + for s in qos_specs_list + ), + ) class SetQos(command.Command): @@ -229,19 +259,21 @@ class SetQos(command.Command): '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Property to add or modify for this QoS specification ' - '(repeat option to set multiple properties)'), + help=_( + 'Property to add or modify for this QoS specification ' + '(repeat option to set multiple properties)' + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - qos_spec = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_spec) + qos_spec = utils.find_resource( + volume_client.qos_specs, parsed_args.qos_spec + ) if parsed_args.property: - volume_client.qos_specs.set_keys(qos_spec.id, - parsed_args.property) + volume_client.qos_specs.set_keys(qos_spec.id, parsed_args.property) class ShowQos(command.ShowOne): @@ -258,19 +290,25 @@ class ShowQos(command.ShowOne): def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - qos_spec = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_spec) + qos_spec = utils.find_resource( + volume_client.qos_specs, parsed_args.qos_spec + ) qos_associations = volume_client.qos_specs.get_associations(qos_spec) if qos_associations: - associations = [association.name - for association in qos_associations] - qos_spec._info.update({ - 'associations': format_columns.ListColumn(associations) - }) + associations = [ + association.name for association in qos_associations + ] + qos_spec._info.update( + {'associations': format_columns.ListColumn(associations)} + ) qos_spec._info.update( - {'properties': - format_columns.DictColumn(qos_spec._info.pop('specs'))}) + { + 'properties': format_columns.DictColumn( + qos_spec._info.pop('specs') + ) + } + ) return zip(*sorted(qos_spec._info.items())) @@ -289,16 +327,20 @@ class UnsetQos(command.Command): '--property', metavar='<key>', action='append', - help=_('Property to remove from the QoS specification. ' - '(repeat option to unset multiple properties)'), + help=_( + 'Property to remove from the QoS specification. ' + '(repeat option to unset multiple properties)' + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - qos_spec = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_spec) + qos_spec = utils.find_resource( + volume_client.qos_specs, parsed_args.qos_spec + ) if parsed_args.property: - volume_client.qos_specs.unset_keys(qos_spec.id, - parsed_args.property) + volume_client.qos_specs.unset_keys( + qos_spec.id, parsed_args.property + ) diff --git a/openstackclient/volume/v1/service.py b/openstackclient/volume/v1/service.py index d468c6ff..fb5869d5 100644 --- a/openstackclient/volume/v1/service.py +++ b/openstackclient/volume/v1/service.py @@ -29,18 +29,18 @@ class ListService(command.Lister): parser.add_argument( "--host", metavar="<host>", - help=_("List services on specified host (name only)") + help=_("List services on specified host (name only)"), ) parser.add_argument( "--service", metavar="<service>", - help=_("List only specified service (name only)") + help=_("List only specified service (name only)"), ) parser.add_argument( "--long", action="store_true", default=False, - help=_("List additional fields in output") + help=_("List additional fields in output"), ) return parser @@ -55,7 +55,7 @@ class ListService(command.Lister): "Status", "State", "Updated At", - "Disabled Reason" + "Disabled Reason", ] else: columns = [ @@ -64,15 +64,22 @@ class ListService(command.Lister): "Zone", "Status", "State", - "Updated At" + "Updated At", ] - data = service_client.services.list(parsed_args.host, - parsed_args.service) - return (columns, - (utils.get_item_properties( - s, columns, - ) for s in data)) + data = service_client.services.list( + parsed_args.host, parsed_args.service + ) + return ( + columns, + ( + utils.get_item_properties( + s, + columns, + ) + for s in data + ), + ) class SetService(command.Command): @@ -80,51 +87,50 @@ class SetService(command.Command): def get_parser(self, prog_name): parser = super(SetService, self).get_parser(prog_name) - parser.add_argument( - "host", - metavar="<host>", - help=_("Name of host") - ) + parser.add_argument("host", metavar="<host>", help=_("Name of host")) parser.add_argument( "service", metavar="<service>", - help=_("Name of service (Binary name)") + help=_("Name of service (Binary name)"), ) enabled_group = parser.add_mutually_exclusive_group() enabled_group.add_argument( - "--enable", - action="store_true", - help=_("Enable volume service") + "--enable", action="store_true", help=_("Enable volume service") ) enabled_group.add_argument( - "--disable", - action="store_true", - help=_("Disable volume service") + "--disable", action="store_true", help=_("Disable volume service") ) parser.add_argument( "--disable-reason", metavar="<reason>", - help=_("Reason for disabling the service " - "(should be used with --disable option)") + help=_( + "Reason for disabling the service " + "(should be used with --disable option)" + ), ) return parser def take_action(self, parsed_args): if parsed_args.disable_reason and not parsed_args.disable: - msg = _("Cannot specify option --disable-reason without " - "--disable specified.") + msg = _( + "Cannot specify option --disable-reason without " + "--disable specified." + ) raise exceptions.CommandError(msg) service_client = self.app.client_manager.volume if parsed_args.enable: service_client.services.enable( - parsed_args.host, parsed_args.service) + parsed_args.host, parsed_args.service + ) if parsed_args.disable: if parsed_args.disable_reason: service_client.services.disable_log_reason( parsed_args.host, parsed_args.service, - parsed_args.disable_reason) + parsed_args.disable_reason, + ) else: service_client.services.disable( - parsed_args.host, parsed_args.service) + parsed_args.host, parsed_args.service + ) diff --git a/openstackclient/volume/v1/volume.py b/openstackclient/volume/v1/volume.py index 198b890f..ec989f02 100644 --- a/openstackclient/volume/v1/volume.py +++ b/openstackclient/volume/v1/volume.py @@ -70,10 +70,11 @@ def _check_size_arg(args): volume is not specified. """ - if ((args.snapshot or args.source) - is None and args.size is None): - msg = _("--size is a required option if snapshot " - "or source volume is not specified.") + if (args.snapshot or args.source) is None and args.size is None: + msg = _( + "--size is a required option if snapshot " + "or source volume is not specified." + ) raise exceptions.CommandError(msg) @@ -91,8 +92,10 @@ class CreateVolume(command.ShowOne): '--size', metavar='<size>', type=int, - help=_("Volume size in GB (Required unless --snapshot or " - "--source is specified)"), + help=_( + "Volume size in GB (Required unless --snapshot or " + "--source is specified)" + ), ) parser.add_argument( '--type', @@ -144,30 +147,32 @@ class CreateVolume(command.ShowOne): '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set a property on this volume ' - '(repeat option to set multiple properties)'), + help=_( + 'Set a property on this volume ' + '(repeat option to set multiple properties)' + ), ) bootable_group = parser.add_mutually_exclusive_group() bootable_group.add_argument( "--bootable", action="store_true", - help=_("Mark volume as bootable") + help=_("Mark volume as bootable"), ) bootable_group.add_argument( "--non-bootable", action="store_true", - help=_("Mark volume as non-bootable (default)") + help=_("Mark volume as non-bootable (default)"), ) readonly_group = parser.add_mutually_exclusive_group() readonly_group.add_argument( "--read-only", action="store_true", - help=_("Set volume to read-only access mode") + help=_("Set volume to read-only access mode"), ) readonly_group.add_argument( "--read-write", action="store_true", - help=_("Set volume to read-write access mode (default)") + help=_("Set volume to read-write access mode (default)"), ) return parser @@ -229,11 +234,10 @@ class CreateVolume(command.ShowOne): volume.id, success_status=['available'], error_status=['error'], - sleep_time=1 + sleep_time=1, ): volume_client.volumes.set_bootable( - volume.id, - parsed_args.bootable + volume.id, parsed_args.bootable ) else: msg = _( @@ -250,11 +254,10 @@ class CreateVolume(command.ShowOne): volume.id, success_status=['available'], error_status=['error'], - sleep_time=1 + sleep_time=1, ): volume_client.volumes.update_readonly_flag( - volume.id, - parsed_args.read_only + volume.id, parsed_args.read_only ) else: msg = _( @@ -263,14 +266,20 @@ class CreateVolume(command.ShowOne): ) raise exceptions.CommandError(msg) except Exception as e: - LOG.error(_("Failed to set volume read-only access " - "mode flag: %s"), e) + LOG.error( + _( + "Failed to set volume read-only access " + "mode flag: %s" + ), + e, + ) # Map 'metadata' column to 'properties' volume._info.update( { - 'properties': - format_columns.DictColumn(volume._info.pop('metadata')), + 'properties': format_columns.DictColumn( + volume._info.pop('metadata') + ), 'type': volume._info.pop('volume_type'), }, ) @@ -299,8 +308,10 @@ class DeleteVolume(command.Command): '--force', action='store_true', default=False, - help=_('Attempt forced removal of volume(s), regardless of state ' - '(defaults to False)'), + help=_( + 'Attempt forced removal of volume(s), regardless of state ' + '(defaults to False)' + ), ) return parser @@ -310,22 +321,27 @@ class DeleteVolume(command.Command): for i in parsed_args.volumes: try: - volume_obj = utils.find_resource( - volume_client.volumes, i) + volume_obj = utils.find_resource(volume_client.volumes, i) if parsed_args.force: volume_client.volumes.force_delete(volume_obj.id) else: volume_client.volumes.delete(volume_obj.id) except Exception as e: result += 1 - LOG.error(_("Failed to delete volume with " - "name or ID '%(volume)s': %(e)s"), - {'volume': i, 'e': e}) + LOG.error( + _( + "Failed to delete volume with " + "name or ID '%(volume)s': %(e)s" + ), + {'volume': i, 'e': e}, + ) if result > 0: total = len(parsed_args.volumes) - msg = (_("%(result)s of %(total)s volumes failed " - "to delete.") % {'result': result, 'total': total}) + msg = _("%(result)s of %(total)s volumes failed " "to delete.") % { + 'result': result, + 'total': total, + } raise exceptions.CommandError(msg) @@ -373,7 +389,6 @@ class ListVolume(command.Lister): return parser def take_action(self, parsed_args): - volume_client = self.app.client_manager.volume compute_client = self.app.client_manager.compute @@ -423,7 +438,8 @@ class ListVolume(command.Lister): # Just forget it if there's any trouble pass AttachmentsColumnWithCache = functools.partial( - AttachmentsColumn, server_cache=server_cache) + AttachmentsColumn, server_cache=server_cache + ) search_opts = { 'all_tenants': parsed_args.all_projects, @@ -439,14 +455,23 @@ class ListVolume(command.Lister): limit=parsed_args.limit, ) column_headers = utils.backward_compat_col_lister( - column_headers, parsed_args.columns, {'Display Name': 'Name'}) + column_headers, parsed_args.columns, {'Display Name': 'Name'} + ) - return (column_headers, - (utils.get_item_properties( - s, columns, - formatters={'Metadata': format_columns.DictColumn, - 'Attachments': AttachmentsColumnWithCache}, - ) for s in data)) + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, + formatters={ + 'Metadata': format_columns.DictColumn, + 'Attachments': AttachmentsColumnWithCache, + }, + ) + for s in data + ), + ) class MigrateVolume(command.Command): @@ -457,27 +482,34 @@ class MigrateVolume(command.Command): parser.add_argument( 'volume', metavar="<volume>", - help=_("Volume to migrate (name or ID)") + help=_("Volume to migrate (name or ID)"), ) parser.add_argument( '--host', metavar="<host>", required=True, - help=_("Destination host (takes the form: host@backend-name#pool)") + help=_( + "Destination host (takes the form: host@backend-name#pool)" + ), ) parser.add_argument( '--force-host-copy', action="store_true", - help=_("Enable generic host-based force-migration, " - "which bypasses driver optimizations") + help=_( + "Enable generic host-based force-migration, " + "which bypasses driver optimizations" + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume volume = utils.find_resource(volume_client.volumes, parsed_args.volume) - volume_client.volumes.migrate_volume(volume.id, parsed_args.host, - parsed_args.force_host_copy,) + volume_client.volumes.migrate_volume( + volume.id, + parsed_args.host, + parsed_args.force_host_copy, + ) class SetVolume(command.Command): @@ -510,39 +542,43 @@ class SetVolume(command.Command): "--no-property", dest="no_property", action="store_true", - help=_("Remove all properties from <volume> " - "(specify both --no-property and --property to " - "remove the current properties before setting " - "new properties.)"), + help=_( + "Remove all properties from <volume> " + "(specify both --no-property and --property to " + "remove the current properties before setting " + "new properties.)" + ), ) parser.add_argument( '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set a property on this volume ' - '(repeat option to set multiple properties)'), + help=_( + 'Set a property on this volume ' + '(repeat option to set multiple properties)' + ), ) bootable_group = parser.add_mutually_exclusive_group() bootable_group.add_argument( "--bootable", action="store_true", - help=_("Mark volume as bootable") + help=_("Mark volume as bootable"), ) bootable_group.add_argument( "--non-bootable", action="store_true", - help=_("Mark volume as non-bootable") + help=_("Mark volume as non-bootable"), ) readonly_group = parser.add_mutually_exclusive_group() readonly_group.add_argument( "--read-only", action="store_true", - help=_("Set volume to read-only access mode") + help=_("Set volume to read-only access mode"), ) readonly_group.add_argument( "--read-write", action="store_true", - help=_("Set volume to read-write access mode") + help=_("Set volume to read-write access mode"), ) return parser @@ -554,12 +590,18 @@ class SetVolume(command.Command): if parsed_args.size: try: if volume.status != 'available': - msg = (_("Volume is in %s state, it must be available " - "before size can be extended") % volume.status) + msg = ( + _( + "Volume is in %s state, it must be available " + "before size can be extended" + ) + % volume.status + ) raise exceptions.CommandError(msg) if parsed_args.size <= volume.size: - msg = (_("New size must be greater than %s GB") - % volume.size) + msg = ( + _("New size must be greater than %s GB") % volume.size + ) raise exceptions.CommandError(msg) volume_client.volumes.extend(volume.id, parsed_args.size) except Exception as e: @@ -569,7 +611,8 @@ class SetVolume(command.Command): if parsed_args.no_property: try: volume_client.volumes.delete_metadata( - volume.id, volume.metadata.keys()) + volume.id, volume.metadata.keys() + ) except Exception as e: LOG.error(_("Failed to clean volume properties: %s"), e) result += 1 @@ -577,26 +620,32 @@ class SetVolume(command.Command): if parsed_args.property: try: volume_client.volumes.set_metadata( - volume.id, - parsed_args.property) + volume.id, parsed_args.property + ) except Exception as e: LOG.error(_("Failed to set volume property: %s"), e) result += 1 if parsed_args.bootable or parsed_args.non_bootable: try: volume_client.volumes.set_bootable( - volume.id, parsed_args.bootable) + volume.id, parsed_args.bootable + ) except Exception as e: LOG.error(_("Failed to set volume bootable property: %s"), e) result += 1 if parsed_args.read_only or parsed_args.read_write: try: volume_client.volumes.update_readonly_flag( - volume.id, - parsed_args.read_only) + volume.id, parsed_args.read_only + ) except Exception as e: - LOG.error(_("Failed to set volume read-only access " - "mode flag: %s"), e) + LOG.error( + _( + "Failed to set volume read-only access " + "mode flag: %s" + ), + e, + ) result += 1 kwargs = {} if parsed_args.name: @@ -607,13 +656,19 @@ class SetVolume(command.Command): try: volume_client.volumes.update(volume.id, **kwargs) except Exception as e: - LOG.error(_("Failed to update volume display name " - "or display description: %s"), e) + LOG.error( + _( + "Failed to update volume display name " + "or display description: %s" + ), + e, + ) result += 1 if result > 0: - raise exceptions.CommandError(_("One or more of the " - "set operations failed")) + raise exceptions.CommandError( + _("One or more of the " "set operations failed") + ) class ShowVolume(command.ShowOne): @@ -634,15 +689,19 @@ class ShowVolume(command.ShowOne): # Map 'metadata' column to 'properties' volume._info.update( { - 'properties': - format_columns.DictColumn(volume._info.pop('metadata')), + 'properties': format_columns.DictColumn( + volume._info.pop('metadata') + ), 'type': volume._info.pop('volume_type'), }, ) if 'os-vol-tenant-attr:tenant_id' in volume._info: volume._info.update( - {'project_id': volume._info.pop( - 'os-vol-tenant-attr:tenant_id')} + { + 'project_id': volume._info.pop( + 'os-vol-tenant-attr:tenant_id' + ) + } ) # Replace "display_name" by "name", keep consistent in v1 and v2 if 'display_name' in volume._info: @@ -669,15 +728,16 @@ class UnsetVolume(command.Command): '--property', metavar='<key>', action='append', - help=_('Remove a property from volume ' - '(repeat option to remove multiple properties)'), + help=_( + 'Remove a property from volume ' + '(repeat option to remove multiple properties)' + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - volume = utils.find_resource( - volume_client.volumes, parsed_args.volume) + volume = utils.find_resource(volume_client.volumes, parsed_args.volume) if parsed_args.property: volume_client.volumes.delete_metadata( diff --git a/openstackclient/volume/v1/volume_backup.py b/openstackclient/volume/v1/volume_backup.py index 790cb463..241fd301 100644 --- a/openstackclient/volume/v1/volume_backup.py +++ b/openstackclient/volume/v1/volume_backup.py @@ -87,13 +87,14 @@ class CreateVolumeBackup(command.ShowOne): def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - volume_id = utils.find_resource(volume_client.volumes, - parsed_args.volume).id + volume_id = utils.find_resource( + volume_client.volumes, parsed_args.volume + ).id backup = volume_client.backups.create( volume_id, parsed_args.container, parsed_args.name, - parsed_args.description + parsed_args.description, ) backup._info.pop('links') @@ -119,19 +120,24 @@ class DeleteVolumeBackup(command.Command): for i in parsed_args.backups: try: - backup_id = utils.find_resource( - volume_client.backups, i).id + backup_id = utils.find_resource(volume_client.backups, i).id volume_client.backups.delete(backup_id) except Exception as e: result += 1 - LOG.error(_("Failed to delete backup with " - "name or ID '%(backup)s': %(e)s"), - {'backup': i, 'e': e}) + LOG.error( + _( + "Failed to delete backup with " + "name or ID '%(backup)s': %(e)s" + ), + {'backup': i, 'e': e}, + ) if result > 0: total = len(parsed_args.backups) - msg = (_("%(result)s of %(total)s backups failed " - "to delete.") % {'result': result, 'total': total}) + msg = _("%(result)s of %(total)s backups failed " "to delete.") % { + 'result': result, + 'total': total, + } raise exceptions.CommandError(msg) @@ -149,22 +155,32 @@ class ListVolumeBackup(command.Lister): parser.add_argument( "--name", metavar="<name>", - help=_("Filters results by the backup name") + help=_("Filters results by the backup name"), ) parser.add_argument( "--status", metavar="<status>", - choices=['creating', 'available', 'deleting', - 'error', 'restoring', 'error_restoring'], - help=_("Filters results by the backup status " - "('creating', 'available', 'deleting', " - "'error', 'restoring' or 'error_restoring')") + choices=[ + 'creating', + 'available', + 'deleting', + 'error', + 'restoring', + 'error_restoring', + ], + help=_( + "Filters results by the backup status " + "('creating', 'available', 'deleting', " + "'error', 'restoring' or 'error_restoring')" + ), ) parser.add_argument( "--volume", metavar="<volume>", - help=_("Filters results by the volume which they " - "backup (name or ID)") + help=_( + "Filters results by the volume which they " + "backup (name or ID)" + ), ) parser.add_argument( '--all-projects', @@ -178,8 +194,16 @@ class ListVolumeBackup(command.Lister): volume_client = self.app.client_manager.volume if parsed_args.long: - columns = ['ID', 'Name', 'Description', 'Status', 'Size', - 'Availability Zone', 'Volume ID', 'Container'] + columns = [ + 'ID', + 'Name', + 'Description', + 'Status', + 'Size', + 'Availability Zone', + 'Volume ID', + 'Container', + ] column_headers = copy.deepcopy(columns) column_headers[6] = 'Volume' else: @@ -194,13 +218,15 @@ class ListVolumeBackup(command.Lister): except Exception: # Just forget it if there's any trouble pass - VolumeIdColumnWithCache = functools.partial(VolumeIdColumn, - volume_cache=volume_cache) + VolumeIdColumnWithCache = functools.partial( + VolumeIdColumn, volume_cache=volume_cache + ) filter_volume_id = None if parsed_args.volume: - filter_volume_id = utils.find_resource(volume_client.volumes, - parsed_args.volume).id + filter_volume_id = utils.find_resource( + volume_client.volumes, parsed_args.volume + ).id search_opts = { 'name': parsed_args.name, 'status': parsed_args.status, @@ -211,11 +237,17 @@ class ListVolumeBackup(command.Lister): search_opts=search_opts, ) - return (column_headers, - (utils.get_item_properties( - s, columns, + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, formatters={'Volume ID': VolumeIdColumnWithCache}, - ) for s in data)) + ) + for s in data + ), + ) class RestoreVolumeBackup(command.Command): @@ -226,20 +258,21 @@ class RestoreVolumeBackup(command.Command): parser.add_argument( 'backup', metavar='<backup>', - help=_('Backup to restore (name or ID)') + help=_('Backup to restore (name or ID)'), ) parser.add_argument( 'volume', metavar='<volume>', nargs='?', - help=_('Volume to restore to (name or ID) (default to None)') + help=_('Volume to restore to (name or ID) (default to None)'), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume backup = utils.find_resource( - volume_client.backups, parsed_args.backup, + volume_client.backups, + parsed_args.backup, ) volume_id = None if parsed_args.volume is not None: @@ -258,13 +291,12 @@ class ShowVolumeBackup(command.ShowOne): parser.add_argument( 'backup', metavar='<backup>', - help=_('Backup to display (name or ID)') + help=_('Backup to display (name or ID)'), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - backup = utils.find_resource(volume_client.backups, - parsed_args.backup) + backup = utils.find_resource(volume_client.backups, parsed_args.backup) backup._info.pop('links') return zip(*sorted(backup._info.items())) diff --git a/openstackclient/volume/v1/volume_snapshot.py b/openstackclient/volume/v1/volume_snapshot.py index 2d1f0359..81960635 100644 --- a/openstackclient/volume/v1/volume_snapshot.py +++ b/openstackclient/volume/v1/volume_snapshot.py @@ -72,8 +72,10 @@ class CreateVolumeSnapshot(command.ShowOne): parser.add_argument( '--volume', metavar='<volume>', - help=_('Volume to snapshot (name or ID) ' - '(default is <snapshot-name>)'), + help=_( + 'Volume to snapshot (name or ID) ' + '(default is <snapshot-name>)' + ), ) parser.add_argument( '--description', @@ -85,8 +87,10 @@ class CreateVolumeSnapshot(command.ShowOne): dest='force', action='store_true', default=False, - help=_('Create a snapshot attached to an instance. ' - 'Default is False'), + help=_( + 'Create a snapshot attached to an instance. ' + 'Default is False' + ), ) return parser @@ -95,18 +99,20 @@ class CreateVolumeSnapshot(command.ShowOne): volume = parsed_args.volume if not parsed_args.volume: volume = parsed_args.snapshot_name - volume_id = utils.find_resource(volume_client.volumes, - volume).id + volume_id = utils.find_resource(volume_client.volumes, volume).id snapshot = volume_client.volume_snapshots.create( volume_id, parsed_args.force, parsed_args.snapshot_name, - parsed_args.description + parsed_args.description, ) snapshot._info.update( - {'properties': - format_columns.DictColumn(snapshot._info.pop('metadata'))} + { + 'properties': format_columns.DictColumn( + snapshot._info.pop('metadata') + ) + } ) return zip(*sorted(snapshot._info.items())) @@ -132,18 +138,24 @@ class DeleteVolumeSnapshot(command.Command): for i in parsed_args.snapshots: try: snapshot_id = utils.find_resource( - volume_client.volume_snapshots, i).id + volume_client.volume_snapshots, i + ).id volume_client.volume_snapshots.delete(snapshot_id) except Exception as e: result += 1 - LOG.error(_("Failed to delete snapshot with " - "name or ID '%(snapshot)s': %(e)s"), - {'snapshot': i, 'e': e}) + LOG.error( + _( + "Failed to delete snapshot with " + "name or ID '%(snapshot)s': %(e)s" + ), + {'snapshot': i, 'e': e}, + ) if result > 0: total = len(parsed_args.snapshots) - msg = (_("%(result)s of %(total)s snapshots failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s snapshots failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -168,22 +180,29 @@ class ListVolumeSnapshot(command.Lister): '--name', metavar='<name>', default=None, - help=_('Filters results by a name.') + help=_('Filters results by a name.'), ) parser.add_argument( '--status', metavar='<status>', - choices=['available', 'error', 'creating', 'deleting', - 'error_deleting'], - help=_("Filters results by a status. " - "('available', 'error', 'creating', 'deleting'" - " or 'error_deleting')") + choices=[ + 'available', + 'error', + 'creating', + 'deleting', + 'error_deleting', + ], + help=_( + "Filters results by a status. " + "('available', 'error', 'creating', 'deleting'" + " or 'error_deleting')" + ), ) parser.add_argument( '--volume', metavar='<volume>', default=None, - help=_('Filters results by a volume (name or ID).') + help=_('Filters results by a volume (name or ID).'), ) return parser @@ -191,14 +210,27 @@ class ListVolumeSnapshot(command.Lister): volume_client = self.app.client_manager.volume if parsed_args.long: - columns = ['ID', 'Display Name', 'Display Description', 'Status', - 'Size', 'Created At', 'Volume ID', 'Metadata'] + columns = [ + 'ID', + 'Display Name', + 'Display Description', + 'Status', + 'Size', + 'Created At', + 'Volume ID', + 'Metadata', + ] column_headers = copy.deepcopy(columns) column_headers[6] = 'Volume' column_headers[7] = 'Properties' else: - columns = ['ID', 'Display Name', 'Display Description', 'Status', - 'Size'] + columns = [ + 'ID', + 'Display Name', + 'Display Description', + 'Status', + 'Size', + ] column_headers = copy.deepcopy(columns) # Always update Name and Description @@ -213,13 +245,15 @@ class ListVolumeSnapshot(command.Lister): except Exception: # Just forget it if there's any trouble pass - VolumeIdColumnWithCache = functools.partial(VolumeIdColumn, - volume_cache=volume_cache) + VolumeIdColumnWithCache = functools.partial( + VolumeIdColumn, volume_cache=volume_cache + ) volume_id = None if parsed_args.volume: volume_id = utils.find_resource( - volume_client.volumes, parsed_args.volume).id + volume_client.volumes, parsed_args.volume + ).id search_opts = { 'all_tenants': parsed_args.all_projects, @@ -228,14 +262,21 @@ class ListVolumeSnapshot(command.Lister): 'volume_id': volume_id, } - data = volume_client.volume_snapshots.list( - search_opts=search_opts) - return (column_headers, - (utils.get_item_properties( - s, columns, - formatters={'Metadata': format_columns.DictColumn, - 'Volume ID': VolumeIdColumnWithCache}, - ) for s in data)) + data = volume_client.volume_snapshots.list(search_opts=search_opts) + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, + formatters={ + 'Metadata': format_columns.DictColumn, + 'Volume ID': VolumeIdColumnWithCache, + }, + ) + for s in data + ), + ) class SetVolumeSnapshot(command.Command): @@ -246,40 +287,43 @@ class SetVolumeSnapshot(command.Command): parser.add_argument( 'snapshot', metavar='<snapshot>', - help=_('Snapshot to modify (name or ID)') + help=_('Snapshot to modify (name or ID)'), ) parser.add_argument( - '--name', - metavar='<name>', - help=_('New snapshot name') + '--name', metavar='<name>', help=_('New snapshot name') ) parser.add_argument( '--description', metavar='<description>', - help=_('New snapshot description') + help=_('New snapshot description'), ) parser.add_argument( "--no-property", dest="no_property", action="store_true", - help=_("Remove all properties from <snapshot> " - "(specify both --no-property and --property to " - "remove the current properties before setting " - "new properties.)"), + help=_( + "Remove all properties from <snapshot> " + "(specify both --no-property and --property to " + "remove the current properties before setting " + "new properties.)" + ), ) parser.add_argument( '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Property to add/change for this snapshot ' - '(repeat option to set multiple properties)'), + help=_( + 'Property to add/change for this snapshot ' + '(repeat option to set multiple properties)' + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - snapshot = utils.find_resource(volume_client.volume_snapshots, - parsed_args.snapshot) + snapshot = utils.find_resource( + volume_client.volume_snapshots, parsed_args.snapshot + ) result = 0 if parsed_args.no_property: @@ -296,7 +340,8 @@ class SetVolumeSnapshot(command.Command): if parsed_args.property: try: volume_client.volume_snapshots.set_metadata( - snapshot.id, parsed_args.property) + snapshot.id, parsed_args.property + ) except Exception as e: LOG.error(_("Failed to set snapshot property: %s"), e) result += 1 @@ -310,13 +355,19 @@ class SetVolumeSnapshot(command.Command): try: snapshot.update(**kwargs) except Exception as e: - LOG.error(_("Failed to update snapshot display name " - "or display description: %s"), e) + LOG.error( + _( + "Failed to update snapshot display name " + "or display description: %s" + ), + e, + ) result += 1 if result > 0: - raise exceptions.CommandError(_("One or more of the " - "set operations failed")) + raise exceptions.CommandError( + _("One or more of the " "set operations failed") + ) class ShowVolumeSnapshot(command.ShowOne): @@ -327,18 +378,22 @@ class ShowVolumeSnapshot(command.ShowOne): parser.add_argument( 'snapshot', metavar='<snapshot>', - help=_('Snapshot to display (name or ID)') + help=_('Snapshot to display (name or ID)'), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - snapshot = utils.find_resource(volume_client.volume_snapshots, - parsed_args.snapshot) + snapshot = utils.find_resource( + volume_client.volume_snapshots, parsed_args.snapshot + ) snapshot._info.update( - {'properties': - format_columns.DictColumn(snapshot._info.pop('metadata'))} + { + 'properties': format_columns.DictColumn( + snapshot._info.pop('metadata') + ) + } ) return zip(*sorted(snapshot._info.items())) @@ -358,15 +413,18 @@ class UnsetVolumeSnapshot(command.Command): '--property', metavar='<key>', action='append', - help=_('Property to remove from snapshot ' - '(repeat option to remove multiple properties)'), + help=_( + 'Property to remove from snapshot ' + '(repeat option to remove multiple properties)' + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume snapshot = utils.find_resource( - volume_client.volume_snapshots, parsed_args.snapshot) + volume_client.volume_snapshots, parsed_args.snapshot + ) if parsed_args.property: volume_client.volume_snapshots.delete_metadata( diff --git a/openstackclient/volume/v1/volume_transfer_request.py b/openstackclient/volume/v1/volume_transfer_request.py index 971b9ab5..a1b8c0c4 100644 --- a/openstackclient/volume/v1/volume_transfer_request.py +++ b/openstackclient/volume/v1/volume_transfer_request.py @@ -48,8 +48,7 @@ class AcceptTransferRequest(command.ShowOne): try: transfer_request_id = utils.find_resource( - volume_client.transfers, - parsed_args.transfer_request + volume_client.transfers, parsed_args.transfer_request ).id except exceptions.CommandError: # Non-admin users will fail to lookup name -> ID so we just @@ -77,12 +76,12 @@ class CreateTransferRequest(command.ShowOne): parser.add_argument( '--name', metavar="<name>", - help=_('New transfer request name (default to None)') + help=_('New transfer request name (default to None)'), ) parser.add_argument( 'volume', metavar="<volume>", - help=_('Volume to transfer (name or ID)') + help=_('Volume to transfer (name or ID)'), ) return parser @@ -127,14 +126,20 @@ class DeleteTransferRequest(command.Command): volume_client.transfers.delete(transfer_request_id) except Exception as e: result += 1 - LOG.error(_("Failed to delete volume transfer request " - "with name or ID '%(transfer)s': %(e)s") - % {'transfer': t, 'e': e}) + LOG.error( + _( + "Failed to delete volume transfer request " + "with name or ID '%(transfer)s': %(e)s" + ) + % {'transfer': t, 'e': e} + ) if result > 0: total = len(parsed_args.transfer_request) - msg = (_("%(result)s of %(total)s volume transfer requests failed" - " to delete") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s volume transfer requests failed" + " to delete" + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -163,9 +168,13 @@ class ListTransferRequest(command.Lister): search_opts={'all_tenants': parsed_args.all_projects}, ) - return (column_headers, ( - utils.get_item_properties(s, columns) - for s in volume_transfer_result)) + return ( + column_headers, + ( + utils.get_item_properties(s, columns) + for s in volume_transfer_result + ), + ) class ShowTransferRequest(command.ShowOne): diff --git a/openstackclient/volume/v1/volume_type.py b/openstackclient/volume/v1/volume_type.py index c584943e..38fd8297 100644 --- a/openstackclient/volume/v1/volume_type.py +++ b/openstackclient/volume/v1/volume_type.py @@ -63,8 +63,10 @@ class EncryptionInfoColumn(cliff_columns.FormattableColumn): def _create_encryption_type(volume_client, volume_type, parsed_args): if not parsed_args.encryption_provider: - msg = _("'--encryption-provider' should be specified while " - "creating a new encryption type") + msg = _( + "'--encryption-provider' should be specified while " + "creating a new encryption type" + ) raise exceptions.CommandError(msg) # set the default of control location while creating control_location = 'front-end' @@ -74,10 +76,11 @@ def _create_encryption_type(volume_client, volume_type, parsed_args): 'provider': parsed_args.encryption_provider, 'cipher': parsed_args.encryption_cipher, 'key_size': parsed_args.encryption_key_size, - 'control_location': control_location + 'control_location': control_location, } encryption = volume_client.volume_encryption_types.create( - volume_type, body) + volume_type, body + ) return encryption @@ -95,44 +98,54 @@ class CreateVolumeType(command.ShowOne): '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set a property on this volume type ' - '(repeat option to set multiple properties)'), + help=_( + 'Set a property on this volume type ' + '(repeat option to set multiple properties)' + ), ) # TODO(Huanxuan Ao): Add choices for each "--encryption-*" option. parser.add_argument( '--encryption-provider', metavar='<provider>', - help=_('Set the encryption provider format for ' - 'this volume type (e.g "luks" or "plain") (admin only) ' - '(This option is required when setting encryption type ' - 'of a volume. Consider using other encryption options ' - 'such as: "--encryption-cipher", "--encryption-key-size" ' - 'and "--encryption-control-location")'), + help=_( + 'Set the encryption provider format for ' + 'this volume type (e.g "luks" or "plain") (admin only) ' + '(This option is required when setting encryption type ' + 'of a volume. Consider using other encryption options ' + 'such as: "--encryption-cipher", "--encryption-key-size" ' + 'and "--encryption-control-location")' + ), ) parser.add_argument( '--encryption-cipher', metavar='<cipher>', - help=_('Set the encryption algorithm or mode for this ' - 'volume type (e.g "aes-xts-plain64") (admin only)'), + help=_( + 'Set the encryption algorithm or mode for this ' + 'volume type (e.g "aes-xts-plain64") (admin only)' + ), ) parser.add_argument( '--encryption-key-size', metavar='<key-size>', type=int, - help=_('Set the size of the encryption key of this ' - 'volume type (e.g "128" or "256") (admin only)'), + help=_( + 'Set the size of the encryption key of this ' + 'volume type (e.g "128" or "256") (admin only)' + ), ) parser.add_argument( '--encryption-control-location', metavar='<control-location>', choices=['front-end', 'back-end'], - help=_('Set the notional service where the encryption is ' - 'performed ("front-end" or "back-end") (admin only) ' - '(The default value for this option is "front-end" ' - 'when setting encryption type of a volume. Consider ' - 'using other encryption options such as: ' - '"--encryption-cipher", "--encryption-key-size" and ' - '"--encryption-provider")'), + help=_( + 'Set the notional service where the encryption is ' + 'performed ("front-end" or "back-end") (admin only) ' + '(The default value for this option is "front-end" ' + 'when setting encryption type of a volume. Consider ' + 'using other encryption options such as: ' + '"--encryption-cipher", "--encryption-key-size" and ' + '"--encryption-provider")' + ), ) return parser @@ -143,22 +156,32 @@ class CreateVolumeType(command.ShowOne): if parsed_args.property: result = volume_type.set_keys(parsed_args.property) volume_type._info.update( - {'properties': format_columns.DictColumn(result)}) - if (parsed_args.encryption_provider or - parsed_args.encryption_cipher or - parsed_args.encryption_key_size or - parsed_args.encryption_control_location): + {'properties': format_columns.DictColumn(result)} + ) + if ( + parsed_args.encryption_provider + or parsed_args.encryption_cipher + or parsed_args.encryption_key_size + or parsed_args.encryption_control_location + ): try: # create new encryption encryption = _create_encryption_type( - volume_client, volume_type, parsed_args) + volume_client, volume_type, parsed_args + ) except Exception as e: - LOG.error(_("Failed to set encryption information for this " - "volume type: %s"), e) + LOG.error( + _( + "Failed to set encryption information for this " + "volume type: %s" + ), + e, + ) # add encryption info in result encryption._info.pop("volume_type_id", None) volume_type._info.update( - {'encryption': format_columns.DictColumn(encryption._info)}) + {'encryption': format_columns.DictColumn(encryption._info)} + ) volume_type._info.pop("os-volume-type-access:is_public", None) return zip(*sorted(volume_type._info.items())) @@ -183,20 +206,26 @@ class DeleteVolumeType(command.Command): for volume_type in parsed_args.volume_types: try: - vol_type = utils.find_resource(volume_client.volume_types, - volume_type) + vol_type = utils.find_resource( + volume_client.volume_types, volume_type + ) volume_client.volume_types.delete(vol_type) except Exception as e: result += 1 - LOG.error(_("Failed to delete volume type with " - "name or ID '%(volume_type)s': %(e)s") - % {'volume_type': volume_type, 'e': e}) + LOG.error( + _( + "Failed to delete volume type with " + "name or ID '%(volume_type)s': %(e)s" + ) + % {'volume_type': volume_type, 'e': e} + ) if result > 0: total = len(parsed_args.volume_types) - msg = (_("%(result)s of %(total)s volume types failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s volume types failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -209,13 +238,15 @@ class ListVolumeType(command.Lister): '--long', action='store_true', default=False, - help=_('List additional fields in output') + help=_('List additional fields in output'), ) parser.add_argument( "--encryption-type", action="store_true", - help=_("Display encryption information for each volume type " - "(admin only)"), + help=_( + "Display encryption information for each volume type " + "(admin only)" + ), ) return parser @@ -241,7 +272,7 @@ class ListVolumeType(command.Lister): 'created_at', 'updated_at', 'deleted_at', - 'volume_type_id' + 'volume_type_id', ] for key in del_key: d._info.pop(key, None) @@ -254,14 +285,21 @@ class ListVolumeType(command.Lister): column_headers += ['Encryption'] _EncryptionInfoColumn = functools.partial( - EncryptionInfoColumn, encryption_data=encryption) + EncryptionInfoColumn, encryption_data=encryption + ) formatters['id'] = _EncryptionInfoColumn - return (column_headers, - (utils.get_item_properties( - s, columns, + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, formatters=formatters, - ) for s in data)) + ) + for s in data + ), + ) class SetVolumeType(command.Command): @@ -278,51 +316,62 @@ class SetVolumeType(command.Command): '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set a property on this volume type ' - '(repeat option to set multiple properties)'), + help=_( + 'Set a property on this volume type ' + '(repeat option to set multiple properties)' + ), ) # TODO(Huanxuan Ao): Add choices for each "--encryption-*" option. parser.add_argument( '--encryption-provider', metavar='<provider>', - help=_('Set the encryption provider format for ' - 'this volume type (e.g "luks" or "plain") (admin only) ' - '(This option is required when setting encryption type ' - 'of a volume. Consider using other encryption options ' - 'such as: "--encryption-cipher", "--encryption-key-size" ' - 'and "--encryption-control-location")'), + help=_( + 'Set the encryption provider format for ' + 'this volume type (e.g "luks" or "plain") (admin only) ' + '(This option is required when setting encryption type ' + 'of a volume. Consider using other encryption options ' + 'such as: "--encryption-cipher", "--encryption-key-size" ' + 'and "--encryption-control-location")' + ), ) parser.add_argument( '--encryption-cipher', metavar='<cipher>', - help=_('Set the encryption algorithm or mode for this ' - 'volume type (e.g "aes-xts-plain64") (admin only)'), + help=_( + 'Set the encryption algorithm or mode for this ' + 'volume type (e.g "aes-xts-plain64") (admin only)' + ), ) parser.add_argument( '--encryption-key-size', metavar='<key-size>', type=int, - help=_('Set the size of the encryption key of this ' - 'volume type (e.g "128" or "256") (admin only)'), + help=_( + 'Set the size of the encryption key of this ' + 'volume type (e.g "128" or "256") (admin only)' + ), ) parser.add_argument( '--encryption-control-location', metavar='<control-location>', choices=['front-end', 'back-end'], - help=_('Set the notional service where the encryption is ' - 'performed ("front-end" or "back-end") (admin only) ' - '(The default value for this option is "front-end" ' - 'when setting encryption type of a volume. Consider ' - 'using other encryption options such as: ' - '"--encryption-cipher", "--encryption-key-size" and ' - '"--encryption-provider")'), + help=_( + 'Set the notional service where the encryption is ' + 'performed ("front-end" or "back-end") (admin only) ' + '(The default value for this option is "front-end" ' + 'when setting encryption type of a volume. Consider ' + 'using other encryption options such as: ' + '"--encryption-cipher", "--encryption-key-size" and ' + '"--encryption-provider")' + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume volume_type = utils.find_resource( - volume_client.volume_types, parsed_args.volume_type) + volume_client.volume_types, parsed_args.volume_type + ) result = 0 if parsed_args.property: @@ -332,21 +381,30 @@ class SetVolumeType(command.Command): LOG.error(_("Failed to set volume type property: %s"), e) result += 1 - if (parsed_args.encryption_provider or - parsed_args.encryption_cipher or - parsed_args.encryption_key_size or - parsed_args.encryption_control_location): + if ( + parsed_args.encryption_provider + or parsed_args.encryption_cipher + or parsed_args.encryption_key_size + or parsed_args.encryption_control_location + ): try: _create_encryption_type( - volume_client, volume_type, parsed_args) + volume_client, volume_type, parsed_args + ) except Exception as e: - LOG.error(_("Failed to set encryption information for this " - "volume type: %s"), e) + LOG.error( + _( + "Failed to set encryption information for this " + "volume type: %s" + ), + e, + ) result += 1 if result > 0: - raise exceptions.CommandError(_("Command Failed: One or more of" - " the operations failed")) + raise exceptions.CommandError( + _("Command Failed: One or more of" " the operations failed") + ) class ShowVolumeType(command.ShowOne): @@ -357,35 +415,45 @@ class ShowVolumeType(command.ShowOne): parser.add_argument( "volume_type", metavar="<volume-type>", - help=_("Volume type to display (name or ID)") + help=_("Volume type to display (name or ID)"), ) parser.add_argument( "--encryption-type", action="store_true", - help=_("Display encryption information of this volume type " - "(admin only)"), + help=_( + "Display encryption information of this volume type " + "(admin only)" + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume volume_type = utils.find_resource( - volume_client.volume_types, parsed_args.volume_type) + volume_client.volume_types, parsed_args.volume_type + ) properties = format_columns.DictColumn( - volume_type._info.pop('extra_specs')) + volume_type._info.pop('extra_specs') + ) volume_type._info.update({'properties': properties}) if parsed_args.encryption_type: # show encryption type information for this volume type try: encryption = volume_client.volume_encryption_types.get( - volume_type.id) + volume_type.id + ) encryption._info.pop("volume_type_id", None) volume_type._info.update( - {'encryption': - format_columns.DictColumn(encryption._info)}) + {'encryption': format_columns.DictColumn(encryption._info)} + ) except Exception as e: - LOG.error(_("Failed to display the encryption information " - "of this volume type: %s"), e) + LOG.error( + _( + "Failed to display the encryption information " + "of this volume type: %s" + ), + e, + ) volume_type._info.pop("os-volume-type-access:is_public", None) return zip(*sorted(volume_type._info.items())) @@ -404,14 +472,18 @@ class UnsetVolumeType(command.Command): '--property', metavar='<key>', action='append', - help=_('Remove a property from this volume type ' - '(repeat option to remove multiple properties)'), + help=_( + 'Remove a property from this volume type ' + '(repeat option to remove multiple properties)' + ), ) parser.add_argument( "--encryption-type", action="store_true", - help=_("Remove the encryption type for this volume type " - "(admin only)"), + help=_( + "Remove the encryption type for this volume type " + "(admin only)" + ), ) return parser @@ -433,10 +505,16 @@ class UnsetVolumeType(command.Command): try: volume_client.volume_encryption_types.delete(volume_type) except Exception as e: - LOG.error(_("Failed to remove the encryption type for this " - "volume type: %s"), e) + LOG.error( + _( + "Failed to remove the encryption type for this " + "volume type: %s" + ), + e, + ) result += 1 if result > 0: - raise exceptions.CommandError(_("Command Failed: One or more of" - " the operations failed")) + raise exceptions.CommandError( + _("Command Failed: One or more of" " the operations failed") + ) diff --git a/openstackclient/volume/v2/backup_record.py b/openstackclient/volume/v2/backup_record.py index 0d3af641..be4b9c69 100644 --- a/openstackclient/volume/v2/backup_record.py +++ b/openstackclient/volume/v2/backup_record.py @@ -26,17 +26,19 @@ LOG = logging.getLogger(__name__) class ExportBackupRecord(command.ShowOne): - _description = _("""Export volume backup details. + _description = _( + """Export volume backup details. Backup information can be imported into a new service instance to be able to -restore.""") +restore.""" + ) def get_parser(self, prog_name): parser = super(ExportBackupRecord, self).get_parser(prog_name) parser.add_argument( "backup", metavar="<backup>", - help=_("Backup to export (name or ID)") + help=_("Backup to export (name or ID)"), ) return parser @@ -55,29 +57,31 @@ restore.""") class ImportBackupRecord(command.ShowOne): - _description = _("""Import volume backup details. + _description = _( + """Import volume backup details. Exported backup details contain the metadata necessary to restore to a new or -rebuilt service instance""") +rebuilt service instance""" + ) def get_parser(self, prog_name): parser = super(ImportBackupRecord, self).get_parser(prog_name) parser.add_argument( "backup_service", metavar="<backup_service>", - help=_("Backup service containing the backup.") + help=_("Backup service containing the backup."), ) parser.add_argument( "backup_metadata", metavar="<backup_metadata>", - help=_("Encoded backup metadata from export.") + help=_("Encoded backup metadata from export."), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume backup_data = volume_client.backups.import_record( - parsed_args.backup_service, - parsed_args.backup_metadata) + parsed_args.backup_service, parsed_args.backup_metadata + ) backup_data.pop('links', None) return zip(*sorted(backup_data.items())) diff --git a/openstackclient/volume/v2/consistency_group.py b/openstackclient/volume/v2/consistency_group.py index 77da6f64..3b4d8803 100644 --- a/openstackclient/volume/v2/consistency_group.py +++ b/openstackclient/volume/v2/consistency_group.py @@ -33,14 +33,17 @@ def _find_volumes(parsed_args_volumes, volume_client): uuid = '' for volume in parsed_args_volumes: try: - volume_id = utils.find_resource( - volume_client.volumes, volume).id + volume_id = utils.find_resource(volume_client.volumes, volume).id uuid += volume_id + ',' except Exception as e: result += 1 - LOG.error(_("Failed to find volume with " - "name or ID '%(volume)s':%(e)s") - % {'volume': volume, 'e': e}) + LOG.error( + _( + "Failed to find volume with " + "name or ID '%(volume)s':%(e)s" + ) + % {'volume': volume, 'e': e} + ) return result, uuid @@ -59,8 +62,10 @@ class AddVolumeToConsistencyGroup(command.Command): 'volumes', metavar='<volume>', nargs='+', - help=_('Volume(s) to add to <consistency-group> (name or ID) ' - '(repeat option to add multiple volumes)'), + help=_( + 'Volume(s) to add to <consistency-group> (name or ID) ' + '(repeat option to add multiple volumes)' + ), ) return parser @@ -70,16 +75,19 @@ class AddVolumeToConsistencyGroup(command.Command): if result > 0: total = len(parsed_args.volumes) - LOG.error(_("%(result)s of %(total)s volumes failed " - "to add.") % {'result': result, 'total': total}) + LOG.error( + _("%(result)s of %(total)s volumes failed " "to add.") + % {'result': result, 'total': total} + ) if add_uuid: add_uuid = add_uuid.rstrip(',') consistency_group_id = utils.find_resource( - volume_client.consistencygroups, - parsed_args.consistency_group).id + volume_client.consistencygroups, parsed_args.consistency_group + ).id volume_client.consistencygroups.update( - consistency_group_id, add_volumes=add_uuid) + consistency_group_id, add_volumes=add_uuid + ) class CreateConsistencyGroup(command.ShowOne): @@ -143,18 +151,20 @@ class CreateConsistencyGroup(command.ShowOne): volume_client = self.app.client_manager.volume if parsed_args.volume_type: volume_type_id = utils.find_resource( - volume_client.volume_types, - parsed_args.volume_type).id + volume_client.volume_types, parsed_args.volume_type + ).id consistency_group = volume_client.consistencygroups.create( volume_type_id, name=parsed_args.name, description=parsed_args.description, - availability_zone=parsed_args.availability_zone + availability_zone=parsed_args.availability_zone, ) else: if parsed_args.availability_zone: - msg = _("'--availability-zone' option will not work " - "if creating consistency group from source") + msg = _( + "'--availability-zone' option will not work " + "if creating consistency group from source" + ) LOG.warning(msg) consistency_group_id = None @@ -208,19 +218,27 @@ class DeleteConsistencyGroup(command.Command): for i in parsed_args.consistency_groups: try: consistency_group_id = utils.find_resource( - volume_client.consistencygroups, i).id + volume_client.consistencygroups, i + ).id volume_client.consistencygroups.delete( - consistency_group_id, parsed_args.force) + consistency_group_id, parsed_args.force + ) except Exception as e: result += 1 - LOG.error(_("Failed to delete consistency group with " - "name or ID '%(consistency_group)s':%(e)s") - % {'consistency_group': i, 'e': e}) + LOG.error( + _( + "Failed to delete consistency group with " + "name or ID '%(consistency_group)s':%(e)s" + ) + % {'consistency_group': i, 'e': e} + ) if result > 0: total = len(parsed_args.consistency_groups) - msg = (_("%(result)s of %(total)s consistency groups failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s consistency groups failed " + "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -232,41 +250,56 @@ class ListConsistencyGroup(command.Lister): parser.add_argument( '--all-projects', action="store_true", - help=_('Show details for all projects. Admin only. ' - '(defaults to False)') + help=_( + 'Show details for all projects. Admin only. ' + '(defaults to False)' + ), ) parser.add_argument( '--long', action="store_true", - help=_('List additional fields in output') + help=_('List additional fields in output'), ) return parser def take_action(self, parsed_args): if parsed_args.long: - columns = ['ID', 'Status', 'Availability Zone', - 'Name', 'Description', 'Volume Types'] + columns = [ + 'ID', + 'Status', + 'Availability Zone', + 'Name', + 'Description', + 'Volume Types', + ] else: columns = ['ID', 'Status', 'Name'] volume_client = self.app.client_manager.volume consistency_groups = volume_client.consistencygroups.list( detailed=True, - search_opts={'all_tenants': parsed_args.all_projects} + search_opts={'all_tenants': parsed_args.all_projects}, ) - return (columns, ( - utils.get_item_properties( - s, columns, - formatters={'Volume Types': format_columns.ListColumn}) - for s in consistency_groups)) + return ( + columns, + ( + utils.get_item_properties( + s, + columns, + formatters={'Volume Types': format_columns.ListColumn}, + ) + for s in consistency_groups + ), + ) class RemoveVolumeFromConsistencyGroup(command.Command): _description = _("Remove volume(s) from consistency group") def get_parser(self, prog_name): - parser = \ - super(RemoveVolumeFromConsistencyGroup, self).get_parser(prog_name) + parser = super(RemoveVolumeFromConsistencyGroup, self).get_parser( + prog_name + ) parser.add_argument( 'consistency_group', metavar="<consistency-group>", @@ -276,8 +309,10 @@ class RemoveVolumeFromConsistencyGroup(command.Command): 'volumes', metavar='<volume>', nargs='+', - help=_('Volume(s) to remove from <consistency-group> (name or ID) ' - '(repeat option to remove multiple volumes)'), + help=_( + 'Volume(s) to remove from <consistency-group> (name or ID) ' + '(repeat option to remove multiple volumes)' + ), ) return parser @@ -287,16 +322,19 @@ class RemoveVolumeFromConsistencyGroup(command.Command): if result > 0: total = len(parsed_args.volumes) - LOG.error(_("%(result)s of %(total)s volumes failed " - "to remove.") % {'result': result, 'total': total}) + LOG.error( + _("%(result)s of %(total)s volumes failed " "to remove.") + % {'result': result, 'total': total} + ) if remove_uuid: remove_uuid = remove_uuid.rstrip(',') consistency_group_id = utils.find_resource( - volume_client.consistencygroups, - parsed_args.consistency_group).id + volume_client.consistencygroups, parsed_args.consistency_group + ).id volume_client.consistencygroups.update( - consistency_group_id, remove_volumes=remove_uuid) + consistency_group_id, remove_volumes=remove_uuid + ) class SetConsistencyGroup(command.Command): @@ -307,7 +345,7 @@ class SetConsistencyGroup(command.Command): parser.add_argument( 'consistency_group', metavar='<consistency-group>', - help=_('Consistency group to modify (name or ID)') + help=_('Consistency group to modify (name or ID)'), ) parser.add_argument( '--name', @@ -330,10 +368,11 @@ class SetConsistencyGroup(command.Command): kwargs['description'] = parsed_args.description if kwargs: consistency_group_id = utils.find_resource( - volume_client.consistencygroups, - parsed_args.consistency_group).id + volume_client.consistencygroups, parsed_args.consistency_group + ).id volume_client.consistencygroups.update( - consistency_group_id, **kwargs) + consistency_group_id, **kwargs + ) class ShowConsistencyGroup(command.ShowOne): @@ -344,13 +383,13 @@ class ShowConsistencyGroup(command.ShowOne): parser.add_argument( "consistency_group", metavar="<consistency-group>", - help=_("Consistency group to display (name or ID)") + help=_("Consistency group to display (name or ID)"), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume consistency_group = utils.find_resource( - volume_client.consistencygroups, - parsed_args.consistency_group) + volume_client.consistencygroups, parsed_args.consistency_group + ) return zip(*sorted(consistency_group._info.items())) diff --git a/openstackclient/volume/v2/consistency_group_snapshot.py b/openstackclient/volume/v2/consistency_group_snapshot.py index 7d5ba82f..fe3c569f 100644 --- a/openstackclient/volume/v2/consistency_group_snapshot.py +++ b/openstackclient/volume/v2/consistency_group_snapshot.py @@ -30,24 +30,27 @@ class CreateConsistencyGroupSnapshot(command.ShowOne): _description = _("Create new consistency group snapshot.") def get_parser(self, prog_name): - parser = super( - CreateConsistencyGroupSnapshot, self).get_parser(prog_name) + parser = super(CreateConsistencyGroupSnapshot, self).get_parser( + prog_name + ) parser.add_argument( "snapshot_name", metavar="<snapshot-name>", nargs="?", - help=_("Name of new consistency group snapshot (default to None)") + help=_("Name of new consistency group snapshot (default to None)"), ) parser.add_argument( "--consistency-group", metavar="<consistency-group>", - help=_("Consistency group to snapshot (name or ID) " - "(default to be the same as <snapshot-name>)") + help=_( + "Consistency group to snapshot (name or ID) " + "(default to be the same as <snapshot-name>)" + ), ) parser.add_argument( "--description", metavar="<description>", - help=_("Description of this consistency group snapshot") + help=_("Description of this consistency group snapshot"), ) return parser @@ -59,8 +62,8 @@ class CreateConsistencyGroupSnapshot(command.ShowOne): # will be the same as the new consistency group snapshot name consistency_group = parsed_args.snapshot_name consistency_group_id = utils.find_resource( - volume_client.consistencygroups, - consistency_group).id + volume_client.consistencygroups, consistency_group + ).id consistency_group_snapshot = volume_client.cgsnapshots.create( consistency_group_id, name=parsed_args.snapshot_name, @@ -74,13 +77,14 @@ class DeleteConsistencyGroupSnapshot(command.Command): _description = _("Delete consistency group snapshot(s).") def get_parser(self, prog_name): - parser = super( - DeleteConsistencyGroupSnapshot, self).get_parser(prog_name) + parser = super(DeleteConsistencyGroupSnapshot, self).get_parser( + prog_name + ) parser.add_argument( "consistency_group_snapshot", metavar="<consistency-group-snapshot>", nargs="+", - help=_("Consistency group snapshot(s) to delete (name or ID)") + help=_("Consistency group snapshot(s) to delete (name or ID)"), ) return parser @@ -90,20 +94,27 @@ class DeleteConsistencyGroupSnapshot(command.Command): for snapshot in parsed_args.consistency_group_snapshot: try: - snapshot_id = utils.find_resource(volume_client.cgsnapshots, - snapshot).id + snapshot_id = utils.find_resource( + volume_client.cgsnapshots, snapshot + ).id volume_client.cgsnapshots.delete(snapshot_id) except Exception as e: result += 1 - LOG.error(_("Failed to delete consistency group snapshot " - "with name or ID '%(snapshot)s': %(e)s") - % {'snapshot': snapshot, 'e': e}) + LOG.error( + _( + "Failed to delete consistency group snapshot " + "with name or ID '%(snapshot)s': %(e)s" + ) + % {'snapshot': snapshot, 'e': e} + ) if result > 0: total = len(parsed_args.consistency_group_snapshot) - msg = (_("%(result)s of %(total)s consistency group snapshots " - "failed to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s consistency group snapshots " + "failed to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -111,38 +122,54 @@ class ListConsistencyGroupSnapshot(command.Lister): _description = _("List consistency group snapshots.") def get_parser(self, prog_name): - parser = super( - ListConsistencyGroupSnapshot, self).get_parser(prog_name) + parser = super(ListConsistencyGroupSnapshot, self).get_parser( + prog_name + ) parser.add_argument( '--all-projects', action="store_true", - help=_('Show detail for all projects (admin only) ' - '(defaults to False)') + help=_( + 'Show detail for all projects (admin only) ' + '(defaults to False)' + ), ) parser.add_argument( '--long', action="store_true", - help=_('List additional fields in output') + help=_('List additional fields in output'), ) parser.add_argument( '--status', metavar="<status>", - choices=['available', 'error', 'creating', 'deleting', - 'error_deleting'], - help=_('Filters results by a status ("available", "error", ' - '"creating", "deleting" or "error_deleting")') + choices=[ + 'available', + 'error', + 'creating', + 'deleting', + 'error_deleting', + ], + help=_( + 'Filters results by a status ("available", "error", ' + '"creating", "deleting" or "error_deleting")' + ), ) parser.add_argument( '--consistency-group', metavar="<consistency-group>", - help=_('Filters results by a consistency group (name or ID)') + help=_('Filters results by a consistency group (name or ID)'), ) return parser def take_action(self, parsed_args): if parsed_args.long: - columns = ['ID', 'Status', 'ConsistencyGroup ID', - 'Name', 'Description', 'Created At'] + columns = [ + 'ID', + 'Status', + 'ConsistencyGroup ID', + 'Name', + 'Description', + 'Created At', + ] else: columns = ['ID', 'Status', 'Name'] volume_client = self.app.client_manager.volume @@ -162,28 +189,32 @@ class ListConsistencyGroupSnapshot(command.Lister): search_opts=search_opts, ) - return (columns, ( - utils.get_item_properties( - s, columns) - for s in consistency_group_snapshots)) + return ( + columns, + ( + utils.get_item_properties(s, columns) + for s in consistency_group_snapshots + ), + ) class ShowConsistencyGroupSnapshot(command.ShowOne): _description = _("Display consistency group snapshot details") def get_parser(self, prog_name): - parser = super( - ShowConsistencyGroupSnapshot, self).get_parser(prog_name) + parser = super(ShowConsistencyGroupSnapshot, self).get_parser( + prog_name + ) parser.add_argument( "consistency_group_snapshot", metavar="<consistency-group-snapshot>", - help=_("Consistency group snapshot to display (name or ID)") + help=_("Consistency group snapshot to display (name or ID)"), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume consistency_group_snapshot = utils.find_resource( - volume_client.cgsnapshots, - parsed_args.consistency_group_snapshot) + volume_client.cgsnapshots, parsed_args.consistency_group_snapshot + ) return zip(*sorted(consistency_group_snapshot._info.items())) diff --git a/openstackclient/volume/v2/qos_specs.py b/openstackclient/volume/v2/qos_specs.py index e6e6b9f8..2c06ee34 100644 --- a/openstackclient/volume/v2/qos_specs.py +++ b/openstackclient/volume/v2/qos_specs.py @@ -48,10 +48,12 @@ class AssociateQos(command.Command): def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - qos_spec = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_spec) - volume_type = utils.find_resource(volume_client.volume_types, - parsed_args.volume_type) + qos_spec = utils.find_resource( + volume_client.qos_specs, parsed_args.qos_spec + ) + volume_type = utils.find_resource( + volume_client.volume_types, parsed_args.volume_type + ) volume_client.qos_specs.associate(qos_spec.id, volume_type.id) @@ -72,16 +74,22 @@ class CreateQos(command.ShowOne): metavar='<consumer>', choices=consumer_choices, default='both', - help=(_('Consumer of the QoS. Valid consumers: %s ' - "(defaults to 'both')") % - utils.format_list(consumer_choices)) + help=( + _( + 'Consumer of the QoS. Valid consumers: %s ' + "(defaults to 'both')" + ) + % utils.format_list(consumer_choices) + ), ) parser.add_argument( '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set a QoS specification property ' - '(repeat option to set multiple properties)'), + help=_( + 'Set a QoS specification property ' + '(repeat option to set multiple properties)' + ), ) return parser @@ -96,8 +104,11 @@ class CreateQos(command.ShowOne): qos_spec = volume_client.qos_specs.create(parsed_args.name, specs) qos_spec._info.update( - {'properties': - format_columns.DictColumn(qos_spec._info.pop('specs'))} + { + 'properties': format_columns.DictColumn( + qos_spec._info.pop('specs') + ) + } ) return zip(*sorted(qos_spec._info.items())) @@ -117,7 +128,7 @@ class DeleteQos(command.Command): '--force', action='store_true', default=False, - help=_("Allow to delete in-use QoS specification(s)") + help=_("Allow to delete in-use QoS specification(s)"), ) return parser @@ -131,14 +142,20 @@ class DeleteQos(command.Command): volume_client.qos_specs.delete(qos_spec.id, parsed_args.force) except Exception as e: result += 1 - LOG.error(_("Failed to delete QoS specification with " - "name or ID '%(qos)s': %(e)s") - % {'qos': i, 'e': e}) + LOG.error( + _( + "Failed to delete QoS specification with " + "name or ID '%(qos)s': %(e)s" + ) + % {'qos': i, 'e': e} + ) if result > 0: total = len(parsed_args.qos_specs) - msg = (_("%(result)s of %(total)s QoS specifications failed" - " to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s QoS specifications failed" + " to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -169,12 +186,14 @@ class DisassociateQos(command.Command): def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - qos_spec = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_spec) + qos_spec = utils.find_resource( + volume_client.qos_specs, parsed_args.qos_spec + ) if parsed_args.volume_type: - volume_type = utils.find_resource(volume_client.volume_types, - parsed_args.volume_type) + volume_type = utils.find_resource( + volume_client.volume_types, parsed_args.volume_type + ) volume_client.qos_specs.disassociate(qos_spec.id, volume_type.id) elif parsed_args.all: volume_client.qos_specs.disassociate_all(qos_spec.id) @@ -204,17 +223,28 @@ class ListQos(command.Lister): raise display_columns = ( - 'ID', 'Name', 'Consumer', 'Associations', 'Properties') + 'ID', + 'Name', + 'Consumer', + 'Associations', + 'Properties', + ) columns = ('ID', 'Name', 'Consumer', 'Associations', 'Specs') - return (display_columns, - (utils.get_dict_properties( - s._info, columns, + return ( + display_columns, + ( + utils.get_dict_properties( + s._info, + columns, formatters={ 'Specs': format_columns.DictColumn, - 'Associations': format_columns.ListColumn + 'Associations': format_columns.ListColumn, }, - ) for s in qos_specs_list)) + ) + for s in qos_specs_list + ), + ) class SetQos(command.Command): @@ -231,19 +261,21 @@ class SetQos(command.Command): '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Property to add or modify for this QoS specification ' - '(repeat option to set multiple properties)'), + help=_( + 'Property to add or modify for this QoS specification ' + '(repeat option to set multiple properties)' + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - qos_spec = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_spec) + qos_spec = utils.find_resource( + volume_client.qos_specs, parsed_args.qos_spec + ) if parsed_args.property: - volume_client.qos_specs.set_keys(qos_spec.id, - parsed_args.property) + volume_client.qos_specs.set_keys(qos_spec.id, parsed_args.property) class ShowQos(command.ShowOne): @@ -260,19 +292,25 @@ class ShowQos(command.ShowOne): def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - qos_spec = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_spec) + qos_spec = utils.find_resource( + volume_client.qos_specs, parsed_args.qos_spec + ) qos_associations = volume_client.qos_specs.get_associations(qos_spec) if qos_associations: - associations = [association.name - for association in qos_associations] - qos_spec._info.update({ - 'associations': format_columns.ListColumn(associations) - }) + associations = [ + association.name for association in qos_associations + ] + qos_spec._info.update( + {'associations': format_columns.ListColumn(associations)} + ) qos_spec._info.update( - {'properties': - format_columns.DictColumn(qos_spec._info.pop('specs'))}) + { + 'properties': format_columns.DictColumn( + qos_spec._info.pop('specs') + ) + } + ) return zip(*sorted(qos_spec._info.items())) @@ -292,16 +330,20 @@ class UnsetQos(command.Command): metavar='<key>', action='append', default=[], - help=_('Property to remove from the QoS specification. ' - '(repeat option to unset multiple properties)'), + help=_( + 'Property to remove from the QoS specification. ' + '(repeat option to unset multiple properties)' + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - qos_spec = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_spec) + qos_spec = utils.find_resource( + volume_client.qos_specs, parsed_args.qos_spec + ) if parsed_args.property: - volume_client.qos_specs.unset_keys(qos_spec.id, - parsed_args.property) + volume_client.qos_specs.unset_keys( + qos_spec.id, parsed_args.property + ) diff --git a/openstackclient/volume/v2/service.py b/openstackclient/volume/v2/service.py index d468c6ff..fb5869d5 100644 --- a/openstackclient/volume/v2/service.py +++ b/openstackclient/volume/v2/service.py @@ -29,18 +29,18 @@ class ListService(command.Lister): parser.add_argument( "--host", metavar="<host>", - help=_("List services on specified host (name only)") + help=_("List services on specified host (name only)"), ) parser.add_argument( "--service", metavar="<service>", - help=_("List only specified service (name only)") + help=_("List only specified service (name only)"), ) parser.add_argument( "--long", action="store_true", default=False, - help=_("List additional fields in output") + help=_("List additional fields in output"), ) return parser @@ -55,7 +55,7 @@ class ListService(command.Lister): "Status", "State", "Updated At", - "Disabled Reason" + "Disabled Reason", ] else: columns = [ @@ -64,15 +64,22 @@ class ListService(command.Lister): "Zone", "Status", "State", - "Updated At" + "Updated At", ] - data = service_client.services.list(parsed_args.host, - parsed_args.service) - return (columns, - (utils.get_item_properties( - s, columns, - ) for s in data)) + data = service_client.services.list( + parsed_args.host, parsed_args.service + ) + return ( + columns, + ( + utils.get_item_properties( + s, + columns, + ) + for s in data + ), + ) class SetService(command.Command): @@ -80,51 +87,50 @@ class SetService(command.Command): def get_parser(self, prog_name): parser = super(SetService, self).get_parser(prog_name) - parser.add_argument( - "host", - metavar="<host>", - help=_("Name of host") - ) + parser.add_argument("host", metavar="<host>", help=_("Name of host")) parser.add_argument( "service", metavar="<service>", - help=_("Name of service (Binary name)") + help=_("Name of service (Binary name)"), ) enabled_group = parser.add_mutually_exclusive_group() enabled_group.add_argument( - "--enable", - action="store_true", - help=_("Enable volume service") + "--enable", action="store_true", help=_("Enable volume service") ) enabled_group.add_argument( - "--disable", - action="store_true", - help=_("Disable volume service") + "--disable", action="store_true", help=_("Disable volume service") ) parser.add_argument( "--disable-reason", metavar="<reason>", - help=_("Reason for disabling the service " - "(should be used with --disable option)") + help=_( + "Reason for disabling the service " + "(should be used with --disable option)" + ), ) return parser def take_action(self, parsed_args): if parsed_args.disable_reason and not parsed_args.disable: - msg = _("Cannot specify option --disable-reason without " - "--disable specified.") + msg = _( + "Cannot specify option --disable-reason without " + "--disable specified." + ) raise exceptions.CommandError(msg) service_client = self.app.client_manager.volume if parsed_args.enable: service_client.services.enable( - parsed_args.host, parsed_args.service) + parsed_args.host, parsed_args.service + ) if parsed_args.disable: if parsed_args.disable_reason: service_client.services.disable_log_reason( parsed_args.host, parsed_args.service, - parsed_args.disable_reason) + parsed_args.disable_reason, + ) else: service_client.services.disable( - parsed_args.host, parsed_args.service) + parsed_args.host, parsed_args.service + ) diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py index a5e5a670..43a64664 100644 --- a/openstackclient/volume/v2/volume.py +++ b/openstackclient/volume/v2/volume.py @@ -71,10 +71,13 @@ def _check_size_arg(args): volume is not specified. """ - if ((args.snapshot or args.source or args.backup) - is None and args.size is None): - msg = _("--size is a required option if snapshot, backup " - "or source volume are not specified.") + if ( + args.snapshot or args.source or args.backup + ) is None and args.size is None: + msg = _( + "--size is a required option if snapshot, backup " + "or source volume are not specified." + ) raise exceptions.CommandError(msg) @@ -93,8 +96,10 @@ class CreateVolume(command.ShowOne): "--size", metavar="<size>", type=int, - help=_("Volume size in GB (required unless --snapshot, " - "--source or --backup is specified)"), + help=_( + "Volume size in GB (required unless --snapshot, " + "--source or --backup is specified)" + ), ) parser.add_argument( "--type", @@ -120,8 +125,10 @@ class CreateVolume(command.ShowOne): source_group.add_argument( "--backup", metavar="<backup>", - help=_("Restore backup to a volume (name or ID) " - "(supported by --os-volume-api-version 3.47 or later)"), + help=_( + "Restore backup to a volume (name or ID) " + "(supported by --os-volume-api-version 3.47 or later)" + ), ) source_group.add_argument( "--source-replicated", @@ -147,37 +154,41 @@ class CreateVolume(command.ShowOne): "--property", metavar="<key=value>", action=parseractions.KeyValueAction, - help=_("Set a property to this volume " - "(repeat option to set multiple properties)"), + help=_( + "Set a property to this volume " + "(repeat option to set multiple properties)" + ), ) parser.add_argument( "--hint", metavar="<key=value>", action=parseractions.KeyValueAction, - help=_("Arbitrary scheduler hint key-value pairs to help boot " - "an instance (repeat option to set multiple hints)"), + help=_( + "Arbitrary scheduler hint key-value pairs to help boot " + "an instance (repeat option to set multiple hints)" + ), ) bootable_group = parser.add_mutually_exclusive_group() bootable_group.add_argument( "--bootable", action="store_true", - help=_("Mark volume as bootable") + help=_("Mark volume as bootable"), ) bootable_group.add_argument( "--non-bootable", action="store_true", - help=_("Mark volume as non-bootable (default)") + help=_("Mark volume as non-bootable (default)"), ) readonly_group = parser.add_mutually_exclusive_group() readonly_group.add_argument( "--read-only", action="store_true", - help=_("Set volume to read-only access mode") + help=_("Set volume to read-only access mode"), ) readonly_group.add_argument( "--read-write", action="store_true", - help=_("Set volume to read-write access mode (default)") + help=_("Set volume to read-write access mode (default)"), ) return parser @@ -193,35 +204,39 @@ class CreateVolume(command.ShowOne): image_client = self.app.client_manager.image if parsed_args.backup and not ( - volume_client.api_version.matches('3.47')): - msg = _("--os-volume-api-version 3.47 or greater is required " - "to create a volume from backup.") + volume_client.api_version.matches('3.47') + ): + msg = _( + "--os-volume-api-version 3.47 or greater is required " + "to create a volume from backup." + ) raise exceptions.CommandError(msg) source_volume = None if parsed_args.source: source_volume_obj = utils.find_resource( - volume_client.volumes, - parsed_args.source) + volume_client.volumes, parsed_args.source + ) source_volume = source_volume_obj.id size = max(size or 0, source_volume_obj.size) consistency_group = None if parsed_args.consistency_group: consistency_group = utils.find_resource( - volume_client.consistencygroups, - parsed_args.consistency_group).id + volume_client.consistencygroups, parsed_args.consistency_group + ).id image = None if parsed_args.image: - image = image_client.find_image(parsed_args.image, - ignore_missing=False).id + image = image_client.find_image( + parsed_args.image, ignore_missing=False + ).id snapshot = None if parsed_args.snapshot: snapshot_obj = utils.find_resource( - volume_client.volume_snapshots, - parsed_args.snapshot) + volume_client.volume_snapshots, parsed_args.snapshot + ) snapshot = snapshot_obj.id # Cinder requires a value for size when creating a volume # even if creating from a snapshot. Cinder will create the @@ -234,8 +249,8 @@ class CreateVolume(command.ShowOne): backup = None if parsed_args.backup: backup_obj = utils.find_resource( - volume_client.backups, - parsed_args.backup) + volume_client.backups, parsed_args.backup + ) backup = backup_obj.id # As above size = max(size or 0, backup_obj.size) @@ -262,11 +277,10 @@ class CreateVolume(command.ShowOne): volume.id, success_status=['available'], error_status=['error'], - sleep_time=1 + sleep_time=1, ): volume_client.volumes.set_bootable( - volume.id, - parsed_args.bootable + volume.id, parsed_args.bootable ) else: msg = _( @@ -283,11 +297,10 @@ class CreateVolume(command.ShowOne): volume.id, success_status=['available'], error_status=['error'], - sleep_time=1 + sleep_time=1, ): volume_client.volumes.update_readonly_flag( - volume.id, - parsed_args.read_only + volume.id, parsed_args.read_only ) else: msg = _( @@ -296,15 +309,21 @@ class CreateVolume(command.ShowOne): ) raise exceptions.CommandError(msg) except Exception as e: - LOG.error(_("Failed to set volume read-only access " - "mode flag: %s"), e) + LOG.error( + _( + "Failed to set volume read-only access " + "mode flag: %s" + ), + e, + ) # Remove key links from being displayed volume._info.update( { - 'properties': - format_columns.DictColumn(volume._info.pop('metadata')), - 'type': volume._info.pop('volume_type') + 'properties': format_columns.DictColumn( + volume._info.pop('metadata') + ), + 'type': volume._info.pop('volume_type'), } ) volume._info.pop("links", None) @@ -320,20 +339,24 @@ class DeleteVolume(command.Command): "volumes", metavar="<volume>", nargs="+", - help=_("Volume(s) to delete (name or ID)") + help=_("Volume(s) to delete (name or ID)"), ) group = parser.add_mutually_exclusive_group() group.add_argument( "--force", action="store_true", - help=_("Attempt forced removal of volume(s), regardless of state " - "(defaults to False)") + help=_( + "Attempt forced removal of volume(s), regardless of state " + "(defaults to False)" + ), ) group.add_argument( "--purge", action="store_true", - help=_("Remove any snapshots along with volume(s) " - "(defaults to False)") + help=_( + "Remove any snapshots along with volume(s) " + "(defaults to False)" + ), ) return parser @@ -343,23 +366,29 @@ class DeleteVolume(command.Command): for i in parsed_args.volumes: try: - volume_obj = utils.find_resource( - volume_client.volumes, i) + volume_obj = utils.find_resource(volume_client.volumes, i) if parsed_args.force: volume_client.volumes.force_delete(volume_obj.id) else: - volume_client.volumes.delete(volume_obj.id, - cascade=parsed_args.purge) + volume_client.volumes.delete( + volume_obj.id, cascade=parsed_args.purge + ) except Exception as e: result += 1 - LOG.error(_("Failed to delete volume with " - "name or ID '%(volume)s': %(e)s"), - {'volume': i, 'e': e}) + LOG.error( + _( + "Failed to delete volume with " + "name or ID '%(volume)s': %(e)s" + ), + {'volume': i, 'e': e}, + ) if result > 0: total = len(parsed_args.volumes) - msg = (_("%(result)s of %(total)s volumes failed " - "to delete.") % {'result': result, 'total': total}) + msg = _("%(result)s of %(total)s volumes failed " "to delete.") % { + 'result': result, + 'total': total, + } raise exceptions.CommandError(msg) @@ -371,13 +400,13 @@ class ListVolume(command.Lister): parser.add_argument( '--project', metavar='<project>', - help=_('Filter results by project (name or ID) (admin only)') + help=_('Filter results by project (name or ID) (admin only)'), ) identity_common.add_project_domain_option_to_parser(parser) parser.add_argument( '--user', metavar='<user>', - help=_('Filter results by user (name or ID) (admin only)') + help=_('Filter results by user (name or ID) (admin only)'), ) identity_common.add_user_domain_option_to_parser(parser) parser.add_argument( @@ -417,7 +446,6 @@ class ListVolume(command.Lister): return parser def take_action(self, parsed_args): - volume_client = self.app.client_manager.volume identity_client = self.app.client_manager.identity @@ -457,20 +485,22 @@ class ListVolume(command.Lister): # Just forget it if there's any trouble pass AttachmentsColumnWithCache = functools.partial( - AttachmentsColumn, server_cache=server_cache) + AttachmentsColumn, server_cache=server_cache + ) project_id = None if parsed_args.project: project_id = identity_common.find_project( identity_client, parsed_args.project, - parsed_args.project_domain).id + parsed_args.project_domain, + ).id user_id = None if parsed_args.user: - user_id = identity_common.find_user(identity_client, - parsed_args.user, - parsed_args.user_domain).id + user_id = identity_common.find_user( + identity_client, parsed_args.user, parsed_args.user_domain + ).id # set value of 'all_tenants' when using project option all_projects = bool(parsed_args.project) or parsed_args.all_projects @@ -489,14 +519,23 @@ class ListVolume(command.Lister): limit=parsed_args.limit, ) column_headers = utils.backward_compat_col_lister( - column_headers, parsed_args.columns, {'Display Name': 'Name'}) + column_headers, parsed_args.columns, {'Display Name': 'Name'} + ) - return (column_headers, - (utils.get_item_properties( - s, columns, - formatters={'Metadata': format_columns.DictColumn, - 'Attachments': AttachmentsColumnWithCache}, - ) for s in data)) + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, + formatters={ + 'Metadata': format_columns.DictColumn, + 'Attachments': AttachmentsColumnWithCache, + }, + ) + for s in data + ), + ) class MigrateVolume(command.Command): @@ -507,35 +546,44 @@ class MigrateVolume(command.Command): parser.add_argument( 'volume', metavar="<volume>", - help=_("Volume to migrate (name or ID)") + help=_("Volume to migrate (name or ID)"), ) parser.add_argument( '--host', metavar="<host>", required=True, - help=_("Destination host (takes the form: host@backend-name#pool)") + help=_( + "Destination host (takes the form: host@backend-name#pool)" + ), ) parser.add_argument( '--force-host-copy', action="store_true", - help=_("Enable generic host-based force-migration, " - "which bypasses driver optimizations") + help=_( + "Enable generic host-based force-migration, " + "which bypasses driver optimizations" + ), ) parser.add_argument( '--lock-volume', action="store_true", - help=_("If specified, the volume state will be locked " - "and will not allow a migration to be aborted " - "(possibly by another operation)") + help=_( + "If specified, the volume state will be locked " + "and will not allow a migration to be aborted " + "(possibly by another operation)" + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume volume = utils.find_resource(volume_client.volumes, parsed_args.volume) - volume_client.volumes.migrate_volume(volume.id, parsed_args.host, - parsed_args.force_host_copy, - parsed_args.lock_volume,) + volume_client.volumes.migrate_volume( + volume.id, + parsed_args.host, + parsed_args.force_host_copy, + parsed_args.lock_volume, + ) class SetVolume(command.Command): @@ -568,56 +616,76 @@ class SetVolume(command.Command): "--no-property", dest="no_property", action="store_true", - help=_("Remove all properties from <volume> " - "(specify both --no-property and --property to " - "remove the current properties before setting " - "new properties.)"), + help=_( + "Remove all properties from <volume> " + "(specify both --no-property and --property to " + "remove the current properties before setting " + "new properties.)" + ), ) parser.add_argument( '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set a property on this volume ' - '(repeat option to set multiple properties)'), + help=_( + 'Set a property on this volume ' + '(repeat option to set multiple properties)' + ), ) parser.add_argument( '--image-property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set an image property on this volume ' - '(repeat option to set multiple image properties)'), + help=_( + 'Set an image property on this volume ' + '(repeat option to set multiple image properties)' + ), ) parser.add_argument( "--state", metavar="<state>", - choices=['available', 'error', 'creating', 'deleting', - 'in-use', 'attaching', 'detaching', 'error_deleting', - 'maintenance'], - help=_('New volume state ("available", "error", "creating", ' - '"deleting", "in-use", "attaching", "detaching", ' - '"error_deleting" or "maintenance") (admin only) ' - '(This option simply changes the state of the volume ' - 'in the database with no regard to actual status, ' - 'exercise caution when using)'), + choices=[ + 'available', + 'error', + 'creating', + 'deleting', + 'in-use', + 'attaching', + 'detaching', + 'error_deleting', + 'maintenance', + ], + help=_( + 'New volume state ("available", "error", "creating", ' + '"deleting", "in-use", "attaching", "detaching", ' + '"error_deleting" or "maintenance") (admin only) ' + '(This option simply changes the state of the volume ' + 'in the database with no regard to actual status, ' + 'exercise caution when using)' + ), ) attached_group = parser.add_mutually_exclusive_group() attached_group.add_argument( "--attached", action="store_true", - help=_('Set volume attachment status to "attached" ' - '(admin only) ' - '(This option simply changes the state of the volume ' - 'in the database with no regard to actual status, ' - 'exercise caution when using)'), + help=_( + 'Set volume attachment status to "attached" ' + '(admin only) ' + '(This option simply changes the state of the volume ' + 'in the database with no regard to actual status, ' + 'exercise caution when using)' + ), ) attached_group.add_argument( "--detached", action="store_true", - help=_('Set volume attachment status to "detached" ' - '(admin only) ' - '(This option simply changes the state of the volume ' - 'in the database with no regard to actual status, ' - 'exercise caution when using)'), + help=_( + 'Set volume attachment status to "detached" ' + '(admin only) ' + '(This option simply changes the state of the volume ' + 'in the database with no regard to actual status, ' + 'exercise caution when using)' + ), ) parser.add_argument( '--type', @@ -628,31 +696,33 @@ class SetVolume(command.Command): '--retype-policy', metavar='<retype-policy>', choices=['never', 'on-demand'], - help=_('Migration policy while re-typing volume ' - '("never" or "on-demand", default is "never" ) ' - '(available only when --type option is specified)'), + help=_( + 'Migration policy while re-typing volume ' + '("never" or "on-demand", default is "never" ) ' + '(available only when --type option is specified)' + ), ) bootable_group = parser.add_mutually_exclusive_group() bootable_group.add_argument( "--bootable", action="store_true", - help=_("Mark volume as bootable") + help=_("Mark volume as bootable"), ) bootable_group.add_argument( "--non-bootable", action="store_true", - help=_("Mark volume as non-bootable") + help=_("Mark volume as non-bootable"), ) readonly_group = parser.add_mutually_exclusive_group() readonly_group.add_argument( "--read-only", action="store_true", - help=_("Set volume to read-only access mode") + help=_("Set volume to read-only access mode"), ) readonly_group.add_argument( "--read-write", action="store_true", - help=_("Set volume to read-write access mode") + help=_("Set volume to read-write access mode"), ) return parser @@ -664,14 +734,21 @@ class SetVolume(command.Command): if parsed_args.size: try: if parsed_args.size <= volume.size: - msg = (_("New size must be greater than %s GB") - % volume.size) + msg = ( + _("New size must be greater than %s GB") % volume.size + ) raise exceptions.CommandError(msg) - if volume.status != 'available' and \ - not volume_client.api_version.matches('3.42'): - - msg = (_("Volume is in %s state, it must be available " - "before size can be extended") % volume.status) + if ( + volume.status != 'available' + and not volume_client.api_version.matches('3.42') + ): + msg = ( + _( + "Volume is in %s state, it must be available " + "before size can be extended" + ) + % volume.status + ) raise exceptions.CommandError(msg) volume_client.volumes.extend(volume.id, parsed_args.size) except Exception as e: @@ -681,7 +758,8 @@ class SetVolume(command.Command): if parsed_args.no_property: try: volume_client.volumes.delete_metadata( - volume.id, volume.metadata.keys()) + volume.id, volume.metadata.keys() + ) except Exception as e: LOG.error(_("Failed to clean volume properties: %s"), e) result += 1 @@ -689,55 +767,62 @@ class SetVolume(command.Command): if parsed_args.property: try: volume_client.volumes.set_metadata( - volume.id, parsed_args.property) + volume.id, parsed_args.property + ) except Exception as e: LOG.error(_("Failed to set volume property: %s"), e) result += 1 if parsed_args.image_property: try: volume_client.volumes.set_image_metadata( - volume.id, parsed_args.image_property) + volume.id, parsed_args.image_property + ) except Exception as e: LOG.error(_("Failed to set image property: %s"), e) result += 1 if parsed_args.state: try: - volume_client.volumes.reset_state( - volume.id, parsed_args.state) + volume_client.volumes.reset_state(volume.id, parsed_args.state) except Exception as e: LOG.error(_("Failed to set volume state: %s"), e) result += 1 if parsed_args.attached: try: volume_client.volumes.reset_state( - volume.id, state=None, - attach_status="attached") + volume.id, state=None, attach_status="attached" + ) except Exception as e: LOG.error(_("Failed to set volume attach-status: %s"), e) result += 1 if parsed_args.detached: try: volume_client.volumes.reset_state( - volume.id, state=None, - attach_status="detached") + volume.id, state=None, attach_status="detached" + ) except Exception as e: LOG.error(_("Failed to set volume attach-status: %s"), e) result += 1 if parsed_args.bootable or parsed_args.non_bootable: try: volume_client.volumes.set_bootable( - volume.id, parsed_args.bootable) + volume.id, parsed_args.bootable + ) except Exception as e: LOG.error(_("Failed to set volume bootable property: %s"), e) result += 1 if parsed_args.read_only or parsed_args.read_write: try: volume_client.volumes.update_readonly_flag( - volume.id, - parsed_args.read_only) + volume.id, parsed_args.read_only + ) except Exception as e: - LOG.error(_("Failed to set volume read-only access " - "mode flag: %s"), e) + LOG.error( + _( + "Failed to set volume read-only access " + "mode flag: %s" + ), + e, + ) result += 1 if parsed_args.type: # get the migration policy @@ -747,20 +832,23 @@ class SetVolume(command.Command): try: # find the volume type volume_type = utils.find_resource( - volume_client.volume_types, - parsed_args.type) + volume_client.volume_types, parsed_args.type + ) # reset to the new volume type volume_client.volumes.retype( - volume.id, - volume_type.id, - migration_policy) + volume.id, volume_type.id, migration_policy + ) except Exception as e: LOG.error(_("Failed to set volume type: %s"), e) result += 1 elif parsed_args.retype_policy: # If the "--retype-policy" is specified without "--type" - LOG.warning(_("'--retype-policy' option will not work " - "without '--type' option")) + LOG.warning( + _( + "'--retype-policy' option will not work " + "without '--type' option" + ) + ) kwargs = {} if parsed_args.name: @@ -771,13 +859,19 @@ class SetVolume(command.Command): try: volume_client.volumes.update(volume.id, **kwargs) except Exception as e: - LOG.error(_("Failed to update volume display name " - "or display description: %s"), e) + LOG.error( + _( + "Failed to update volume display name " + "or display description: %s" + ), + e, + ) result += 1 if result > 0: - raise exceptions.CommandError(_("One or more of the " - "set operations failed")) + raise exceptions.CommandError( + _("One or more of the " "set operations failed") + ) class ShowVolume(command.ShowOne): @@ -788,7 +882,7 @@ class ShowVolume(command.ShowOne): parser.add_argument( 'volume', metavar="<volume>", - help=_("Volume to display (name or ID)") + help=_("Volume to display (name or ID)"), ) return parser @@ -801,8 +895,9 @@ class ShowVolume(command.ShowOne): # 'volume_type' --> 'type' volume._info.update( { - 'properties': - format_columns.DictColumn(volume._info.pop('metadata')), + 'properties': format_columns.DictColumn( + volume._info.pop('metadata') + ), 'type': volume._info.pop('volume_type'), }, ) @@ -826,28 +921,32 @@ class UnsetVolume(command.Command): '--property', metavar='<key>', action='append', - help=_('Remove a property from volume ' - '(repeat option to remove multiple properties)'), + help=_( + 'Remove a property from volume ' + '(repeat option to remove multiple properties)' + ), ) parser.add_argument( '--image-property', metavar='<key>', action='append', - help=_('Remove an image property from volume ' - '(repeat option to remove multiple image properties)'), + help=_( + 'Remove an image property from volume ' + '(repeat option to remove multiple image properties)' + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - volume = utils.find_resource( - volume_client.volumes, parsed_args.volume) + volume = utils.find_resource(volume_client.volumes, parsed_args.volume) result = 0 if parsed_args.property: try: volume_client.volumes.delete_metadata( - volume.id, parsed_args.property) + volume.id, parsed_args.property + ) except Exception as e: LOG.error(_("Failed to unset volume property: %s"), e) result += 1 @@ -855,11 +954,13 @@ class UnsetVolume(command.Command): if parsed_args.image_property: try: volume_client.volumes.delete_image_metadata( - volume.id, parsed_args.image_property) + volume.id, parsed_args.image_property + ) except Exception as e: LOG.error(_("Failed to unset image property: %s"), e) result += 1 if result > 0: - raise exceptions.CommandError(_("One or more of the " - "unset operations failed")) + raise exceptions.CommandError( + _("One or more of the " "unset operations failed") + ) diff --git a/openstackclient/volume/v2/volume_backend.py b/openstackclient/volume/v2/volume_backend.py index c5194d35..5e9eaf48 100644 --- a/openstackclient/volume/v2/volume_backend.py +++ b/openstackclient/volume/v2/volume_backend.py @@ -28,7 +28,7 @@ class ShowCapability(command.Lister): parser.add_argument( "host", metavar="<host>", - help=_("List capabilities of specified host (host@backend-name)") + help=_("List capabilities of specified host (host@backend-name)"), ) return parser @@ -55,10 +55,16 @@ class ShowCapability(command.Lister): capability_data['key'] = key print_data.append(capability_data) - return (columns, - (utils.get_dict_properties( - s, columns, - ) for s in print_data)) + return ( + columns, + ( + utils.get_dict_properties( + s, + columns, + ) + for s in print_data + ), + ) class ListPool(command.Lister): @@ -70,7 +76,7 @@ class ListPool(command.Lister): "--long", action="store_true", default=False, - help=_("Show detailed information about pools.") + help=_("Show detailed information about pools."), ) # TODO(smcginnis): Starting with Cinder microversion 3.33, user is also # able to pass in --filters with a <key>=<value> pair to filter on. @@ -98,7 +104,7 @@ class ListPool(command.Lister): 'Volumes', 'Capacity', 'Allocated', - 'Max Over Ratio' + 'Max Over Ratio', ] else: columns = [ @@ -107,7 +113,13 @@ class ListPool(command.Lister): headers = columns data = volume_client.pools.list(detailed=parsed_args.long) - return (headers, - (utils.get_item_properties( - s, columns, - ) for s in data)) + return ( + headers, + ( + utils.get_item_properties( + s, + columns, + ) + for s in data + ), + ) diff --git a/openstackclient/volume/v2/volume_backup.py b/openstackclient/volume/v2/volume_backup.py index d96b28e9..7040216a 100644 --- a/openstackclient/volume/v2/volume_backup.py +++ b/openstackclient/volume/v2/volume_backup.py @@ -66,44 +66,42 @@ class CreateVolumeBackup(command.ShowOne): parser.add_argument( "volume", metavar="<volume>", - help=_("Volume to backup (name or ID)") + help=_("Volume to backup (name or ID)"), ) parser.add_argument( - "--name", - metavar="<name>", - help=_("Name of the backup") + "--name", metavar="<name>", help=_("Name of the backup") ) parser.add_argument( "--description", metavar="<description>", - help=_("Description of the backup") + help=_("Description of the backup"), ) parser.add_argument( "--container", metavar="<container>", - help=_("Optional backup container name") + help=_("Optional backup container name"), ) parser.add_argument( "--snapshot", metavar="<snapshot>", - help=_("Snapshot to backup (name or ID)") + help=_("Snapshot to backup (name or ID)"), ) parser.add_argument( '--force', action='store_true', default=False, - help=_("Allow to back up an in-use volume") + help=_("Allow to back up an in-use volume"), ) parser.add_argument( '--incremental', action='store_true', default=False, - help=_("Perform an incremental backup") + help=_("Perform an incremental backup"), ) parser.add_argument( '--no-incremental', action='store_false', - help=_("Do not perform an incremental backup") + help=_("Do not perform an incremental backup"), ) parser.add_argument( '--property', @@ -131,14 +129,16 @@ class CreateVolumeBackup(command.ShowOne): volume_client = self.app.client_manager.volume volume_id = utils.find_resource( - volume_client.volumes, parsed_args.volume, + volume_client.volumes, + parsed_args.volume, ).id kwargs = {} if parsed_args.snapshot: kwargs['snapshot_id'] = utils.find_resource( - volume_client.volume_snapshots, parsed_args.snapshot, + volume_client.volume_snapshots, + parsed_args.snapshot, ).id if parsed_args.properties: @@ -183,13 +183,13 @@ class DeleteVolumeBackup(command.Command): "backups", metavar="<backup>", nargs="+", - help=_("Backup(s) to delete (name or ID)") + help=_("Backup(s) to delete (name or ID)"), ) parser.add_argument( '--force', action='store_true', default=False, - help=_("Allow delete in state other than error or available") + help=_("Allow delete in state other than error or available"), ) return parser @@ -200,19 +200,25 @@ class DeleteVolumeBackup(command.Command): for i in parsed_args.backups: try: backup_id = utils.find_resource( - volume_client.backups, i, + volume_client.backups, + i, ).id volume_client.backups.delete(backup_id, parsed_args.force) except Exception as e: result += 1 - LOG.error(_("Failed to delete backup with " - "name or ID '%(backup)s': %(e)s") - % {'backup': i, 'e': e}) + LOG.error( + _( + "Failed to delete backup with " + "name or ID '%(backup)s': %(e)s" + ) + % {'backup': i, 'e': e} + ) if result > 0: total = len(parsed_args.backups) msg = _("%(result)s of %(total)s backups failed to delete.") % { - 'result': result, 'total': total, + 'result': result, + 'total': total, } raise exceptions.CommandError(msg) @@ -226,19 +232,23 @@ class ListVolumeBackup(command.Lister): "--long", action="store_true", default=False, - help=_("List additional fields in output") + help=_("List additional fields in output"), ) parser.add_argument( "--name", metavar="<name>", - help=_("Filters results by the backup name") + help=_("Filters results by the backup name"), ) parser.add_argument( "--status", metavar="<status>", choices=[ - 'creating', 'available', 'deleting', - 'error', 'restoring', 'error_restoring', + 'creating', + 'available', + 'deleting', + 'error', + 'restoring', + 'error_restoring', ], help=_( "Filters results by the backup status, one of: " @@ -306,26 +316,31 @@ class ListVolumeBackup(command.Lister): pass _VolumeIdColumn = functools.partial( - VolumeIdColumn, volume_cache=volume_cache) + VolumeIdColumn, volume_cache=volume_cache + ) filter_volume_id = None if parsed_args.volume: try: filter_volume_id = utils.find_resource( - volume_client.volumes, parsed_args.volume, + volume_client.volumes, + parsed_args.volume, ).id except exceptions.CommandError: # Volume with that ID does not exist, but search for backups # for that volume nevertheless - LOG.debug("No volume with ID %s existing, continuing to " - "search for backups for that volume ID", - parsed_args.volume) + LOG.debug( + "No volume with ID %s existing, continuing to " + "search for backups for that volume ID", + parsed_args.volume, + ) filter_volume_id = parsed_args.volume marker_backup_id = None if parsed_args.marker: marker_backup_id = utils.find_resource( - volume_client.backups, parsed_args.marker, + volume_client.backups, + parsed_args.marker, ).id search_opts = { @@ -344,8 +359,11 @@ class ListVolumeBackup(command.Lister): column_headers, ( utils.get_item_properties( - s, columns, formatters={'volume_id': _VolumeIdColumn}, - ) for s in data + s, + columns, + formatters={'volume_id': _VolumeIdColumn}, + ) + for s in data ), ) @@ -358,7 +376,7 @@ class RestoreVolumeBackup(command.ShowOne): parser.add_argument( "backup", metavar="<backup>", - help=_("Backup to restore (name or ID)") + help=_("Backup to restore (name or ID)"), ) parser.add_argument( "volume", @@ -368,7 +386,7 @@ class RestoreVolumeBackup(command.ShowOne): "Volume to restore to " "(name or ID for existing volume, name only for new volume) " "(default to None)" - ) + ), ) parser.add_argument( "--force", @@ -376,7 +394,7 @@ class RestoreVolumeBackup(command.ShowOne): help=_( "Restore the backup to an existing volume " "(default to False)" - ) + ), ) return parser @@ -401,11 +419,13 @@ class RestoreVolumeBackup(command.ShowOne): msg = _( "Volume '%s' already exists; if you want to restore the " "backup to it you need to specify the '--force' option" - ) % parsed_args.volume - raise exceptions.CommandError(msg) + ) + raise exceptions.CommandError(msg % parsed_args.volume) return volume_client.restores.restore( - backup.id, volume_id, volume_name, + backup.id, + volume_id, + volume_name, ) @@ -417,7 +437,7 @@ class SetVolumeBackup(command.Command): parser.add_argument( "backup", metavar="<backup>", - help=_("Backup to modify (name or ID)") + help=_("Backup to modify (name or ID)"), ) parser.add_argument( '--name', @@ -471,14 +491,12 @@ class SetVolumeBackup(command.Command): def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - backup = utils.find_resource( - volume_client.backups, parsed_args.backup) + backup = utils.find_resource(volume_client.backups, parsed_args.backup) result = 0 if parsed_args.state: try: - volume_client.backups.reset_state( - backup.id, parsed_args.state) + volume_client.backups.reset_state(backup.id, parsed_args.state) except Exception as e: LOG.error(_("Failed to set backup state: %s"), e) result += 1 @@ -553,7 +571,7 @@ class UnsetVolumeBackup(command.Command): parser.add_argument( 'backup', metavar='<backup>', - help=_('Backup to modify (name or ID)') + help=_('Backup to modify (name or ID)'), ) parser.add_argument( '--property', @@ -577,8 +595,7 @@ class UnsetVolumeBackup(command.Command): ) raise exceptions.CommandError(msg) - backup = utils.find_resource( - volume_client.backups, parsed_args.backup) + backup = utils.find_resource(volume_client.backups, parsed_args.backup) metadata = copy.deepcopy(backup.metadata) for key in parsed_args.properties: @@ -586,7 +603,8 @@ class UnsetVolumeBackup(command.Command): # ignore invalid properties but continue LOG.warning( "'%s' is not a valid property for backup '%s'", - key, parsed_args.backup, + key, + parsed_args.backup, ) continue @@ -607,13 +625,12 @@ class ShowVolumeBackup(command.ShowOne): parser.add_argument( "backup", metavar="<backup>", - help=_("Backup to display (name or ID)") + help=_("Backup to display (name or ID)"), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - backup = utils.find_resource(volume_client.backups, - parsed_args.backup) + backup = utils.find_resource(volume_client.backups, parsed_args.backup) backup._info.pop("links", None) return zip(*sorted(backup._info.items())) diff --git a/openstackclient/volume/v2/volume_host.py b/openstackclient/volume/v2/volume_host.py index 2fdeb968..df93c059 100644 --- a/openstackclient/volume/v2/volume_host.py +++ b/openstackclient/volume/v2/volume_host.py @@ -25,23 +25,24 @@ class FailoverVolumeHost(command.Command): def get_parser(self, prog_name): parser = super(FailoverVolumeHost, self).get_parser(prog_name) parser.add_argument( - "host", - metavar="<host-name>", - help=_("Name of volume host") + "host", metavar="<host-name>", help=_("Name of volume host") ) parser.add_argument( "--volume-backend", metavar="<backend-id>", required=True, - help=_("The ID of the volume backend replication " - "target where the host will failover to (required)") + help=_( + "The ID of the volume backend replication " + "target where the host will failover to (required)" + ), ) return parser def take_action(self, parsed_args): service_client = self.app.client_manager.volume - service_client.services.failover_host(parsed_args.host, - parsed_args.volume_backend) + service_client.services.failover_host( + parsed_args.host, parsed_args.volume_backend + ) class SetVolumeHost(command.Command): @@ -50,20 +51,18 @@ class SetVolumeHost(command.Command): def get_parser(self, prog_name): parser = super(SetVolumeHost, self).get_parser(prog_name) parser.add_argument( - "host", - metavar="<host-name>", - help=_("Name of volume host") + "host", metavar="<host-name>", help=_("Name of volume host") ) enabled_group = parser.add_mutually_exclusive_group() enabled_group.add_argument( "--disable", action="store_true", - help=_("Freeze and disable the specified volume host") + help=_("Freeze and disable the specified volume host"), ) enabled_group.add_argument( "--enable", action="store_true", - help=_("Thaw and enable the specified volume host") + help=_("Thaw and enable the specified volume host"), ) return parser diff --git a/openstackclient/volume/v2/volume_snapshot.py b/openstackclient/volume/v2/volume_snapshot.py index 53d8d27f..376c2b5e 100644 --- a/openstackclient/volume/v2/volume_snapshot.py +++ b/openstackclient/volume/v2/volume_snapshot.py @@ -72,36 +72,44 @@ class CreateVolumeSnapshot(command.ShowOne): parser.add_argument( "--volume", metavar="<volume>", - help=_("Volume to snapshot (name or ID) " - "(default is <snapshot-name>)") + help=_( + "Volume to snapshot (name or ID) " + "(default is <snapshot-name>)" + ), ) parser.add_argument( "--description", metavar="<description>", - help=_("Description of the snapshot") + help=_("Description of the snapshot"), ) parser.add_argument( "--force", action="store_true", default=False, - help=_("Create a snapshot attached to an instance. " - "Default is False") + help=_( + "Create a snapshot attached to an instance. " + "Default is False" + ), ) parser.add_argument( "--property", metavar="<key=value>", action=parseractions.KeyValueAction, - help=_("Set a property to this snapshot " - "(repeat option to set multiple properties)"), + help=_( + "Set a property to this snapshot " + "(repeat option to set multiple properties)" + ), ) parser.add_argument( "--remote-source", metavar="<key=value>", action=parseractions.KeyValueAction, - help=_("The attribute(s) of the existing remote volume snapshot " - "(admin required) (repeat option to specify multiple " - "attributes) e.g.: '--remote-source source-name=test_name " - "--remote-source source-id=test_id'"), + help=_( + "The attribute(s) of the existing remote volume snapshot " + "(admin required) (repeat option to specify multiple " + "attributes) e.g.: '--remote-source source-name=test_name " + "--remote-source source-id=test_id'" + ), ) return parser @@ -110,14 +118,15 @@ class CreateVolumeSnapshot(command.ShowOne): volume = parsed_args.volume if not parsed_args.volume: volume = parsed_args.snapshot_name - volume_id = utils.find_resource( - volume_client.volumes, volume).id + volume_id = utils.find_resource(volume_client.volumes, volume).id if parsed_args.remote_source: # Create a new snapshot from an existing remote snapshot source if parsed_args.force: - msg = (_("'--force' option will not work when you create " - "new volume snapshot from an existing remote " - "volume snapshot")) + msg = _( + "'--force' option will not work when you create " + "new volume snapshot from an existing remote " + "volume snapshot" + ) LOG.warning(msg) snapshot = volume_client.volume_snapshots.manage( volume_id=volume_id, @@ -136,8 +145,11 @@ class CreateVolumeSnapshot(command.ShowOne): metadata=parsed_args.property, ) snapshot._info.update( - {'properties': - format_columns.DictColumn(snapshot._info.pop('metadata'))} + { + 'properties': format_columns.DictColumn( + snapshot._info.pop('metadata') + ) + } ) return zip(*sorted(snapshot._info.items())) @@ -151,13 +163,15 @@ class DeleteVolumeSnapshot(command.Command): "snapshots", metavar="<snapshot>", nargs="+", - help=_("Snapshot(s) to delete (name or ID)") + help=_("Snapshot(s) to delete (name or ID)"), ) parser.add_argument( '--force', action='store_true', - help=_("Attempt forced removal of snapshot(s), " - "regardless of state (defaults to False)") + help=_( + "Attempt forced removal of snapshot(s), " + "regardless of state (defaults to False)" + ), ) return parser @@ -168,19 +182,26 @@ class DeleteVolumeSnapshot(command.Command): for i in parsed_args.snapshots: try: snapshot_id = utils.find_resource( - volume_client.volume_snapshots, i).id + volume_client.volume_snapshots, i + ).id volume_client.volume_snapshots.delete( - snapshot_id, parsed_args.force) + snapshot_id, parsed_args.force + ) except Exception as e: result += 1 - LOG.error(_("Failed to delete snapshot with " - "name or ID '%(snapshot)s': %(e)s") - % {'snapshot': i, 'e': e}) + LOG.error( + _( + "Failed to delete snapshot with " + "name or ID '%(snapshot)s': %(e)s" + ) + % {'snapshot': i, 'e': e} + ) if result > 0: total = len(parsed_args.snapshots) - msg = (_("%(result)s of %(total)s snapshots failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s snapshots failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -198,7 +219,7 @@ class ListVolumeSnapshot(command.Lister): parser.add_argument( '--project', metavar='<project>', - help=_('Filter results by project (name or ID) (admin only)') + help=_('Filter results by project (name or ID) (admin only)'), ) identity_common.add_project_domain_option_to_parser(parser) parser.add_argument( @@ -223,22 +244,29 @@ class ListVolumeSnapshot(command.Lister): '--name', metavar='<name>', default=None, - help=_('Filters results by a name.') + help=_('Filters results by a name.'), ) parser.add_argument( '--status', metavar='<status>', - choices=['available', 'error', 'creating', 'deleting', - 'error_deleting'], - help=_("Filters results by a status. " - "('available', 'error', 'creating', 'deleting'" - " or 'error_deleting')") + choices=[ + 'available', + 'error', + 'creating', + 'deleting', + 'error_deleting', + ], + help=_( + "Filters results by a status. " + "('available', 'error', 'creating', 'deleting'" + " or 'error_deleting')" + ), ) parser.add_argument( '--volume', metavar='<volume>', default=None, - help=_('Filters results by a volume (name or ID).') + help=_('Filters results by a volume (name or ID).'), ) return parser @@ -247,8 +275,16 @@ class ListVolumeSnapshot(command.Lister): identity_client = self.app.client_manager.identity if parsed_args.long: - columns = ['ID', 'Name', 'Description', 'Status', - 'Size', 'Created At', 'Volume ID', 'Metadata'] + columns = [ + 'ID', + 'Name', + 'Description', + 'Status', + 'Size', + 'Created At', + 'Volume ID', + 'Metadata', + ] column_headers = copy.deepcopy(columns) column_headers[6] = 'Volume' column_headers[7] = 'Properties' @@ -264,24 +300,28 @@ class ListVolumeSnapshot(command.Lister): except Exception: # Just forget it if there's any trouble pass - _VolumeIdColumn = functools.partial(VolumeIdColumn, - volume_cache=volume_cache) + _VolumeIdColumn = functools.partial( + VolumeIdColumn, volume_cache=volume_cache + ) volume_id = None if parsed_args.volume: volume_id = utils.find_resource( - volume_client.volumes, parsed_args.volume).id + volume_client.volumes, parsed_args.volume + ).id project_id = None if parsed_args.project: project_id = identity_common.find_project( identity_client, parsed_args.project, - parsed_args.project_domain).id + parsed_args.project_domain, + ).id # set value of 'all_tenants' when using project option - all_projects = True if parsed_args.project else \ - parsed_args.all_projects + all_projects = ( + True if parsed_args.project else parsed_args.all_projects + ) search_opts = { 'all_tenants': all_projects, @@ -296,12 +336,20 @@ class ListVolumeSnapshot(command.Lister): marker=parsed_args.marker, limit=parsed_args.limit, ) - return (column_headers, - (utils.get_item_properties( - s, columns, - formatters={'Metadata': format_columns.DictColumn, - 'Volume ID': _VolumeIdColumn}, - ) for s in data)) + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, + formatters={ + 'Metadata': format_columns.DictColumn, + 'Volume ID': _VolumeIdColumn, + }, + ) + for s in data + ), + ) class SetVolumeSnapshot(command.Command): @@ -312,51 +360,61 @@ class SetVolumeSnapshot(command.Command): parser.add_argument( 'snapshot', metavar='<snapshot>', - help=_('Snapshot to modify (name or ID)') + help=_('Snapshot to modify (name or ID)'), ) parser.add_argument( - '--name', - metavar='<name>', - help=_('New snapshot name') + '--name', metavar='<name>', help=_('New snapshot name') ) parser.add_argument( '--description', metavar='<description>', - help=_('New snapshot description') + help=_('New snapshot description'), ) parser.add_argument( "--no-property", dest="no_property", action="store_true", - help=_("Remove all properties from <snapshot> " - "(specify both --no-property and --property to " - "remove the current properties before setting " - "new properties.)"), + help=_( + "Remove all properties from <snapshot> " + "(specify both --no-property and --property to " + "remove the current properties before setting " + "new properties.)" + ), ) parser.add_argument( '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Property to add/change for this snapshot ' - '(repeat option to set multiple properties)'), + help=_( + 'Property to add/change for this snapshot ' + '(repeat option to set multiple properties)' + ), ) parser.add_argument( '--state', metavar='<state>', - choices=['available', 'error', 'creating', 'deleting', - 'error_deleting'], - help=_('New snapshot state. ("available", "error", "creating", ' - '"deleting", or "error_deleting") (admin only) ' - '(This option simply changes the state of the snapshot ' - 'in the database with no regard to actual status, ' - 'exercise caution when using)'), + choices=[ + 'available', + 'error', + 'creating', + 'deleting', + 'error_deleting', + ], + help=_( + 'New snapshot state. ("available", "error", "creating", ' + '"deleting", or "error_deleting") (admin only) ' + '(This option simply changes the state of the snapshot ' + 'in the database with no regard to actual status, ' + 'exercise caution when using)' + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - snapshot = utils.find_resource(volume_client.volume_snapshots, - parsed_args.snapshot) + snapshot = utils.find_resource( + volume_client.volume_snapshots, parsed_args.snapshot + ) result = 0 if parsed_args.no_property: @@ -373,7 +431,8 @@ class SetVolumeSnapshot(command.Command): if parsed_args.property: try: volume_client.volume_snapshots.set_metadata( - snapshot.id, parsed_args.property) + snapshot.id, parsed_args.property + ) except Exception as e: LOG.error(_("Failed to set snapshot property: %s"), e) result += 1 @@ -381,7 +440,8 @@ class SetVolumeSnapshot(command.Command): if parsed_args.state: try: volume_client.volume_snapshots.reset_state( - snapshot.id, parsed_args.state) + snapshot.id, parsed_args.state + ) except Exception as e: LOG.error(_("Failed to set snapshot state: %s"), e) result += 1 @@ -393,16 +453,18 @@ class SetVolumeSnapshot(command.Command): kwargs['description'] = parsed_args.description if kwargs: try: - volume_client.volume_snapshots.update( - snapshot.id, **kwargs) + volume_client.volume_snapshots.update(snapshot.id, **kwargs) except Exception as e: - LOG.error(_("Failed to update snapshot name " - "or description: %s"), e) + LOG.error( + _("Failed to update snapshot name " "or description: %s"), + e, + ) result += 1 if result > 0: - raise exceptions.CommandError(_("One or more of the " - "set operations failed")) + raise exceptions.CommandError( + _("One or more of the " "set operations failed") + ) class ShowVolumeSnapshot(command.ShowOne): @@ -413,17 +475,21 @@ class ShowVolumeSnapshot(command.ShowOne): parser.add_argument( "snapshot", metavar="<snapshot>", - help=_("Snapshot to display (name or ID)") + help=_("Snapshot to display (name or ID)"), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume snapshot = utils.find_resource( - volume_client.volume_snapshots, parsed_args.snapshot) + volume_client.volume_snapshots, parsed_args.snapshot + ) snapshot._info.update( - {'properties': - format_columns.DictColumn(snapshot._info.pop('metadata'))} + { + 'properties': format_columns.DictColumn( + snapshot._info.pop('metadata') + ) + } ) return zip(*sorted(snapshot._info.items())) @@ -443,15 +509,18 @@ class UnsetVolumeSnapshot(command.Command): metavar='<key>', action='append', default=[], - help=_('Property to remove from snapshot ' - '(repeat option to remove multiple properties)'), + help=_( + 'Property to remove from snapshot ' + '(repeat option to remove multiple properties)' + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume snapshot = utils.find_resource( - volume_client.volume_snapshots, parsed_args.snapshot) + volume_client.volume_snapshots, parsed_args.snapshot + ) if parsed_args.property: volume_client.volume_snapshots.delete_metadata( diff --git a/openstackclient/volume/v2/volume_transfer_request.py b/openstackclient/volume/v2/volume_transfer_request.py index 89199336..e25770e3 100644 --- a/openstackclient/volume/v2/volume_transfer_request.py +++ b/openstackclient/volume/v2/volume_transfer_request.py @@ -50,8 +50,7 @@ class AcceptTransferRequest(command.ShowOne): try: transfer_request_id = utils.find_resource( - volume_client.transfers, - parsed_args.transfer_request + volume_client.transfers, parsed_args.transfer_request ).id except exceptions.CommandError: # Non-admin users will fail to lookup name -> ID so we just @@ -160,14 +159,20 @@ class DeleteTransferRequest(command.Command): volume_client.transfers.delete(transfer_request_id) except Exception as e: result += 1 - LOG.error(_("Failed to delete volume transfer request " - "with name or ID '%(transfer)s': %(e)s") - % {'transfer': t, 'e': e}) + LOG.error( + _( + "Failed to delete volume transfer request " + "with name or ID '%(transfer)s': %(e)s" + ) + % {'transfer': t, 'e': e} + ) if result > 0: total = len(parsed_args.transfer_request) - msg = (_("%(result)s of %(total)s volume transfer requests failed" - " to delete") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s volume transfer requests failed" + " to delete" + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -196,9 +201,13 @@ class ListTransferRequest(command.Lister): search_opts={'all_tenants': parsed_args.all_projects}, ) - return (column_headers, ( - utils.get_item_properties(s, columns) - for s in volume_transfer_result)) + return ( + column_headers, + ( + utils.get_item_properties(s, columns) + for s in volume_transfer_result + ), + ) class ShowTransferRequest(command.ShowOne): diff --git a/openstackclient/volume/v2/volume_type.py b/openstackclient/volume/v2/volume_type.py index 483e6dd3..b6813003 100644 --- a/openstackclient/volume/v2/volume_type.py +++ b/openstackclient/volume/v2/volume_type.py @@ -63,8 +63,10 @@ class EncryptionInfoColumn(cliff_columns.FormattableColumn): def _create_encryption_type(volume_client, volume_type, parsed_args): if not parsed_args.encryption_provider: - msg = _("'--encryption-provider' should be specified while " - "creating a new encryption type") + msg = _( + "'--encryption-provider' should be specified while " + "creating a new encryption type" + ) raise exceptions.CommandError(msg) # set the default of control location while creating control_location = 'front-end' @@ -74,10 +76,11 @@ def _create_encryption_type(volume_client, volume_type, parsed_args): 'provider': parsed_args.encryption_provider, 'cipher': parsed_args.encryption_cipher, 'key_size': parsed_args.encryption_key_size, - 'control_location': control_location + 'control_location': control_location, } encryption = volume_client.volume_encryption_types.create( - volume_type, body) + volume_type, body + ) return encryption @@ -93,10 +96,13 @@ def _set_encryption_type(volume_client, volume_type, parsed_args): except Exception as e: if type(e).__name__ == 'NotFound': # create new encryption type - LOG.warning(_("No existing encryption type found, creating " - "new encryption type for this volume type ...")) - _create_encryption_type( - volume_client, volume_type, parsed_args) + LOG.warning( + _( + "No existing encryption type found, creating " + "new encryption type for this volume type ..." + ) + ) + _create_encryption_type(volume_client, volume_type, parsed_args) class CreateVolumeType(command.ShowOne): @@ -131,50 +137,62 @@ class CreateVolumeType(command.ShowOne): '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set a property on this volume type ' - '(repeat option to set multiple properties)'), + help=_( + 'Set a property on this volume type ' + '(repeat option to set multiple properties)' + ), ) parser.add_argument( '--project', metavar='<project>', - help=_("Allow <project> to access private type (name or ID) " - "(Must be used with --private option)"), + help=_( + "Allow <project> to access private type (name or ID) " + "(Must be used with --private option)" + ), ) # TODO(Huanxuan Ao): Add choices for each "--encryption-*" option. parser.add_argument( '--encryption-provider', metavar='<provider>', - help=_('Set the encryption provider format for ' - 'this volume type (e.g "luks" or "plain") (admin only) ' - '(This option is required when setting encryption type ' - 'of a volume. Consider using other encryption options ' - 'such as: "--encryption-cipher", "--encryption-key-size" ' - 'and "--encryption-control-location")'), + help=_( + 'Set the encryption provider format for ' + 'this volume type (e.g "luks" or "plain") (admin only) ' + '(This option is required when setting encryption type ' + 'of a volume. Consider using other encryption options ' + 'such as: "--encryption-cipher", "--encryption-key-size" ' + 'and "--encryption-control-location")' + ), ) parser.add_argument( '--encryption-cipher', metavar='<cipher>', - help=_('Set the encryption algorithm or mode for this ' - 'volume type (e.g "aes-xts-plain64") (admin only)'), + help=_( + 'Set the encryption algorithm or mode for this ' + 'volume type (e.g "aes-xts-plain64") (admin only)' + ), ) parser.add_argument( '--encryption-key-size', metavar='<key-size>', type=int, - help=_('Set the size of the encryption key of this ' - 'volume type (e.g "128" or "256") (admin only)'), + help=_( + 'Set the size of the encryption key of this ' + 'volume type (e.g "128" or "256") (admin only)' + ), ) parser.add_argument( '--encryption-control-location', metavar='<control-location>', choices=['front-end', 'back-end'], - help=_('Set the notional service where the encryption is ' - 'performed ("front-end" or "back-end") (admin only) ' - '(The default value for this option is "front-end" ' - 'when setting encryption type of a volume. Consider ' - 'using other encryption options such as: ' - '"--encryption-cipher", "--encryption-key-size" and ' - '"--encryption-provider")'), + help=_( + 'Set the notional service where the encryption is ' + 'performed ("front-end" or "back-end") (admin only) ' + '(The default value for this option is "front-end" ' + 'when setting encryption type of a volume. Consider ' + 'using other encryption options such as: ' + '"--encryption-cipher", "--encryption-key-size" and ' + '"--encryption-provider")' + ), ) identity_common.add_project_domain_option_to_parser(parser) return parser @@ -194,9 +212,7 @@ class CreateVolumeType(command.ShowOne): kwargs['is_public'] = False volume_type = volume_client.volume_types.create( - parsed_args.name, - description=parsed_args.description, - **kwargs + parsed_args.name, description=parsed_args.description, **kwargs ) volume_type._info.pop('extra_specs') @@ -208,30 +224,43 @@ class CreateVolumeType(command.ShowOne): parsed_args.project_domain, ).id volume_client.volume_type_access.add_project_access( - volume_type.id, project_id) + volume_type.id, project_id + ) except Exception as e: - msg = _("Failed to add project %(project)s access to " - "type: %(e)s") + msg = _( + "Failed to add project %(project)s access to " + "type: %(e)s" + ) LOG.error(msg % {'project': parsed_args.project, 'e': e}) if parsed_args.property: result = volume_type.set_keys(parsed_args.property) volume_type._info.update( - {'properties': format_columns.DictColumn(result)}) - if (parsed_args.encryption_provider or - parsed_args.encryption_cipher or - parsed_args.encryption_key_size or - parsed_args.encryption_control_location): + {'properties': format_columns.DictColumn(result)} + ) + if ( + parsed_args.encryption_provider + or parsed_args.encryption_cipher + or parsed_args.encryption_key_size + or parsed_args.encryption_control_location + ): try: # create new encryption encryption = _create_encryption_type( - volume_client, volume_type, parsed_args) + volume_client, volume_type, parsed_args + ) except Exception as e: - LOG.error(_("Failed to set encryption information for this " - "volume type: %s"), e) + LOG.error( + _( + "Failed to set encryption information for this " + "volume type: %s" + ), + e, + ) # add encryption info in result encryption._info.pop("volume_type_id", None) volume_type._info.update( - {'encryption': format_columns.DictColumn(encryption._info)}) + {'encryption': format_columns.DictColumn(encryption._info)} + ) volume_type._info.pop("os-volume-type-access:is_public", None) return zip(*sorted(volume_type._info.items())) @@ -246,7 +275,7 @@ class DeleteVolumeType(command.Command): "volume_types", metavar="<volume-type>", nargs="+", - help=_("Volume type(s) to delete (name or ID)") + help=_("Volume type(s) to delete (name or ID)"), ) return parser @@ -256,20 +285,26 @@ class DeleteVolumeType(command.Command): for volume_type in parsed_args.volume_types: try: - vol_type = utils.find_resource(volume_client.volume_types, - volume_type) + vol_type = utils.find_resource( + volume_client.volume_types, volume_type + ) volume_client.volume_types.delete(vol_type) except Exception as e: result += 1 - LOG.error(_("Failed to delete volume type with " - "name or ID '%(volume_type)s': %(e)s") - % {'volume_type': volume_type, 'e': e}) + LOG.error( + _( + "Failed to delete volume type with " + "name or ID '%(volume_type)s': %(e)s" + ) + % {'volume_type': volume_type, 'e': e} + ) if result > 0: total = len(parsed_args.volume_types) - msg = (_("%(result)s of %(total)s volume types failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s volume types failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -282,30 +317,30 @@ class ListVolumeType(command.Lister): '--long', action='store_true', default=False, - help=_('List additional fields in output') + help=_('List additional fields in output'), ) public_group = parser.add_mutually_exclusive_group() public_group.add_argument( "--default", action='store_true', default=False, - help=_('List the default volume type') + help=_('List the default volume type'), ) public_group.add_argument( - "--public", - action="store_true", - help=_("List only public types") + "--public", action="store_true", help=_("List only public types") ) public_group.add_argument( "--private", action="store_true", - help=_("List only private types (admin only)") + help=_("List only private types (admin only)"), ) parser.add_argument( "--encryption-type", action="store_true", - help=_("Display encryption information for each volume type " - "(admin only)"), + help=_( + "Display encryption information for each volume type " + "(admin only)" + ), ) return parser @@ -314,7 +349,12 @@ class ListVolumeType(command.Lister): if parsed_args.long: columns = ['ID', 'Name', 'Is Public', 'Description', 'Extra Specs'] column_headers = [ - 'ID', 'Name', 'Is Public', 'Description', 'Properties'] + 'ID', + 'Name', + 'Is Public', + 'Description', + 'Properties', + ] else: columns = ['ID', 'Name', 'Is Public'] column_headers = ['ID', 'Name', 'Is Public'] @@ -326,8 +366,7 @@ class ListVolumeType(command.Lister): is_public = True if parsed_args.private: is_public = False - data = volume_client.volume_types.list( - is_public=is_public) + data = volume_client.volume_types.list(is_public=is_public) formatters = {'Extra Specs': format_columns.DictColumn} @@ -341,7 +380,7 @@ class ListVolumeType(command.Lister): 'created_at', 'updated_at', 'deleted_at', - 'volume_type_id' + 'volume_type_id', ] for key in del_key: d._info.pop(key, None) @@ -354,14 +393,21 @@ class ListVolumeType(command.Lister): column_headers += ['Encryption'] _EncryptionInfoColumn = functools.partial( - EncryptionInfoColumn, encryption_data=encryption) + EncryptionInfoColumn, encryption_data=encryption + ) formatters['id'] = _EncryptionInfoColumn - return (column_headers, - (utils.get_item_properties( - s, columns, + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, formatters=formatters, - ) for s in data)) + ) + for s in data + ), + ) class SetVolumeType(command.Command): @@ -388,52 +434,64 @@ class SetVolumeType(command.Command): '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set a property on this volume type ' - '(repeat option to set multiple properties)'), + help=_( + 'Set a property on this volume type ' + '(repeat option to set multiple properties)' + ), ) parser.add_argument( '--project', metavar='<project>', - help=_('Set volume type access to project (name or ID) ' - '(admin only)'), + help=_( + 'Set volume type access to project (name or ID) ' + '(admin only)' + ), ) identity_common.add_project_domain_option_to_parser(parser) # TODO(Huanxuan Ao): Add choices for each "--encryption-*" option. parser.add_argument( '--encryption-provider', metavar='<provider>', - help=_('Set the encryption provider format for ' - 'this volume type (e.g "luks" or "plain") (admin only) ' - '(This option is required when setting encryption type ' - 'of a volume for the first time. Consider using other ' - 'encryption options such as: "--encryption-cipher", ' - '"--encryption-key-size" and ' - '"--encryption-control-location")'), + help=_( + 'Set the encryption provider format for ' + 'this volume type (e.g "luks" or "plain") (admin only) ' + '(This option is required when setting encryption type ' + 'of a volume for the first time. Consider using other ' + 'encryption options such as: "--encryption-cipher", ' + '"--encryption-key-size" and ' + '"--encryption-control-location")' + ), ) parser.add_argument( '--encryption-cipher', metavar='<cipher>', - help=_('Set the encryption algorithm or mode for this ' - 'volume type (e.g "aes-xts-plain64") (admin only)'), + help=_( + 'Set the encryption algorithm or mode for this ' + 'volume type (e.g "aes-xts-plain64") (admin only)' + ), ) parser.add_argument( '--encryption-key-size', metavar='<key-size>', type=int, - help=_('Set the size of the encryption key of this ' - 'volume type (e.g "128" or "256") (admin only)'), + help=_( + 'Set the size of the encryption key of this ' + 'volume type (e.g "128" or "256") (admin only)' + ), ) parser.add_argument( '--encryption-control-location', metavar='<control-location>', choices=['front-end', 'back-end'], - help=_('Set the notional service where the encryption is ' - 'performed ("front-end" or "back-end") (admin only) ' - '(The default value for this option is "front-end" ' - 'when setting encryption type of a volume for the ' - 'first time. Consider using other encryption options ' - 'such as: "--encryption-cipher", "--encryption-key-size" ' - 'and "--encryption-provider")'), + help=_( + 'Set the notional service where the encryption is ' + 'performed ("front-end" or "back-end") (admin only) ' + '(The default value for this option is "front-end" ' + 'when setting encryption type of a volume for the ' + 'first time. Consider using other encryption options ' + 'such as: "--encryption-cipher", "--encryption-key-size" ' + 'and "--encryption-provider")' + ), ) return parser @@ -442,7 +500,8 @@ class SetVolumeType(command.Command): identity_client = self.app.client_manager.identity volume_type = utils.find_resource( - volume_client.volume_types, parsed_args.volume_type) + volume_client.volume_types, parsed_args.volume_type + ) result = 0 kwargs = {} if parsed_args.name: @@ -452,13 +511,15 @@ class SetVolumeType(command.Command): if kwargs: try: - volume_client.volume_types.update( - volume_type.id, - **kwargs - ) + volume_client.volume_types.update(volume_type.id, **kwargs) except Exception as e: - LOG.error(_("Failed to update volume type name or" - " description: %s"), e) + LOG.error( + _( + "Failed to update volume type name or" + " description: %s" + ), + e, + ) result += 1 if parsed_args.property: @@ -474,29 +535,40 @@ class SetVolumeType(command.Command): project_info = identity_common.find_project( identity_client, parsed_args.project, - parsed_args.project_domain) + parsed_args.project_domain, + ) volume_client.volume_type_access.add_project_access( - volume_type.id, project_info.id) + volume_type.id, project_info.id + ) except Exception as e: - LOG.error(_("Failed to set volume type access to " - "project: %s"), e) + LOG.error( + _("Failed to set volume type access to " "project: %s"), e + ) result += 1 - if (parsed_args.encryption_provider or - parsed_args.encryption_cipher or - parsed_args.encryption_key_size or - parsed_args.encryption_control_location): + if ( + parsed_args.encryption_provider + or parsed_args.encryption_cipher + or parsed_args.encryption_key_size + or parsed_args.encryption_control_location + ): try: _set_encryption_type(volume_client, volume_type, parsed_args) except Exception as e: - LOG.error(_("Failed to set encryption information for this " - "volume type: %s"), e) + LOG.error( + _( + "Failed to set encryption information for this " + "volume type: %s" + ), + e, + ) result += 1 if result > 0: - raise exceptions.CommandError(_("Command Failed: One or more of" - " the operations failed")) + raise exceptions.CommandError( + _("Command Failed: One or more of" " the operations failed") + ) class ShowVolumeType(command.ShowOne): @@ -507,50 +579,65 @@ class ShowVolumeType(command.ShowOne): parser.add_argument( "volume_type", metavar="<volume-type>", - help=_("Volume type to display (name or ID)") + help=_("Volume type to display (name or ID)"), ) parser.add_argument( "--encryption-type", action="store_true", - help=_("Display encryption information of this volume type " - "(admin only)"), + help=_( + "Display encryption information of this volume type " + "(admin only)" + ), ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume volume_type = utils.find_resource( - volume_client.volume_types, parsed_args.volume_type) + volume_client.volume_types, parsed_args.volume_type + ) properties = format_columns.DictColumn( - volume_type._info.pop('extra_specs', {})) + volume_type._info.pop('extra_specs', {}) + ) volume_type._info.update({'properties': properties}) access_project_ids = None if not volume_type.is_public: try: volume_type_access = volume_client.volume_type_access.list( - volume_type.id) - project_ids = [utils.get_field(item, 'project_id') - for item in volume_type_access] + volume_type.id + ) + project_ids = [ + utils.get_field(item, 'project_id') + for item in volume_type_access + ] # TODO(Rui Chen): This format list case can be removed after # patch https://review.opendev.org/#/c/330223/ merged. access_project_ids = format_columns.ListColumn(project_ids) except Exception as e: - msg = _('Failed to get access project list for volume type ' - '%(type)s: %(e)s') + msg = _( + 'Failed to get access project list for volume type ' + '%(type)s: %(e)s' + ) LOG.error(msg % {'type': volume_type.id, 'e': e}) volume_type._info.update({'access_project_ids': access_project_ids}) if parsed_args.encryption_type: # show encryption type information for this volume type try: encryption = volume_client.volume_encryption_types.get( - volume_type.id) + volume_type.id + ) encryption._info.pop("volume_type_id", None) volume_type._info.update( - {'encryption': - format_columns.DictColumn(encryption._info)}) + {'encryption': format_columns.DictColumn(encryption._info)} + ) except Exception as e: - LOG.error(_("Failed to display the encryption information " - "of this volume type: %s"), e) + LOG.error( + _( + "Failed to display the encryption information " + "of this volume type: %s" + ), + e, + ) volume_type._info.pop("os-volume-type-access:is_public", None) return zip(*sorted(volume_type._info.items())) @@ -569,21 +656,27 @@ class UnsetVolumeType(command.Command): '--property', metavar='<key>', action='append', - help=_('Remove a property from this volume type ' - '(repeat option to remove multiple properties)'), + help=_( + 'Remove a property from this volume type ' + '(repeat option to remove multiple properties)' + ), ) parser.add_argument( '--project', metavar='<project>', - help=_('Removes volume type access to project (name or ID) ' - '(admin only)'), + help=_( + 'Removes volume type access to project (name or ID) ' + '(admin only)' + ), ) identity_common.add_project_domain_option_to_parser(parser) parser.add_argument( "--encryption-type", action="store_true", - help=_("Remove the encryption type for this volume type " - "(admin only)"), + help=_( + "Remove the encryption type for this volume type " + "(admin only)" + ), ) return parser @@ -610,22 +703,35 @@ class UnsetVolumeType(command.Command): project_info = identity_common.find_project( identity_client, parsed_args.project, - parsed_args.project_domain) + parsed_args.project_domain, + ) volume_client.volume_type_access.remove_project_access( - volume_type.id, project_info.id) + volume_type.id, project_info.id + ) except Exception as e: - LOG.error(_("Failed to remove volume type access from " - "project: %s"), e) + LOG.error( + _( + "Failed to remove volume type access from " + "project: %s" + ), + e, + ) result += 1 if parsed_args.encryption_type: try: volume_client.volume_encryption_types.delete(volume_type) except Exception as e: - LOG.error(_("Failed to remove the encryption type for this " - "volume type: %s"), e) + LOG.error( + _( + "Failed to remove the encryption type for this " + "volume type: %s" + ), + e, + ) result += 1 if result > 0: - raise exceptions.CommandError(_("Command Failed: One or more of" - " the operations failed")) + raise exceptions.CommandError( + _("Command Failed: One or more of" " the operations failed") + ) diff --git a/openstackclient/volume/v3/block_storage_cleanup.py b/openstackclient/volume/v3/block_storage_cleanup.py index f99b8217..361440c9 100644 --- a/openstackclient/volume/v3/block_storage_cleanup.py +++ b/openstackclient/volume/v3/block_storage_cleanup.py @@ -31,8 +31,13 @@ def _format_cleanup_response(cleaning, unavailable): combined_data.append(details) for obj in unavailable: - details = (obj.id, obj.cluster_name, obj.host, obj.binary, - 'Unavailable') + details = ( + obj.id, + obj.cluster_name, + obj.host, + obj.binary, + 'Unavailable', + ) combined_data.append(details) return (column_headers, combined_data) @@ -49,20 +54,22 @@ class BlockStorageCleanup(command.Lister): parser.add_argument( '--cluster', metavar='<cluster>', - help=_('Name of block storage cluster in which cleanup needs ' - 'to be performed (name only)') + help=_( + 'Name of block storage cluster in which cleanup needs ' + 'to be performed (name only)' + ), ) parser.add_argument( "--host", metavar="<host>", default=None, - help=_("Host where the service resides. (name only)") + help=_("Host where the service resides. (name only)"), ) parser.add_argument( '--binary', metavar='<binary>', default=None, - help=_("Name of the service binary.") + help=_("Name of the service binary."), ) service_up_parser = parser.add_mutually_exclusive_group() service_up_parser.add_argument( @@ -72,7 +79,7 @@ class BlockStorageCleanup(command.Lister): default=None, help=_( 'Filter by up status. If this is set, services need to be up.' - ) + ), ) service_up_parser.add_argument( '--down', @@ -81,7 +88,7 @@ class BlockStorageCleanup(command.Lister): help=_( 'Filter by down status. If this is set, services need to be ' 'down.' - ) + ), ) service_disabled_parser = parser.add_mutually_exclusive_group() service_disabled_parser.add_argument( @@ -89,25 +96,25 @@ class BlockStorageCleanup(command.Lister): dest='disabled', action='store_true', default=None, - help=_('Filter by disabled status.') + help=_('Filter by disabled status.'), ) service_disabled_parser.add_argument( '--enabled', dest='disabled', action='store_false', - help=_('Filter by enabled status.') + help=_('Filter by enabled status.'), ) parser.add_argument( '--resource-id', metavar='<resource-id>', default=None, - help=_('UUID of a resource to cleanup.') + help=_('UUID of a resource to cleanup.'), ) parser.add_argument( '--resource-type', metavar='<Volume|Snapshot>', choices=('Volume', 'Snapshot'), - help=_('Type of resource to cleanup.') + help=_('Type of resource to cleanup.'), ) parser.add_argument( '--service-id', @@ -116,7 +123,7 @@ class BlockStorageCleanup(command.Lister): help=_( 'The service ID field from the DB, not the UUID of the ' 'service.' - ) + ), ) return parser @@ -138,7 +145,7 @@ class BlockStorageCleanup(command.Lister): 'disabled': parsed_args.disabled, 'resource_id': parsed_args.resource_id, 'resource_type': parsed_args.resource_type, - 'service_id': parsed_args.service_id + 'service_id': parsed_args.service_id, } filters = {k: v for k, v in filters.items() if v is not None} diff --git a/openstackclient/volume/v3/block_storage_cluster.py b/openstackclient/volume/v3/block_storage_cluster.py index 34b25efc..58bcae67 100644 --- a/openstackclient/volume/v3/block_storage_cluster.py +++ b/openstackclient/volume/v3/block_storage_cluster.py @@ -76,7 +76,9 @@ class ListBlockStorageCluster(command.Lister): def get_parser(self, prog_name): parser = super().get_parser(prog_name) parser.add_argument( - '--cluster', metavar='<name>', default=None, + '--cluster', + metavar='<name>', + default=None, help=_( 'Filter by cluster name, without backend will list ' 'all clustered services from the same cluster.' @@ -131,7 +133,7 @@ class ListBlockStorageCluster(command.Lister): '--long', action='store_true', default=False, - help=_("List additional fields in output") + help=_("List additional fields in output"), ) return parser @@ -183,7 +185,7 @@ class SetBlockStorageCluster(command.Command): parser.add_argument( 'cluster', metavar='<cluster>', - help=_('Name of block storage cluster to update (name only)') + help=_('Name of block storage cluster to update (name only)'), ) parser.add_argument( '--binary', @@ -192,7 +194,7 @@ class SetBlockStorageCluster(command.Command): help=_( "Name of binary to filter by; defaults to 'cinder-volume' " "(optional)" - ) + ), ) enabled_group = parser.add_mutually_exclusive_group() enabled_group.add_argument( @@ -200,13 +202,13 @@ class SetBlockStorageCluster(command.Command): action='store_false', dest='disabled', default=None, - help=_('Enable cluster') + help=_('Enable cluster'), ) enabled_group.add_argument( '--disable', action='store_true', dest='disabled', - help=_('Disable cluster') + help=_('Disable cluster'), ) parser.add_argument( '--disable-reason', @@ -215,7 +217,7 @@ class SetBlockStorageCluster(command.Command): help=_( 'Reason for disabling the cluster ' '(should be used with --disable option)' - ) + ), ) return parser diff --git a/openstackclient/volume/v3/block_storage_log_level.py b/openstackclient/volume/v3/block_storage_log_level.py index d5286cdd..878cf408 100644 --- a/openstackclient/volume/v3/block_storage_log_level.py +++ b/openstackclient/volume/v3/block_storage_log_level.py @@ -34,8 +34,10 @@ class BlockStorageLogLevelList(command.Lister): "--host", metavar="<host>", default="", - help=_("List block storage service log level of specified host " - "(name only)") + help=_( + "List block storage service log level of specified host " + "(name only)" + ), ) parser.add_argument( "--service", @@ -47,15 +49,18 @@ class BlockStorageLogLevelList(command.Lister): 'cinder-api', 'cinder-volume', 'cinder-scheduler', - 'cinder-backup'), - help=_("List block storage service log level of the specified " - "service (name only)") + 'cinder-backup', + ), + help=_( + "List block storage service log level of the specified " + "service (name only)" + ), ) parser.add_argument( "--log-prefix", metavar="<log-prefix>", default="", - help="Prefix for the log, e.g. 'sqlalchemy'" + help="Prefix for the log, e.g. 'sqlalchemy'", ) return parser @@ -78,12 +83,19 @@ class BlockStorageLogLevelList(command.Lister): data = service_client.services.get_log_levels( binary=parsed_args.service, server=parsed_args.host, - prefix=parsed_args.log_prefix) + prefix=parsed_args.log_prefix, + ) - return (columns, - (utils.get_item_properties( - s, columns, - ) for s in data)) + return ( + columns, + ( + utils.get_item_properties( + s, + columns, + ) + for s in data + ), + ) class BlockStorageLogLevelSet(command.Command): @@ -99,14 +111,16 @@ class BlockStorageLogLevelSet(command.Command): metavar="<log-level>", choices=('INFO', 'WARNING', 'ERROR', 'DEBUG'), type=str.upper, - help=_("Desired log level.") + help=_("Desired log level."), ) parser.add_argument( "--host", metavar="<host>", default="", - help=_("Set block storage service log level of specified host " - "(name only)") + help=_( + "Set block storage service log level of specified host " + "(name only)" + ), ) parser.add_argument( "--service", @@ -118,15 +132,18 @@ class BlockStorageLogLevelSet(command.Command): 'cinder-api', 'cinder-volume', 'cinder-scheduler', - 'cinder-backup'), - help=_("Set block storage service log level of specified service " - "(name only)") + 'cinder-backup', + ), + help=_( + "Set block storage service log level of specified service " + "(name only)" + ), ) parser.add_argument( "--log-prefix", metavar="<log-prefix>", default="", - help="Prefix for the log, e.g. 'sqlalchemy'" + help="Prefix for the log, e.g. 'sqlalchemy'", ) return parser @@ -144,4 +161,5 @@ class BlockStorageLogLevelSet(command.Command): level=parsed_args.level, binary=parsed_args.service, server=parsed_args.host, - prefix=parsed_args.log_prefix) + prefix=parsed_args.log_prefix, + ) diff --git a/openstackclient/volume/v3/block_storage_manage.py b/openstackclient/volume/v3/block_storage_manage.py index 9015f44d..6810e5c8 100644 --- a/openstackclient/volume/v3/block_storage_manage.py +++ b/openstackclient/volume/v3/block_storage_manage.py @@ -38,50 +38,61 @@ class BlockStorageManageVolumes(command.Lister): "host", metavar="<host>", nargs='?', - help=_('Cinder host on which to list manageable volumes. ' - 'Takes the form: host@backend-name#pool') + help=_( + 'Cinder host on which to list manageable volumes. ' + 'Takes the form: host@backend-name#pool' + ), ) host_group.add_argument( "--cluster", metavar="<cluster>", - help=_('Cinder cluster on which to list manageable volumes. ' - 'Takes the form: cluster@backend-name#pool. ' - '(supported by --os-volume-api-version 3.17 or later)') + help=_( + 'Cinder cluster on which to list manageable volumes. ' + 'Takes the form: cluster@backend-name#pool. ' + '(supported by --os-volume-api-version 3.17 or later)' + ), ) parser.add_argument( '--detailed', metavar='<detailed>', default=True, - help=_('Returns detailed information (Default=True).') + help=_('Returns detailed information (Default=True).'), ) parser.add_argument( '--marker', metavar='<marker>', default=None, - help=_('Begin returning volumes that appear later in the volume ' - 'list than that represented by this reference. This ' - 'reference should be json like. Default=None.') + help=_( + 'Begin returning volumes that appear later in the volume ' + 'list than that represented by this reference. This ' + 'reference should be json like. Default=None.' + ), ) parser.add_argument( '--limit', metavar='<limit>', default=None, - help=_('Maximum number of volumes to return. Default=None.') + help=_('Maximum number of volumes to return. Default=None.'), ) parser.add_argument( '--offset', metavar='<offset>', default=None, - help=_('Number of volumes to skip after marker. Default=None.') + help=_('Number of volumes to skip after marker. Default=None.'), ) parser.add_argument( '--sort', metavar='<key>[:<direction>]', default=None, - help=(_('Comma-separated list of sort keys and directions in the ' + help=( + _( + 'Comma-separated list of sort keys and directions in the ' 'form of <key>[:<asc|desc>]. ' 'Valid keys: %s. ' - 'Default=None.') % ', '.join(SORT_MANAGEABLE_KEY_VALUES)) + 'Default=None.' + ) + % ', '.join(SORT_MANAGEABLE_KEY_VALUES) + ), ) return parser @@ -119,11 +130,13 @@ class BlockStorageManageVolumes(command.Lister): 'safe_to_manage', ] if detailed: - columns.extend([ - 'reason_not_safe', - 'cinder_id', - 'extra_info', - ]) + columns.extend( + [ + 'reason_not_safe', + 'cinder_id', + 'extra_info', + ] + ) data = volume_client.volumes.list_manageable( host=parsed_args.host, @@ -132,12 +145,19 @@ class BlockStorageManageVolumes(command.Lister): limit=parsed_args.limit, offset=parsed_args.offset, sort=parsed_args.sort, - cluster=cluster) + cluster=cluster, + ) - return (columns, - (utils.get_item_properties( - s, columns, - ) for s in data)) + return ( + columns, + ( + utils.get_item_properties( + s, + columns, + ) + for s in data + ), + ) class BlockStorageManageSnapshots(command.Lister): @@ -153,50 +173,61 @@ class BlockStorageManageSnapshots(command.Lister): "host", metavar="<host>", nargs='?', - help=_('Cinder host on which to list manageable snapshots. ' - 'Takes the form: host@backend-name#pool') + help=_( + 'Cinder host on which to list manageable snapshots. ' + 'Takes the form: host@backend-name#pool' + ), ) host_group.add_argument( "--cluster", metavar="<cluster>", - help=_('Cinder cluster on which to list manageable snapshots. ' - 'Takes the form: cluster@backend-name#pool. ' - '(supported by --os-volume-api-version 3.17 or later)') + help=_( + 'Cinder cluster on which to list manageable snapshots. ' + 'Takes the form: cluster@backend-name#pool. ' + '(supported by --os-volume-api-version 3.17 or later)' + ), ) parser.add_argument( '--detailed', metavar='<detailed>', default=True, - help=_('Returns detailed information (Default=True).') + help=_('Returns detailed information (Default=True).'), ) parser.add_argument( '--marker', metavar='<marker>', default=None, - help=_('Begin returning snapshots that appear later in the ' - 'snapshot list than that represented by this reference. ' - 'This reference should be json like. Default=None.') + help=_( + 'Begin returning snapshots that appear later in the ' + 'snapshot list than that represented by this reference. ' + 'This reference should be json like. Default=None.' + ), ) parser.add_argument( '--limit', metavar='<limit>', default=None, - help=_('Maximum number of snapshots to return. Default=None.') + help=_('Maximum number of snapshots to return. Default=None.'), ) parser.add_argument( '--offset', metavar='<offset>', default=None, - help=_('Number of snapshots to skip after marker. Default=None.') + help=_('Number of snapshots to skip after marker. Default=None.'), ) parser.add_argument( '--sort', metavar='<key>[:<direction>]', default=None, - help=(_('Comma-separated list of sort keys and directions in the ' + help=( + _( + 'Comma-separated list of sort keys and directions in the ' 'form of <key>[:<asc|desc>]. ' 'Valid keys: %s. ' - 'Default=None.') % ', '.join(SORT_MANAGEABLE_KEY_VALUES)) + 'Default=None.' + ) + % ', '.join(SORT_MANAGEABLE_KEY_VALUES) + ), ) return parser @@ -237,11 +268,13 @@ class BlockStorageManageSnapshots(command.Lister): 'source_reference', ] if detailed: - columns.extend([ - 'reason_not_safe', - 'cinder_id', - 'extra_info', - ]) + columns.extend( + [ + 'reason_not_safe', + 'cinder_id', + 'extra_info', + ] + ) data = volume_client.volume_snapshots.list_manageable( host=parsed_args.host, @@ -250,9 +283,16 @@ class BlockStorageManageSnapshots(command.Lister): limit=parsed_args.limit, offset=parsed_args.offset, sort=parsed_args.sort, - cluster=cluster) + cluster=cluster, + ) - return (columns, - (utils.get_item_properties( - s, columns, - ) for s in data)) + return ( + columns, + ( + utils.get_item_properties( + s, + columns, + ) + for s in data + ), + ) diff --git a/openstackclient/volume/v3/block_storage_resource_filter.py b/openstackclient/volume/v3/block_storage_resource_filter.py index 4bcacf90..4963fd4c 100644 --- a/openstackclient/volume/v3/block_storage_resource_filter.py +++ b/openstackclient/volume/v3/block_storage_resource_filter.py @@ -42,7 +42,7 @@ class ListBlockStorageResourceFilter(command.Lister): return ( column_headers, - (utils.get_item_properties(s, column_headers) for s in data) + (utils.get_item_properties(s, column_headers) for s in data), ) @@ -54,7 +54,7 @@ class ShowBlockStorageResourceFilter(command.ShowOne): parser.add_argument( 'resource', metavar='<resource>', - help=_('Resource to show filters for (name).') + help=_('Resource to show filters for (name).'), ) return parser diff --git a/openstackclient/volume/v3/volume.py b/openstackclient/volume/v3/volume.py index 4b159688..f02053f0 100644 --- a/openstackclient/volume/v3/volume.py +++ b/openstackclient/volume/v3/volume.py @@ -42,7 +42,6 @@ class VolumeSummary(command.ShowOne): return parser def take_action(self, parsed_args): - volume_client = self.app.client_manager.volume if volume_client.api_version < api_versions.APIVersion('3.12'): @@ -89,13 +88,14 @@ class VolumeRevertToSnapshot(command.Command): parser.add_argument( 'snapshot', metavar="<snapshot>", - help=_('Name or ID of the snapshot to restore. The snapshot must ' - 'be the most recent one known to cinder.'), + help=_( + 'Name or ID of the snapshot to restore. The snapshot must ' + 'be the most recent one known to cinder.' + ), ) return parser def take_action(self, parsed_args): - volume_client = self.app.client_manager.volume if volume_client.api_version < api_versions.APIVersion('3.40'): @@ -106,9 +106,10 @@ class VolumeRevertToSnapshot(command.Command): raise exceptions.CommandError(msg) snapshot = utils.find_resource( - volume_client.volume_snapshots, parsed_args.snapshot) - volume = utils.find_resource( - volume_client.volumes, snapshot.volume_id) + volume_client.volume_snapshots, parsed_args.snapshot + ) + volume = utils.find_resource(volume_client.volumes, snapshot.volume_id) volume_client.volumes.revert_to_snapshot( - volume=volume, snapshot=snapshot) + volume=volume, snapshot=snapshot + ) diff --git a/openstackclient/volume/v3/volume_attachment.py b/openstackclient/volume/v3/volume_attachment.py index 57a6da73..652fdf63 100644 --- a/openstackclient/volume/v3/volume_attachment.py +++ b/openstackclient/volume/v3/volume_attachment.py @@ -199,15 +199,17 @@ class CreateVolumeAttachment(command.ShowOne): 'mountpoint': parsed_args.mountpoint, } else: - if any({ - parsed_args.initiator, - parsed_args.ip, - parsed_args.platform, - parsed_args.host, - parsed_args.host, - parsed_args.multipath, - parsed_args.mountpoint, - }): + if any( + { + parsed_args.initiator, + parsed_args.ip, + parsed_args.platform, + parsed_args.host, + parsed_args.host, + parsed_args.multipath, + parsed_args.mountpoint, + } + ): msg = _( 'You must specify the --connect option for any of the ' 'connection-specific options such as --initiator to be ' @@ -225,7 +227,8 @@ class CreateVolumeAttachment(command.ShowOne): ) attachment = volume_client.attachments.create( - volume.id, connector, server.id, parsed_args.mode) + volume.id, connector, server.id, parsed_args.mode + ) return _format_attachment(attachment) @@ -346,7 +349,8 @@ class SetVolumeAttachment(command.ShowOne): } attachment = volume_client.attachments.update( - parsed_args.attachment, connector) + parsed_args.attachment, connector + ) return _format_attachment(attachment) @@ -469,7 +473,8 @@ class ListVolumeAttachment(command.Lister): attachments = volume_client.attachments.list( search_opts=search_opts, marker=parsed_args.marker, - limit=parsed_args.limit) + limit=parsed_args.limit, + ) column_headers = ( 'ID', @@ -486,10 +491,7 @@ class ListVolumeAttachment(command.Lister): return ( column_headers, - ( - utils.get_item_properties(a, columns) - for a in attachments - ), + (utils.get_item_properties(a, columns) for a in attachments), ) diff --git a/openstackclient/volume/v3/volume_group.py b/openstackclient/volume/v3/volume_group.py index 242ffcd4..ba9368e0 100644 --- a/openstackclient/volume/v3/volume_group.py +++ b/openstackclient/volume/v3/volume_group.py @@ -155,7 +155,7 @@ class CreateVolumeGroup(command.ShowOne): parser.add_argument( '--description', metavar='<description>', - help=_('Description of a volume group.') + help=_('Description of a volume group.'), ) parser.add_argument( '--availability-zone', @@ -178,8 +178,10 @@ class CreateVolumeGroup(command.ShowOne): ) self.log.warning(msg) - volume_group_type = parsed_args.volume_group_type or \ - parsed_args.volume_group_type_legacy + volume_group_type = ( + parsed_args.volume_group_type + or parsed_args.volume_group_type_legacy + ) volume_types = parsed_args.volume_types[:] volume_types.extend(parsed_args.volume_types_legacy) @@ -229,8 +231,10 @@ class CreateVolumeGroup(command.ShowOne): "[--source-group|--group-snapshot]' command" ) raise exceptions.CommandError(msg) - if (parsed_args.source_group is None and - parsed_args.group_snapshot is None): + if ( + parsed_args.source_group is None + and parsed_args.group_snapshot is None + ): msg = _( "Either --source-group <source_group> or " "'--group-snapshot <group_snapshot>' needs to be " @@ -239,24 +243,28 @@ class CreateVolumeGroup(command.ShowOne): ) raise exceptions.CommandError(msg) if parsed_args.availability_zone: - msg = _("'--availability-zone' option will not work " - "if creating group from source.") + msg = _( + "'--availability-zone' option will not work " + "if creating group from source." + ) self.log.warning(msg) source_group = None if parsed_args.source_group: - source_group = utils.find_resource(volume_client.groups, - parsed_args.source_group) + source_group = utils.find_resource( + volume_client.groups, parsed_args.source_group + ) group_snapshot = None if parsed_args.group_snapshot: group_snapshot = utils.find_resource( - volume_client.group_snapshots, - parsed_args.group_snapshot) + volume_client.group_snapshots, parsed_args.group_snapshot + ) group = volume_client.groups.create_from_src( group_snapshot.id if group_snapshot else None, source_group.id if source_group else None, parsed_args.name, - parsed_args.description) + parsed_args.description, + ) group = volume_client.groups.get(group.id) return _format_group(group) @@ -281,7 +289,7 @@ class DeleteVolumeGroup(command.Command): help=_( 'Delete the volume group even if it contains volumes. ' 'This will delete any remaining volumes in the group.', - ) + ), ) return parser @@ -300,8 +308,7 @@ class DeleteVolumeGroup(command.Command): parsed_args.group, ) - volume_client.groups.delete( - group.id, delete_volumes=parsed_args.force) + volume_client.groups.delete(group.id, delete_volumes=parsed_args.force) class SetVolumeGroup(command.ShowOne): @@ -436,8 +443,7 @@ class ListVolumeGroup(command.Lister): 'all_tenants': parsed_args.all_projects, } - groups = volume_client.groups.list( - search_opts=search_opts) + groups = volume_client.groups.list(search_opts=search_opts) column_headers = ( 'ID', @@ -452,10 +458,7 @@ class ListVolumeGroup(command.Lister): return ( column_headers, - ( - utils.get_item_properties(a, columns) - for a in groups - ), + (utils.get_item_properties(a, columns) for a in groups), ) @@ -551,8 +554,9 @@ class ShowVolumeGroup(command.ShowOne): group = volume_client.groups.show(group.id, **kwargs) if parsed_args.show_replication_targets: - replication_targets = \ + replication_targets = ( volume_client.groups.list_replication_targets(group.id) + ) group.replication_targets = replication_targets @@ -580,7 +584,7 @@ class FailoverVolumeGroup(command.Command): default=False, help=_( 'Allow group with attached volumes to be failed over.', - ) + ), ) parser.add_argument( '--disallow-attached-volume', @@ -589,7 +593,7 @@ class FailoverVolumeGroup(command.Command): default=False, help=_( 'Disallow group with attached volumes to be failed over.', - ) + ), ) parser.add_argument( '--secondary-backend-id', diff --git a/openstackclient/volume/v3/volume_group_snapshot.py b/openstackclient/volume/v3/volume_group_snapshot.py index 229cbd71..bb7d46f5 100644 --- a/openstackclient/volume/v3/volume_group_snapshot.py +++ b/openstackclient/volume/v3/volume_group_snapshot.py @@ -70,7 +70,7 @@ class CreateVolumeGroupSnapshot(command.ShowOne): parser.add_argument( '--description', metavar='<description>', - help=_('Description of a volume group snapshot.') + help=_('Description of a volume group snapshot.'), ) return parser @@ -90,9 +90,8 @@ class CreateVolumeGroupSnapshot(command.ShowOne): ) snapshot = volume_client.group_snapshots.create( - volume_group.id, - parsed_args.name, - parsed_args.description) + volume_group.id, parsed_args.name, parsed_args.description + ) return _format_group_snapshot(snapshot) @@ -175,8 +174,7 @@ class ListVolumeGroupSnapshot(command.Lister): 'all_tenants': parsed_args.all_projects, } - groups = volume_client.group_snapshots.list( - search_opts=search_opts) + groups = volume_client.group_snapshots.list(search_opts=search_opts) column_headers = ( 'ID', @@ -191,10 +189,7 @@ class ListVolumeGroupSnapshot(command.Lister): return ( column_headers, - ( - utils.get_item_properties(a, columns) - for a in groups - ), + (utils.get_item_properties(a, columns) for a in groups), ) diff --git a/openstackclient/volume/v3/volume_group_type.py b/openstackclient/volume/v3/volume_group_type.py index 860fa544..f1ef6174 100644 --- a/openstackclient/volume/v3/volume_group_type.py +++ b/openstackclient/volume/v3/volume_group_type.py @@ -70,7 +70,7 @@ class CreateVolumeGroupType(command.ShowOne): parser.add_argument( '--description', metavar='<description>', - help=_('Description of the volume group type.') + help=_('Description of the volume group type.'), ) type_group = parser.add_mutually_exclusive_group() type_group.add_argument( @@ -86,7 +86,7 @@ class CreateVolumeGroupType(command.ShowOne): '--private', dest='is_public', action='store_false', - help=_('Volume group type is not available to other projects') + help=_('Volume group type is not available to other projects'), ) return parser @@ -101,9 +101,8 @@ class CreateVolumeGroupType(command.ShowOne): raise exceptions.CommandError(msg) group_type = volume_client.group_types.create( - parsed_args.name, - parsed_args.description, - parsed_args.is_public) + parsed_args.name, parsed_args.description, parsed_args.is_public + ) return _format_group_type(group_type) @@ -176,7 +175,7 @@ class SetVolumeGroupType(command.ShowOne): '--private', dest='is_public', action='store_false', - help=_('Make volume group type unavailable to other projects.') + help=_('Make volume group type unavailable to other projects.'), ) parser.add_argument( '--no-property', @@ -230,7 +229,8 @@ class SetVolumeGroupType(command.ShowOne): if kwargs: try: group_type = volume_client.group_types.update( - group_type.id, **kwargs) + group_type.id, **kwargs + ) except Exception as e: LOG.error(_("Failed to update group type: %s"), e) errors += 1 @@ -251,9 +251,7 @@ class SetVolumeGroupType(command.ShowOne): errors += 1 if errors > 0: - msg = _( - "Command Failed: One or more of the operations failed" - ) + msg = _("Command Failed: One or more of the operations failed") raise exceptions.CommandError() return _format_group_type(group_type) @@ -370,10 +368,7 @@ class ListVolumeGroupType(command.Lister): return ( column_headers, - ( - utils.get_item_properties(a, columns) - for a in group_types - ), + (utils.get_item_properties(a, columns) for a in group_types), ) diff --git a/openstackclient/volume/v3/volume_message.py b/openstackclient/volume/v3/volume_message.py index 4fe5ae92..b76ebe32 100644 --- a/openstackclient/volume/v3/volume_message.py +++ b/openstackclient/volume/v3/volume_message.py @@ -34,7 +34,7 @@ class DeleteMessage(command.Command): 'message_ids', metavar='<message-id>', nargs='+', - help=_('Message(s) to delete (ID)') + help=_('Message(s) to delete (ID)'), ) return parser @@ -60,7 +60,8 @@ class DeleteMessage(command.Command): if errors > 0: total = len(parsed_args.message_ids) msg = _('Failed to delete %(errors)s of %(total)s messages.') % { - 'errors': errors, 'total': total, + 'errors': errors, + 'total': total, } raise exceptions.CommandError(msg) @@ -121,7 +122,8 @@ class ListMessages(command.Lister): project_id = identity_common.find_project( identity_client, parsed_args.project, - parsed_args.project_domain).id + parsed_args.project_domain, + ).id search_opts = { 'project_id': project_id, @@ -129,11 +131,12 @@ class ListMessages(command.Lister): data = volume_client.messages.list( search_opts=search_opts, marker=parsed_args.marker, - limit=parsed_args.limit) + limit=parsed_args.limit, + ) return ( column_headers, - (utils.get_item_properties(s, column_headers) for s in data) + (utils.get_item_properties(s, column_headers) for s in data), ) @@ -145,7 +148,7 @@ class ShowMessage(command.ShowOne): parser.add_argument( 'message_id', metavar='<message-id>', - help=_('Message to show (ID).') + help=_('Message to show (ID).'), ) return parser |
