diff options
Diffstat (limited to 'openstackclient/common')
-rw-r--r-- | openstackclient/common/availability_zone.py | 51 | ||||
-rw-r--r-- | openstackclient/common/clientmanager.py | 34 | ||||
-rw-r--r-- | openstackclient/common/configuration.py | 3 | ||||
-rw-r--r-- | openstackclient/common/extension.py | 41 | ||||
-rw-r--r-- | openstackclient/common/limits.py | 64 | ||||
-rw-r--r-- | openstackclient/common/module.py | 19 | ||||
-rw-r--r-- | openstackclient/common/progressbar.py | 8 | ||||
-rw-r--r-- | openstackclient/common/project_cleanup.py | 52 | ||||
-rw-r--r-- | openstackclient/common/project_purge.py | 42 | ||||
-rw-r--r-- | openstackclient/common/quota.py | 6 | ||||
-rw-r--r-- | openstackclient/common/versions.py | 42 |
11 files changed, 220 insertions, 142 deletions
diff --git a/openstackclient/common/availability_zone.py b/openstackclient/common/availability_zone.py index 3b2fa848..935f90c6 100644 --- a/openstackclient/common/availability_zone.py +++ b/openstackclient/common/availability_zone.py @@ -28,8 +28,9 @@ LOG = logging.getLogger(__name__) def _xform_common_availability_zone(az, zone_info): if hasattr(az, 'zoneState'): - zone_info['zone_status'] = ('available' if az.zoneState['available'] - else 'not available') + zone_info['zone_status'] = ( + 'available' if az.zoneState['available'] else 'not available' + ) if hasattr(az, 'zoneName'): zone_info['zone_name'] = az.zoneName @@ -56,7 +57,8 @@ def _xform_compute_availability_zone(az, include_extra): info['service_status'] = '%s %s %s' % ( 'enabled' if state['active'] else 'disabled', ':-)' if state['available'] else 'XXX', - state['updated_at']) + state['updated_at'], + ) result.append(info) else: zone_info['host_name'] = '' @@ -141,8 +143,10 @@ class ListAvailabilityZone(command.Lister): except Exception as e: LOG.debug('Volume availability zone exception: %s', e) if parsed_args.volume: - message = _("Availability zones list not supported by " - "Block Storage API") + message = _( + "Availability zones list not supported by " + "Block Storage API" + ) LOG.warning(message) result = [] @@ -154,13 +158,15 @@ class ListAvailabilityZone(command.Lister): network_client = self.app.client_manager.network try: # Verify that the extension exists. - network_client.find_extension('Availability Zone', - ignore_missing=False) + network_client.find_extension( + 'Availability Zone', ignore_missing=False + ) except Exception as e: LOG.debug('Network availability zone exception: ', e) if parsed_args.network: - message = _("Availability zones list not supported by " - "Network API") + message = _( + "Availability zones list not supported by " "Network API" + ) LOG.warning(message) return [] @@ -170,17 +176,24 @@ class ListAvailabilityZone(command.Lister): return result def take_action(self, parsed_args): - if parsed_args.long: - columns = ('Zone Name', 'Zone Status', 'Zone Resource', - 'Host Name', 'Service Name', 'Service Status') + columns = ( + 'Zone Name', + 'Zone Status', + 'Zone Resource', + 'Host Name', + 'Service Name', + 'Service Status', + ) else: columns = ('Zone Name', 'Zone Status') # Show everything by default. - show_all = (not parsed_args.compute and - not parsed_args.volume and - not parsed_args.network) + show_all = ( + not parsed_args.compute + and not parsed_args.volume + and not parsed_args.network + ) result = [] if parsed_args.compute or show_all: @@ -190,7 +203,7 @@ class ListAvailabilityZone(command.Lister): if parsed_args.network or show_all: result += self._get_network_availability_zones(parsed_args) - return (columns, - (utils.get_dict_properties( - s, columns - ) for s in result)) + return ( + columns, + (utils.get_dict_properties(s, columns) for s in result), + ) diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py index 1ed6aa24..35c79247 100644 --- a/openstackclient/common/clientmanager.py +++ b/openstackclient/common/clientmanager.py @@ -77,18 +77,20 @@ class ClientManager(clientmanager.ClientManager): # CloudConfig.__init__() and we'll die if it was not # passed. if ( - self._auth_required and - self._cli_options._openstack_config is not None + self._auth_required + and self._cli_options._openstack_config is not None ): - self._cli_options._openstack_config._pw_callback = \ + self._cli_options._openstack_config._pw_callback = ( shell.prompt_for_password + ) try: # We might already get auth from SDK caching if not self._cli_options._auth: - self._cli_options._auth = \ + self._cli_options._auth = ( self._cli_options._openstack_config.load_auth_plugin( self._cli_options.config, ) + ) except TypeError as e: self._fallback_load_auth_plugin(e) @@ -101,14 +103,14 @@ class ClientManager(clientmanager.ClientManager): # We know it looks ugly, but it's necessary. if self._cli_options.config['auth']['token'] == 'x': # restore original auth_type - self._cli_options.config['auth_type'] = \ - self._original_auth_type + self._cli_options.config['auth_type'] = self._original_auth_type del self._cli_options.config['auth']['token'] del self._cli_options.config['auth']['endpoint'] - self._cli_options._auth = \ + self._cli_options._auth = ( self._cli_options._openstack_config.load_auth_plugin( self._cli_options.config, ) + ) else: raise e @@ -132,8 +134,10 @@ class ClientManager(clientmanager.ClientManager): # name so we need to figure out which version to look # for when calling is_service_available() volume_version = volume_client.api_version.ver_major - if self.is_service_available( - "volumev%s" % volume_version) is not False: + if ( + self.is_service_available("volumev%s" % volume_version) + is not False + ): return True elif self.is_service_available('volume') is not False: return True @@ -143,6 +147,7 @@ class ClientManager(clientmanager.ClientManager): # Plugin Support + def get_plugin_modules(group): """Find plugin entry points""" mod_list = [] @@ -165,7 +170,8 @@ def get_plugin_modules(group): module = importlib.import_module(module_name) except Exception as err: sys.stderr.write( - "WARNING: Failed to import plugin %s: %s.\n" % (ep.name, err)) + "WARNING: Failed to import plugin %s: %s.\n" % (ep.name, err) + ) continue mod_list.append(module) @@ -198,6 +204,8 @@ PLUGIN_MODULES = get_plugin_modules( 'openstack.cli.base', ) # Append list of external plugin modules -PLUGIN_MODULES.extend(get_plugin_modules( - 'openstack.cli.extension', -)) +PLUGIN_MODULES.extend( + get_plugin_modules( + 'openstack.cli.extension', + ) +) diff --git a/openstackclient/common/configuration.py b/openstackclient/common/configuration.py index cb415505..4aa690a5 100644 --- a/openstackclient/common/configuration.py +++ b/openstackclient/common/configuration.py @@ -53,7 +53,8 @@ class ShowConfiguration(command.ShowOne): if getattr(self.app.client_manager, "auth_plugin_name", None): auth_plg_name = self.app.client_manager.auth_plugin_name secret_opts = [ - o.dest for o in base.get_plugin_options(auth_plg_name) + o.dest + for o in base.get_plugin_options(auth_plg_name) if o.secret ] diff --git a/openstackclient/common/extension.py b/openstackclient/common/extension.py index 1ed2012c..a1b17d33 100644 --- a/openstackclient/common/extension.py +++ b/openstackclient/common/extension.py @@ -65,8 +65,14 @@ class ListExtension(command.Lister): def take_action(self, parsed_args): if parsed_args.long: - columns = ('Name', 'Alias', 'Description', - 'Namespace', 'Updated', 'Links') + columns = ( + 'Name', + 'Alias', + 'Description', + 'Namespace', + 'Updated', + 'Links', + ) else: columns = ('Name', 'Alias', 'Description') @@ -75,10 +81,12 @@ class ListExtension(command.Lister): # by default we want to show everything, unless the # user specifies one or more of the APIs to show # for now, only identity and compute are supported. - show_all = (not parsed_args.identity and - not parsed_args.compute and - not parsed_args.volume and - not parsed_args.network) + show_all = ( + not parsed_args.identity + and not parsed_args.compute + and not parsed_args.volume + and not parsed_args.network + ) if parsed_args.identity or show_all: identity_client = self.app.client_manager.identity @@ -101,8 +109,9 @@ class ListExtension(command.Lister): try: data += volume_client.list_extensions.show_all() except Exception: - message = _("Extensions list not supported by " - "Block Storage API") + message = _( + "Extensions list not supported by " "Block Storage API" + ) LOG.warning(message) if parsed_args.network or show_all: @@ -110,15 +119,17 @@ class ListExtension(command.Lister): try: data += network_client.extensions() except Exception: - message = _("Failed to retrieve extensions list " - "from Network API") + message = _( + "Failed to retrieve extensions list " "from Network API" + ) LOG.warning(message) extension_tuples = ( utils.get_item_properties( s, columns, - ) for s in data + ) + for s in data ) return (columns, extension_tuples) @@ -132,9 +143,11 @@ class ShowExtension(command.ShowOne): parser.add_argument( 'extension', metavar='<extension>', - help=_('Extension to display. ' - 'Currently, only network extensions are supported. ' - '(Name or Alias)'), + help=_( + 'Extension to display. ' + 'Currently, only network extensions are supported. ' + '(Name or Alias)' + ), ) return parser diff --git a/openstackclient/common/limits.py b/openstackclient/common/limits.py index 19db35d7..7353b350 100644 --- a/openstackclient/common/limits.py +++ b/openstackclient/common/limits.py @@ -54,19 +54,22 @@ class ShowLimits(command.Lister): parser.add_argument( '--project', metavar='<project>', - help=_('Show limits for a specific project (name or ID)' - ' [only valid with --absolute]'), + help=_( + 'Show limits for a specific project (name or ID)' + ' [only valid with --absolute]' + ), ) parser.add_argument( '--domain', metavar='<domain>', - help=_('Domain the project belongs to (name or ID)' - ' [only valid with --absolute]'), + help=_( + 'Domain the project belongs to (name or ID)' + ' [only valid with --absolute]' + ), ) return parser def take_action(self, parsed_args): - compute_client = self.app.client_manager.compute volume_client = self.app.client_manager.volume @@ -74,21 +77,26 @@ class ShowLimits(command.Lister): if parsed_args.project is not None: identity_client = self.app.client_manager.identity if parsed_args.domain is not None: - domain = identity_common.find_domain(identity_client, - parsed_args.domain) - project_id = utils.find_resource(identity_client.projects, - parsed_args.project, - domain_id=domain.id).id + domain = identity_common.find_domain( + identity_client, parsed_args.domain + ) + project_id = utils.find_resource( + identity_client.projects, + parsed_args.project, + domain_id=domain.id, + ).id else: - project_id = utils.find_resource(identity_client.projects, - parsed_args.project).id + project_id = utils.find_resource( + identity_client.projects, parsed_args.project + ).id compute_limits = None volume_limits = None if self.app.client_manager.is_compute_endpoint_enabled(): - compute_limits = compute_client.limits.get(parsed_args.is_reserved, - tenant_id=project_id) + compute_limits = compute_client.limits.get( + parsed_args.is_reserved, tenant_id=project_id + ) if self.app.client_manager.is_volume_endpoint_enabled(volume_client): volume_limits = volume_client.limits.get() @@ -100,17 +108,33 @@ class ShowLimits(command.Lister): if volume_limits: data.append(volume_limits.absolute) columns = ["Name", "Value"] - return (columns, (utils.get_item_properties(s, columns) - for s in itertools.chain(*data))) + return ( + columns, + ( + utils.get_item_properties(s, columns) + for s in itertools.chain(*data) + ), + ) elif parsed_args.is_rate: if compute_limits: data.append(compute_limits.rate) if volume_limits: data.append(volume_limits.rate) - columns = ["Verb", "URI", "Value", "Remain", "Unit", - "Next Available"] - return (columns, (utils.get_item_properties(s, columns) - for s in itertools.chain(*data))) + columns = [ + "Verb", + "URI", + "Value", + "Remain", + "Unit", + "Next Available", + ] + return ( + columns, + ( + utils.get_item_properties(s, columns) + for s in itertools.chain(*data) + ), + ) else: return {}, {} diff --git a/openstackclient/common/module.py b/openstackclient/common/module.py index f55fdce0..486a27cc 100644 --- a/openstackclient/common/module.py +++ b/openstackclient/common/module.py @@ -33,9 +33,11 @@ class ListCommand(command.Lister): parser.add_argument( '--group', metavar='<group-keyword>', - help=_('Show commands filtered by a command group, for example: ' - 'identity, volume, compute, image, network and ' - 'other keywords'), + help=_( + 'Show commands filtered by a command group, for example: ' + 'identity, volume, compute, image, network and ' + 'other keywords' + ), ) return parser @@ -54,7 +56,6 @@ class ListCommand(command.Lister): command_names = sorted(command_names) if command_names != []: - # TODO(bapalm): Fix this when cliff properly supports # handling the detection rather than using the hard-code below. if parsed_args.formatter == 'table': @@ -81,7 +82,6 @@ class ListModule(command.ShowOne): return parser def take_action(self, parsed_args): - data = {} # Get module versions mods = sys.modules @@ -95,9 +95,12 @@ class ListModule(command.ShowOne): # show for the default (not --all) invocation. # It should be just the things we actually care # about like client and plugin modules... - if (parsed_args.all or - # Handle xxxclient and openstacksdk - (k.endswith('client') or k == 'openstack')): + if ( + parsed_args.all + or + # Handle xxxclient and openstacksdk + (k.endswith('client') or k == 'openstack') + ): try: # NOTE(RuiChen): openstacksdk bug/1588823 exist, # no good way to add __version__ for diff --git a/openstackclient/common/progressbar.py b/openstackclient/common/progressbar.py index 7678aceb..98747ea1 100644 --- a/openstackclient/common/progressbar.py +++ b/openstackclient/common/progressbar.py @@ -38,9 +38,11 @@ class _ProgressBarBase(object): if self._show_progress: self._percent += size_read / self._totalsize # Output something like this: [==========> ] 49% - sys.stdout.write('\r[{0:<30}] {1:.0%}'.format( - '=' * int(round(self._percent * 29)) + '>', self._percent - )) + sys.stdout.write( + '\r[{0:<30}] {1:.0%}'.format( + '=' * int(round(self._percent * 29)) + '>', self._percent + ) + ) sys.stdout.flush() def __getattr__(self, attr): diff --git a/openstackclient/common/project_cleanup.py b/openstackclient/common/project_cleanup.py index 1193051a..32a1fa7a 100644 --- a/openstackclient/common/project_cleanup.py +++ b/openstackclient/common/project_cleanup.py @@ -35,8 +35,7 @@ def ask_user_yesno(msg): :return bool: User choice """ while True: - answer = getpass._raw_input( - '{} [{}]: '.format(msg, 'y/n')) + answer = getpass._raw_input('{} [{}]: '.format(msg, 'y/n')) if answer in ('y', 'Y', 'yes'): return True elif answer in ('n', 'N', 'no'): @@ -52,33 +51,33 @@ class ProjectCleanup(command.Command): action_group.add_argument( '--dry-run', action='store_true', - help=_("List a project's resources but do not delete them") + help=_("List a project's resources but do not delete them"), ) action_group.add_argument( '--auto-approve', action='store_true', - help=_("Delete resources without asking for confirmation") + help=_("Delete resources without asking for confirmation"), ) project_group = parser.add_mutually_exclusive_group(required=True) project_group.add_argument( '--auth-project', action='store_true', - help=_('Delete resources of the project used to authenticate') + help=_('Delete resources of the project used to authenticate'), ) project_group.add_argument( '--project', metavar='<project>', - help=_('Project to clean (name or ID)') + help=_('Project to clean (name or ID)'), ) parser.add_argument( '--created-before', metavar='<YYYY-MM-DDTHH24:MI:SS>', - help=_('Only delete resources created before the given time') + help=_('Only delete resources created before the given time'), ) parser.add_argument( '--updated-before', metavar='<YYYY-MM-DDTHH24:MI:SS>', - help=_('Only delete resources updated before the given time') + help=_('Only delete resources updated before the given time'), ) identity_common.add_project_domain_option_to_parser(parser) return parser @@ -90,16 +89,18 @@ class ProjectCleanup(command.Command): project_connect = sdk elif parsed_args.project: project = sdk.identity.find_project( - name_or_id=parsed_args.project, - ignore_missing=False) + name_or_id=parsed_args.project, ignore_missing=False + ) project_connect = sdk.connect_as_project(project) if project_connect: status_queue = queue.Queue() - parsed_args.max_width = int(os.environ.get('CLIFF_MAX_TERM_WIDTH', - 0)) - parsed_args.fit_width = bool(int(os.environ.get('CLIFF_FIT_WIDTH', - 0))) + parsed_args.max_width = int( + os.environ.get('CLIFF_MAX_TERM_WIDTH', 0) + ) + parsed_args.fit_width = bool( + int(os.environ.get('CLIFF_FIT_WIDTH', 0)) + ) parsed_args.print_empty = False table_fmt = table.TableFormatter() @@ -112,22 +113,20 @@ class ProjectCleanup(command.Command): if parsed_args.updated_before: filters['updated_at'] = parsed_args.updated_before - project_connect.project_cleanup(dry_run=True, - status_queue=status_queue, - filters=filters) + project_connect.project_cleanup( + dry_run=True, status_queue=status_queue, filters=filters + ) data = [] while not status_queue.empty(): resource = status_queue.get_nowait() data.append( - (type(resource).__name__, resource.id, resource.name)) + (type(resource).__name__, resource.id, resource.name) + ) status_queue.task_done() status_queue.join() table_fmt.emit_list( - ('Type', 'ID', 'Name'), - data, - self.app.stdout, - parsed_args + ('Type', 'ID', 'Name'), data, self.app.stdout, parsed_args ) if parsed_args.dry_run: @@ -135,11 +134,12 @@ class ProjectCleanup(command.Command): if not parsed_args.auto_approve: if not ask_user_yesno( - _("These resources will be deleted. Are you sure")): + _("These resources will be deleted. Are you sure") + ): return self.log.warning(_('Deleting resources')) - project_connect.project_cleanup(dry_run=False, - status_queue=status_queue, - filters=filters) + project_connect.project_cleanup( + dry_run=False, status_queue=status_queue, filters=filters + ) diff --git a/openstackclient/common/project_purge.py b/openstackclient/common/project_purge.py index 76ed4563..11cf0076 100644 --- a/openstackclient/common/project_purge.py +++ b/openstackclient/common/project_purge.py @@ -88,7 +88,8 @@ class ProjectPurge(command.Command): search_opts = {'tenant_id': project_id, 'all_tenants': True} data = compute_client.servers.list(search_opts=search_opts) self.delete_objects( - compute_client.servers.delete, data, 'server', dry_run) + compute_client.servers.delete, data, 'server', dry_run + ) except Exception: pass @@ -104,7 +105,8 @@ class ProjectPurge(command.Command): else: raise NotImplementedError self.delete_objects( - image_client.images.delete, data, 'image', dry_run) + image_client.images.delete, data, 'image', dry_run + ) except Exception: pass @@ -117,45 +119,49 @@ class ProjectPurge(command.Command): self.delete_one_volume_snapshot, data, 'volume snapshot', - dry_run) + dry_run, + ) except Exception: pass try: data = volume_client.backups.list(search_opts=search_opts) self.delete_objects( - self.delete_one_volume_backup, - data, - 'volume backup', - dry_run) + self.delete_one_volume_backup, data, 'volume backup', dry_run + ) except Exception: pass try: data = volume_client.volumes.list(search_opts=search_opts) self.delete_objects( - volume_client.volumes.force_delete, data, 'volume', dry_run) + volume_client.volumes.force_delete, data, 'volume', dry_run + ) except Exception: pass def delete_objects(self, func_delete, data, resource, dry_run): result = 0 for i in data: - LOG.warning(_('Deleting %(resource)s : %(id)s') % - {'resource': resource, 'id': i.id}) + LOG.warning( + _('Deleting %(resource)s : %(id)s') + % {'resource': resource, 'id': i.id} + ) if not dry_run: try: func_delete(i.id) except Exception as e: result += 1 - LOG.error(_("Failed to delete %(resource)s with " - "ID '%(id)s': %(e)s") - % {'resource': resource, 'id': i.id, 'e': e}) + LOG.error( + _( + "Failed to delete %(resource)s with " + "ID '%(id)s': %(e)s" + ) + % {'resource': resource, 'id': i.id, 'e': e} + ) if result > 0: total = len(data) - msg = (_("%(result)s of %(total)s %(resource)ss failed " - "to delete.") % - {'result': result, - 'total': total, - 'resource': resource}) + msg = _( + "%(result)s of %(total)s %(resource)ss failed " "to delete." + ) % {'result': result, 'total': total, 'resource': resource} LOG.error(msg) def delete_one_volume_snapshot(self, snapshot_id): diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py index 670451e2..409fea6c 100644 --- a/openstackclient/common/quota.py +++ b/openstackclient/common/quota.py @@ -749,10 +749,12 @@ class SetQuota(common.NetDetectionMixin, command.Command): class ShowQuota(command.Lister): - _description = _("""Show quotas for project or class. + _description = _( + """Show quotas for project or class. Specify ``--os-compute-api-version 2.50`` or higher to see ``server-groups`` -and ``server-group-members`` output for a given quota class.""") +and ``server-group-members`` output for a given quota class.""" + ) def get_parser(self, prog_name): parser = super().get_parser(prog_name) diff --git a/openstackclient/common/versions.py b/openstackclient/common/versions.py index 3acd9f73..b7ebf02e 100644 --- a/openstackclient/common/versions.py +++ b/openstackclient/common/versions.py @@ -46,26 +46,29 @@ class ShowVersions(command.Lister): parser.add_argument( '--service', metavar='<service>', - help=_('Show versions for a specific service. The argument should ' - 'be either an exact match to what is in the catalog or a ' - 'known official value or alias from ' - 'service-types-authority ' - '(https://service-types.openstack.org/)'), + help=_( + 'Show versions for a specific service. The argument should ' + 'be either an exact match to what is in the catalog or a ' + 'known official value or alias from ' + 'service-types-authority ' + '(https://service-types.openstack.org/)' + ), ) parser.add_argument( '--status', metavar='<status>', - help=_("""Show versions for a specific status. Valid values are: + help=_( + """Show versions for a specific status. Valid values are: - SUPPORTED - CURRENT - DEPRECATED -- EXPERIMENTAL""") +- EXPERIMENTAL""" + ), ) return parser def take_action(self, parsed_args): - interface = parsed_args.interface if parsed_args.is_all_interfaces: interface = None @@ -74,7 +77,8 @@ class ShowVersions(command.Lister): version_data = session.get_all_version_data( interface=interface, region_name=parsed_args.region_name, - service_type=parsed_args.service) + service_type=parsed_args.service, + ) columns = [ "Region Name", @@ -97,13 +101,15 @@ class ShowVersions(command.Lister): for data in service_versions: if status and status != data['status']: continue - versions.append(( - region_name, - service_type, - data['version'], - data['status'], - data['url'], - data['min_microversion'], - data['max_microversion'], - )) + versions.append( + ( + region_name, + service_type, + data['version'], + data['status'], + data['url'], + data['min_microversion'], + data['max_microversion'], + ) + ) return (columns, versions) |