diff options
| author | Zuul <zuul@review.opendev.org> | 2022-10-07 16:37:20 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2022-10-07 16:37:20 +0000 |
| commit | eac38feef03d6991d41552a200cd1624550525ea (patch) | |
| tree | 7f6703e7ce6e3746598983122974cc3791037d99 /openstackclient/common | |
| parent | 7d67a0be7ffd870da52e5f38490435ad3a11b83a (diff) | |
| parent | 45bec041b206678de36f2f463ac6872b785e592e (diff) | |
| download | python-openstackclient-eac38feef03d6991d41552a200cd1624550525ea.tar.gz | |
Merge "quota: Add 'quota delete' command"
Diffstat (limited to 'openstackclient/common')
| -rw-r--r-- | openstackclient/common/quota.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py index 44482367..0110feb6 100644 --- a/openstackclient/common/quota.py +++ b/openstackclient/common/quota.py @@ -697,3 +697,82 @@ class ShowQuota(command.ShowOne, BaseQuota): info['project_name'] = project_name return zip(*sorted(info.items())) + + +class DeleteQuota(command.Command): + _description = _( + "Delete configured quota for a project and revert to defaults." + ) + + def get_parser(self, prog_name): + parser = super().get_parser(prog_name) + parser.add_argument( + 'project', + metavar='<project>', + help=_('Delete quotas for this project (name or ID)'), + ) + option = parser.add_mutually_exclusive_group() + option.add_argument( + '--all', + action='store_const', + const='all', + dest='service', + default='all', + help=_('Delete project quotas for all services (default)'), + ) + option.add_argument( + '--compute', + action='store_const', + const='compute', + dest='service', + default='all', + help=_( + 'Delete compute quotas for the project ' + '(including network quotas when using nova-network)' + ), + ) + option.add_argument( + '--volume', + action='store_const', + const='volume', + dest='service', + default='all', + help=_('Delete volume quotas for the project'), + ) + option.add_argument( + '--network', + action='store_const', + const='network', + dest='service', + default='all', + help=_('Delete network quotas for the project'), + ) + return parser + + def take_action(self, parsed_args): + identity_client = self.app.client_manager.identity + project = utils.find_resource( + identity_client.projects, + parsed_args.project, + ) + + # compute quotas + if parsed_args.service in {'all', 'compute'}: + compute_client = self.app.client_manager.compute + compute_client.quotas.delete(project) + + # volume quotas + if parsed_args.service in {'all', 'volume'}: + volume_client = self.app.client_manager.volume + volume_client.quotas.delete(project) + + # network quotas (but only if we're not using nova-network, otherwise + # we already deleted the quotas in the compute step) + if ( + parsed_args.service in {'all', 'network'} + and self.app.client_manager.is_network_endpoint_enabled() + ): + network_client = self.app.client_manager.network + network_client.quotas.delete(project) + + return None |
