diff options
| author | Stephen Finucane <sfinucan@redhat.com> | 2023-05-08 11:34:37 +0100 |
|---|---|---|
| committer | Stephen Finucane <sfinucan@redhat.com> | 2023-05-10 10:51:30 +0100 |
| commit | 7ca43885c26d9dd7903e7015c0a31f3486730eea (patch) | |
| tree | fe4bb785229fe2d904d523a147559a83e6e32411 /openstackclient/image | |
| parent | 329296cedd0a64e9f65b080cef749b65256db85b (diff) | |
| download | python-openstackclient-7ca43885c26d9dd7903e7015c0a31f3486730eea.tar.gz | |
Blacken openstackclient.image
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: I6420ec6fd550903b03083b9b1f8391511913c86f
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/image')
| -rw-r--r-- | openstackclient/image/client.py | 5 | ||||
| -rw-r--r-- | openstackclient/image/v1/image.py | 211 | ||||
| -rw-r--r-- | openstackclient/image/v2/image.py | 12 | ||||
| -rw-r--r-- | openstackclient/image/v2/metadef_namespaces.py | 46 |
4 files changed, 174 insertions, 100 deletions
diff --git a/openstackclient/image/client.py b/openstackclient/image/client.py index 9a0d7bac..a3da099a 100644 --- a/openstackclient/image/client.py +++ b/openstackclient/image/client.py @@ -32,7 +32,6 @@ API_VERSIONS = { def make_client(instance): - LOG.debug( 'Image client initialized using OpenStack SDK: %s', instance.sdk_connection.image, @@ -46,7 +45,7 @@ def build_option_parser(parser): '--os-image-api-version', metavar='<image-api-version>', default=utils.env('OS_IMAGE_API_VERSION'), - help=_('Image API version, default=%s (Env: OS_IMAGE_API_VERSION)') % - DEFAULT_API_VERSION, + help=_('Image API version, default=%s (Env: OS_IMAGE_API_VERSION)') + % DEFAULT_API_VERSION, ) return parser diff --git a/openstackclient/image/v1/image.py b/openstackclient/image/v1/image.py index 43ccf5d2..9edec48d 100644 --- a/openstackclient/image/v1/image.py +++ b/openstackclient/image/v1/image.py @@ -39,29 +39,42 @@ else: CONTAINER_CHOICES = ["ami", "ari", "aki", "bare", "docker", "ova", "ovf"] DEFAULT_CONTAINER_FORMAT = 'bare' DEFAULT_DISK_FORMAT = 'raw' -DISK_CHOICES = ["ami", "ari", "aki", "vhd", "vmdk", "raw", "qcow2", "vhdx", - "vdi", "iso", "ploop"] +DISK_CHOICES = [ + "ami", + "ari", + "aki", + "vhd", + "vmdk", + "raw", + "qcow2", + "vhdx", + "vdi", + "iso", + "ploop", +] LOG = logging.getLogger(__name__) def _get_columns(item): - column_map = { - 'is_protected': 'protected', - 'owner_id': 'owner' - } + column_map = {'is_protected': 'protected', 'owner_id': 'owner'} hidden_columns = [ - 'location', 'checksum', 'copy_from', 'created_at', 'status', + 'location', + 'checksum', + 'copy_from', + 'created_at', + 'status', 'updated_at', ] return utils.get_osc_show_columns_for_sdk_resource( - item.to_dict(), column_map, hidden_columns, + item.to_dict(), + column_map, + hidden_columns, ) -_formatters = { -} +_formatters = {} class HumanReadableSizeColumn(cliff_columns.FormattableColumn): @@ -117,25 +130,36 @@ class CreateImage(command.ShowOne): default=DEFAULT_CONTAINER_FORMAT, metavar="<container-format>", choices=CONTAINER_CHOICES, - help=(_("Image container format. " + help=( + _( + "Image container format. " "The supported options are: %(option_list)s. " - "The default format is: %(default_opt)s") % - {'option_list': ', '.join(CONTAINER_CHOICES), - 'default_opt': DEFAULT_CONTAINER_FORMAT}) + "The default format is: %(default_opt)s" + ) + % { + 'option_list': ', '.join(CONTAINER_CHOICES), + 'default_opt': DEFAULT_CONTAINER_FORMAT, + } + ), ) parser.add_argument( "--disk-format", default=DEFAULT_DISK_FORMAT, metavar="<disk-format>", choices=DISK_CHOICES, - help=_("Image disk format. The supported options are: %s. " - "The default format is: raw") % ', '.join(DISK_CHOICES) + help=_( + "Image disk format. The supported options are: %s. " + "The default format is: raw" + ) + % ', '.join(DISK_CHOICES), ) parser.add_argument( "--size", metavar="<size>", - help=_("Image size, in bytes (only used with --location and" - " --copy-from)"), + help=_( + "Image size, in bytes (only used with --location and" + " --copy-from)" + ), ) parser.add_argument( "--min-disk", @@ -175,8 +199,10 @@ class CreateImage(command.ShowOne): dest='force', action='store_true', default=False, - help=_("Force image creation if volume is in use " - "(only meaningful with --volume)"), + help=_( + "Force image creation if volume is in use " + "(only meaningful with --volume)" + ), ) parser.add_argument( "--checksum", @@ -210,8 +236,10 @@ class CreateImage(command.ShowOne): dest="properties", metavar="<key=value>", action=parseractions.KeyValueAction, - help=_("Set a property on this image " - "(repeat option to set multiple properties)"), + help=_( + "Set a property on this image " + "(repeat option to set multiple properties)" + ), ) parser.add_argument( "--project", @@ -226,10 +254,23 @@ class CreateImage(command.ShowOne): # Build an attribute dict from the parsed args, only include # attributes that were actually set on the command line kwargs = {} - copy_attrs = ('name', 'id', 'store', 'container_format', - 'disk_format', 'owner', 'size', 'min_disk', 'min_ram', - 'location', 'copy_from', 'volume', 'force', - 'checksum', 'properties') + copy_attrs = ( + 'name', + 'id', + 'store', + 'container_format', + 'disk_format', + 'owner', + 'size', + 'min_disk', + 'min_ram', + 'location', + 'copy_from', + 'volume', + 'force', + 'checksum', + 'properties', + ) for attr in copy_attrs: if attr in parsed_args: val = getattr(parsed_args, attr, None) @@ -295,20 +336,25 @@ class CreateImage(command.ShowOne): image = image_client.create_image(**kwargs) finally: # Clean up open files - make sure data isn't a string - if ('data' in kwargs and hasattr(kwargs['data'], 'close') and - kwargs['data'] != sys.stdin): + if ( + 'data' in kwargs + and hasattr(kwargs['data'], 'close') + and kwargs['data'] != sys.stdin + ): kwargs['data'].close() if image: display_columns, columns = _get_columns(image) _formatters['properties'] = format_columns.DictColumn - data = utils.get_item_properties(image, columns, - formatters=_formatters) + data = utils.get_item_properties( + image, columns, formatters=_formatters + ) return (display_columns, data) elif info: info.update(image._info) info['properties'] = format_columns.DictColumn( - info.get('properties', {})) + info.get('properties', {}) + ) return zip(*sorted(info.items())) @@ -384,9 +430,11 @@ class ListImage(command.Lister): '--sort', metavar="<key>[:<direction>]", default='name:asc', - help=_("Sort output by selected keys and directions(asc or desc) " - "(default: name:asc), multiple keys and directions can be " - "specified separated by comma"), + help=_( + "Sort output by selected keys and directions(asc or desc) " + "(default: name:asc), multiple keys and directions can be " + "specified separated by comma" + ), ) return parser @@ -447,14 +495,17 @@ class ListImage(command.Lister): return ( column_headers, - (utils.get_item_properties( - s, - columns, - formatters={ - 'is_public': VisibilityColumn, - 'properties': format_columns.DictColumn, - }, - ) for s in data) + ( + utils.get_item_properties( + s, + columns, + formatters={ + 'is_public': VisibilityColumn, + 'properties': format_columns.DictColumn, + }, + ) + for s in data + ), ) @@ -517,21 +568,21 @@ class SetImage(command.Command): "--container-format", metavar="<container-format>", choices=CONTAINER_CHOICES, - help=_("Image container format. The supported options are: %s") % - ', '.join(CONTAINER_CHOICES) + help=_("Image container format. The supported options are: %s") + % ', '.join(CONTAINER_CHOICES), ) parser.add_argument( "--disk-format", metavar="<disk-format>", choices=DISK_CHOICES, - help=_("Image disk format. The supported options are: %s.") % - ', '.join(DISK_CHOICES) + help=_("Image disk format. The supported options are: %s.") + % ', '.join(DISK_CHOICES), ) parser.add_argument( "--size", metavar="<size>", type=int, - help=_("Size of image data (in bytes)") + help=_("Size of image data (in bytes)"), ) protected_group = parser.add_mutually_exclusive_group() protected_group.add_argument( @@ -560,8 +611,10 @@ class SetImage(command.Command): dest="properties", metavar="<key=value>", action=parseractions.KeyValueAction, - help=_("Set a property on this image " - "(repeat option to set multiple properties)"), + help=_( + "Set a property on this image " + "(repeat option to set multiple properties)" + ), ) parser.add_argument( "--store", @@ -593,8 +646,10 @@ class SetImage(command.Command): dest='force', action='store_true', default=False, - help=_("Force image change if volume is in use " - "(only meaningful with --volume)"), + help=_( + "Force image change if volume is in use " + "(only meaningful with --volume)" + ), ) parser.add_argument( "--stdin", @@ -619,9 +674,21 @@ class SetImage(command.Command): image_client = self.app.client_manager.image kwargs = {} - copy_attrs = ('name', 'owner', 'min_disk', 'min_ram', 'properties', - 'container_format', 'disk_format', 'size', 'store', - 'location', 'copy_from', 'volume', 'checksum') + copy_attrs = ( + 'name', + 'owner', + 'min_disk', + 'min_ram', + 'properties', + 'container_format', + 'disk_format', + 'size', + 'store', + 'location', + 'copy_from', + 'volume', + 'checksum', + ) for attr in copy_attrs: if attr in parsed_args: val = getattr(parsed_args, attr, None) @@ -665,12 +732,16 @@ class SetImage(command.Command): source_volume.id, parsed_args.force, parsed_args.image, - (parsed_args.container_format - if parsed_args.container_format - else image.container_format), - (parsed_args.disk_format - if parsed_args.disk_format - else image.disk_format), + ( + parsed_args.container_format + if parsed_args.container_format + else image.container_format + ), + ( + parsed_args.disk_format + if parsed_args.disk_format + else image.disk_format + ), ) elif parsed_args.file: # Send an open file handle to glanceclient so it will @@ -687,8 +758,12 @@ class SetImage(command.Command): else: kwargs["data"] = sys.stdin else: - LOG.warning(_('Use --stdin to enable read image ' - 'data from standard input')) + LOG.warning( + _( + 'Use --stdin to enable read image ' + 'data from standard input' + ) + ) if image.properties and parsed_args.properties: image.properties.update(kwargs['properties']) @@ -697,8 +772,11 @@ class SetImage(command.Command): image = image_client.update_image(image.id, **kwargs) finally: # Clean up open files - make sure data isn't a string - if ('data' in kwargs and hasattr(kwargs['data'], 'close') and - kwargs['data'] != sys.stdin): + if ( + 'data' in kwargs + and hasattr(kwargs['data'], 'close') + and kwargs['data'] != sys.stdin + ): kwargs['data'].close() @@ -728,6 +806,7 @@ class ShowImage(command.ShowOne): _formatters['size'] = HumanReadableSizeColumn display_columns, columns = _get_columns(image) _formatters['properties'] = format_columns.DictColumn - data = utils.get_item_properties(image, columns, - formatters=_formatters) + data = utils.get_item_properties( + image, columns, formatters=_formatters + ) return (display_columns, data) diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index da26e918..8a0066ca 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -506,8 +506,8 @@ class CreateImage(command.ShowOne): raise exceptions.CommandError(msg) if ( - len(parsed_args.sign_key_path) < 1 or - len(parsed_args.sign_cert_id) < 1 + len(parsed_args.sign_key_path) < 1 + or len(parsed_args.sign_cert_id) < 1 ): msg = _( "'sign-key-path' and 'sign-cert-id' must both be " @@ -596,10 +596,7 @@ class CreateImage(command.ShowOne): ) kwargs = {} if volume_client.api_version < api_versions.APIVersion('3.1'): - if ( - parsed_args.visibility or - parsed_args.is_protected is not None - ): + if parsed_args.visibility or parsed_args.is_protected is not None: msg = _( '--os-volume-api-version 3.1 or greater is required ' 'to support the --public, --private, --community, ' @@ -618,7 +615,7 @@ class CreateImage(command.ShowOne): parsed_args.name, parsed_args.container_format, parsed_args.disk_format, - **kwargs + **kwargs, ) info = body['os-volume_upload_image'] try: @@ -659,7 +656,6 @@ class DeleteImage(command.Command): return parser def take_action(self, parsed_args): - del_result = 0 image_client = self.app.client_manager.image for image in parsed_args.images: diff --git a/openstackclient/image/v2/metadef_namespaces.py b/openstackclient/image/v2/metadef_namespaces.py index f09f2002..eaaae674 100644 --- a/openstackclient/image/v2/metadef_namespaces.py +++ b/openstackclient/image/v2/metadef_namespaces.py @@ -52,8 +52,9 @@ def _format_namespace(namespace): if key in fields_to_show: info[key] = namespace.get(key) elif key == "resource_type_associations": - info[key] = [resource_type['name'] - for resource_type in namespace.get(key)] + info[key] = [ + resource_type['name'] for resource_type in namespace.get(key) + ] elif key == 'properties': info['properties'] = list(namespace.get(key).keys()) @@ -114,11 +115,7 @@ class CreateMetadefNameSpace(command.ShowOne): def take_action(self, parsed_args): image_client = self.app.client_manager.image - filter_keys = [ - 'namespace', - 'display_name', - 'description' - ] + filter_keys = ['namespace', 'display_name', 'description'] kwargs = {} for key in filter_keys: @@ -160,15 +157,19 @@ class DeleteMetadefNameSpace(command.Command): image_client.delete_metadef_namespace(namespace.id) except Exception as e: result += 1 - LOG.error(_("Failed to delete namespace with name or " - "ID '%(namespace)s': %(e)s"), - {'namespace': i, 'e': e} - ) + LOG.error( + _( + "Failed to delete namespace with name or " + "ID '%(namespace)s': %(e)s" + ), + {'namespace': i, 'e': e}, + ) if result > 0: total = len(parsed_args.namespace_name) - msg = (_("%(result)s of %(total)s namespace failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s namespace failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -203,11 +204,14 @@ class ListMetadefNameSpaces(command.Lister): column_headers = columns return ( column_headers, - (utils.get_item_properties( - s, - columns, - formatters=_formatters, - ) for s in data) + ( + utils.get_item_properties( + s, + columns, + formatters=_formatters, + ) + for s in data + ), ) @@ -268,11 +272,7 @@ class SetMetadefNameSpace(command.Command): namespace = parsed_args.namespace - filter_keys = [ - 'namespace', - 'display_name', - 'description' - ] + filter_keys = ['namespace', 'display_name', 'description'] kwargs = {} for key in filter_keys: |
