Kien Nguyen eedf5c7fdd Allow setting quota of other tenants
Currently, the quota API/CLI allows users to set
quotas for current tenant only. However, admin
users needs the ability to set quota for other
tenants. For example:

   $ source /opt/stack/devstack/openrc admin admin
   $ openstack appcontainer quota update --containers 100 <DEMO_TENANT_UUID>

Depends-On: https://review.openstack.org/627075
Change-Id: Ia147575d3e8d2c6d54bddd98846f0c9e3e518ec3
Related-Bug: #1807620
2018-12-24 14:52:48 +07:00

53 lines
1.7 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from zunclient.common import base
class Quota(base.Resource):
def __repr__(self):
return "<Quota %s>" % self._info
class QuotaManager(base.Manager):
resource_class = Quota
@staticmethod
def _path(project_id):
if project_id is not None:
return '/v1/quotas/{}'.format(project_id)
return '/v1/quotas'
def get(self, project_id, **kwargs):
if not kwargs.get('usages'):
kwargs = {}
return self._list(self._path(project_id), qparams=kwargs)[0]
def update(self, project_id, containers=None,
memory=None, cpu=None, disk=None):
resources = {}
if cpu is not None:
resources['cpu'] = cpu
if memory is not None:
resources['memory'] = memory
if containers is not None:
resources['containers'] = containers
if disk is not None:
resources['disk'] = disk
return self._update(self._path(project_id), resources, method='PUT')
def defaults(self, project_id):
return self._list(self._path(project_id) + '/defaults')[0]
def delete(self, project_id):
return self._delete(self._path(project_id))