diff options
| author | Stephen Finucane <sfinucan@redhat.com> | 2022-09-22 18:09:08 +0100 |
|---|---|---|
| committer | Stephen Finucane <sfinucan@redhat.com> | 2022-09-30 10:54:11 +0100 |
| commit | 45bec041b206678de36f2f463ac6872b785e592e (patch) | |
| tree | 09747744bb4cdd5ffc29151234196e28075a84ae /openstackclient/common | |
| parent | bfdf900d0a2fae16fe1ff2d8604215dd2de01d4a (diff) | |
| download | python-openstackclient-45bec041b206678de36f2f463ac6872b785e592e.tar.gz | |
quota: Add 'quota delete' command
We had previously indicated that people use 'quota set' for unsetting a
project's quotas, however, there was nothing that actually allowed us to
do this. Correct that oversight.
Change-Id: I04057e766b8ccf94bf219972249b68dc2bb796d4
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
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 |
