quota: Add 'quota set --default' option
This should have been added as a counterpart to the 'quota show --default' option way back when we added that. Better late than never! Change-Id: I0e3719e585353664fea6f23ec658a330086db3df Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
		@@ -461,10 +461,15 @@ class SetQuota(common.NetDetectionMixin, command.Command):
 | 
			
		||||
        parser.add_argument(
 | 
			
		||||
            'project',
 | 
			
		||||
            metavar='<project/class>',
 | 
			
		||||
            help=_('Set quotas for this project or class (name or ID)'),
 | 
			
		||||
            nargs='?',
 | 
			
		||||
            help=_(
 | 
			
		||||
                'Set quotas for this project or class (name or ID) '
 | 
			
		||||
                '(defaults to current project)'
 | 
			
		||||
            ),
 | 
			
		||||
        )
 | 
			
		||||
        # TODO(stephenfin): Remove in OSC 8.0
 | 
			
		||||
        parser.add_argument(
 | 
			
		||||
        type_group = parser.add_mutually_exclusive_group()
 | 
			
		||||
        type_group.add_argument(
 | 
			
		||||
            '--class',
 | 
			
		||||
            dest='quota_class',
 | 
			
		||||
            action='store_true',
 | 
			
		||||
@@ -476,6 +481,13 @@ class SetQuota(common.NetDetectionMixin, command.Command):
 | 
			
		||||
                '(compute and volume only)'
 | 
			
		||||
            ),
 | 
			
		||||
        )
 | 
			
		||||
        type_group.add_argument(
 | 
			
		||||
            '--default',
 | 
			
		||||
            dest='default',
 | 
			
		||||
            action='store_true',
 | 
			
		||||
            default=False,
 | 
			
		||||
            help=_('Set default quotas for <project>'),
 | 
			
		||||
        )
 | 
			
		||||
        for k, v, h in self._build_options_list():
 | 
			
		||||
            parser.add_argument(
 | 
			
		||||
                '--%s' % v,
 | 
			
		||||
@@ -529,13 +541,13 @@ class SetQuota(common.NetDetectionMixin, command.Command):
 | 
			
		||||
                "never fully implemented and the compute and volume services "
 | 
			
		||||
                "only support a single 'default' quota class while the "
 | 
			
		||||
                "network service does not support quota classes at all. "
 | 
			
		||||
                "Please use 'openstack quota show --default' instead."
 | 
			
		||||
                "Please use 'openstack quota set --default' instead."
 | 
			
		||||
            )
 | 
			
		||||
            self.log.warning(msg)
 | 
			
		||||
 | 
			
		||||
        identity_client = self.app.client_manager.identity
 | 
			
		||||
        compute_client = self.app.client_manager.compute
 | 
			
		||||
        volume_client = self.app.client_manager.volume
 | 
			
		||||
 | 
			
		||||
        compute_kwargs = {}
 | 
			
		||||
        for k, v in COMPUTE_QUOTAS.items():
 | 
			
		||||
            value = getattr(parsed_args, k, None)
 | 
			
		||||
@@ -581,15 +593,15 @@ class SetQuota(common.NetDetectionMixin, command.Command):
 | 
			
		||||
                if value is not None:
 | 
			
		||||
                    compute_kwargs[k] = value
 | 
			
		||||
 | 
			
		||||
        if parsed_args.quota_class:
 | 
			
		||||
        if parsed_args.quota_class or parsed_args.default:
 | 
			
		||||
            if compute_kwargs:
 | 
			
		||||
                compute_client.quota_classes.update(
 | 
			
		||||
                    parsed_args.project,
 | 
			
		||||
                    parsed_args.project or 'default',
 | 
			
		||||
                    **compute_kwargs,
 | 
			
		||||
                )
 | 
			
		||||
            if volume_kwargs:
 | 
			
		||||
                volume_client.quota_classes.update(
 | 
			
		||||
                    parsed_args.project,
 | 
			
		||||
                    parsed_args.project or 'default',
 | 
			
		||||
                    **volume_kwargs,
 | 
			
		||||
                )
 | 
			
		||||
            if network_kwargs:
 | 
			
		||||
@@ -600,10 +612,8 @@ class SetQuota(common.NetDetectionMixin, command.Command):
 | 
			
		||||
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        project = utils.find_resource(
 | 
			
		||||
            identity_client.projects,
 | 
			
		||||
            parsed_args.project,
 | 
			
		||||
        ).id
 | 
			
		||||
        project_info = get_project(self.app, parsed_args.project)
 | 
			
		||||
        project = project_info['id']
 | 
			
		||||
 | 
			
		||||
        if compute_kwargs:
 | 
			
		||||
            compute_client.quotas.update(project, **compute_kwargs)
 | 
			
		||||
 
 | 
			
		||||
