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/v1 | |
| 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/v1')
| -rw-r--r-- | openstackclient/volume/v1/qos_specs.py | 138 | ||||
| -rw-r--r-- | openstackclient/volume/v1/service.py | 66 | ||||
| -rw-r--r-- | openstackclient/volume/v1/volume.py | 220 | ||||
| -rw-r--r-- | openstackclient/volume/v1/volume_backup.py | 100 | ||||
| -rw-r--r-- | openstackclient/volume/v1/volume_snapshot.py | 184 | ||||
| -rw-r--r-- | openstackclient/volume/v1/volume_transfer_request.py | 33 | ||||
| -rw-r--r-- | openstackclient/volume/v1/volume_type.py | 268 |
7 files changed, 647 insertions, 362 deletions
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") + ) |