@@ -788,6 +788,89 @@ class TestQuotaSet(TestQuota):
 | 
			
		||||
        self.assertNotCalled(self.network_client.update_quota)
 | 
			
		||||
        self.assertIsNone(result)
 | 
			
		||||
 | 
			
		||||
    def test_quota_set_default(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            '--injected-files',
 | 
			
		||||
            str(compute_fakes.injected_file_num),
 | 
			
		||||
            '--injected-file-size',
 | 
			
		||||
            str(compute_fakes.injected_file_size_num),
 | 
			
		||||
            '--injected-path-size',
 | 
			
		||||
            str(compute_fakes.injected_path_size_num),
 | 
			
		||||
            '--key-pairs',
 | 
			
		||||
            str(compute_fakes.key_pair_num),
 | 
			
		||||
            '--cores',
 | 
			
		||||
            str(compute_fakes.core_num),
 | 
			
		||||
            '--ram',
 | 
			
		||||
            str(compute_fakes.ram_num),
 | 
			
		||||
            '--instances',
 | 
			
		||||
            str(compute_fakes.instance_num),
 | 
			
		||||
            '--properties',
 | 
			
		||||
            str(compute_fakes.property_num),
 | 
			
		||||
            '--server-groups',
 | 
			
		||||
            str(compute_fakes.servgroup_num),
 | 
			
		||||
            '--server-group-members',
 | 
			
		||||
            str(compute_fakes.servgroup_members_num),
 | 
			
		||||
            '--gigabytes',
 | 
			
		||||
            str(compute_fakes.floating_ip_num),
 | 
			
		||||
            '--snapshots',
 | 
			
		||||
            str(compute_fakes.fix_ip_num),
 | 
			
		||||
            '--volumes',
 | 
			
		||||
            str(volume_fakes.QUOTA['volumes']),
 | 
			
		||||
            '--network',
 | 
			
		||||
            str(network_fakes.QUOTA['network']),
 | 
			
		||||
            '--default',
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ('injected_files', compute_fakes.injected_file_num),
 | 
			
		||||
            (
 | 
			
		||||
                'injected_file_content_bytes',
 | 
			
		||||
                compute_fakes.injected_file_size_num,
 | 
			
		||||
            ),
 | 
			
		||||
            ('injected_file_path_bytes', compute_fakes.injected_path_size_num),
 | 
			
		||||
            ('key_pairs', compute_fakes.key_pair_num),
 | 
			
		||||
            ('cores', compute_fakes.core_num),
 | 
			
		||||
            ('ram', compute_fakes.ram_num),
 | 
			
		||||
            ('instances', compute_fakes.instance_num),
 | 
			
		||||
            ('metadata_items', compute_fakes.property_num),
 | 
			
		||||
            ('server_groups', compute_fakes.servgroup_num),
 | 
			
		||||
            ('server_group_members', compute_fakes.servgroup_members_num),
 | 
			
		||||
            ('gigabytes', compute_fakes.floating_ip_num),
 | 
			
		||||
            ('snapshots', compute_fakes.fix_ip_num),
 | 
			
		||||
            ('volumes', volume_fakes.QUOTA['volumes']),
 | 
			
		||||
            ('network', network_fakes.QUOTA['network']),
 | 
			
		||||
            ('default', True),
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 | 
			
		||||
        result = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        kwargs_compute = {
 | 
			
		||||
            'injected_files': compute_fakes.injected_file_num,
 | 
			
		||||
            'injected_file_content_bytes': compute_fakes.injected_file_size_num,  # noqa: E501
 | 
			
		||||
            'injected_file_path_bytes': compute_fakes.injected_path_size_num,
 | 
			
		||||
            'key_pairs': compute_fakes.key_pair_num,
 | 
			
		||||
            'cores': compute_fakes.core_num,
 | 
			
		||||
            'ram': compute_fakes.ram_num,
 | 
			
		||||
            'instances': compute_fakes.instance_num,
 | 
			
		||||
            'metadata_items': compute_fakes.property_num,
 | 
			
		||||
            'server_groups': compute_fakes.servgroup_num,
 | 
			
		||||
            'server_group_members': compute_fakes.servgroup_members_num,
 | 
			
		||||
        }
 | 
			
		||||
        kwargs_volume = {
 | 
			
		||||
            'gigabytes': compute_fakes.floating_ip_num,
 | 
			
		||||
            'snapshots': compute_fakes.fix_ip_num,
 | 
			
		||||
            'volumes': volume_fakes.QUOTA['volumes'],
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        self.compute_quotas_class_mock.update.assert_called_with(
 | 
			
		||||
            'default', **kwargs_compute
 | 
			
		||||
        )
 | 
			
		||||
        self.volume_quotas_class_mock.update.assert_called_with(
 | 
			
		||||
            'default', **kwargs_volume
 | 
			
		||||
        )
 | 
			
		||||
        self.assertNotCalled(self.network_client.update_quota)
 | 
			
		||||
        self.assertIsNone(result)
 | 
			
		||||
 | 
			
		||||
    def test_quota_set_with_force(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            '--cores',
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,7 @@
 | 
			
		||||
---
 | 
			
		||||
features:
 | 
			
		||||
  - |
 | 
			
		||||
    The ``quota set`` command now supports a ``--default`` option. When
 | 
			
		||||
    provided, this will allow you to set quotas for the default quota class
 | 
			
		||||
    which is the only quota class supported by the Compute and Block Storage
 | 
			
		||||
    services. This replaces the deprecated ``quota set --class`` option.
 | 
			
		||||
		Reference in New Issue
	
	Block a user