Add commands for quota class API
Change-Id: Id1710f986d7ff1943fe3841cfd9837d2316419e0 Implements: blueprint support-quotas-in-karbor
This commit is contained in:
40
karborclient/tests/unit/v1/test_quota_classes.py
Normal file
40
karborclient/tests/unit/v1/test_quota_classes.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# 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.
|
||||
|
||||
import mock
|
||||
|
||||
from karborclient.tests.unit import base
|
||||
from karborclient.tests.unit.v1 import fakes
|
||||
|
||||
cs = fakes.FakeClient()
|
||||
mock_request_return = ({}, {'quota_class': {'plans': 50}})
|
||||
|
||||
|
||||
class QuotaClassesTest(base.TestCaseShell):
|
||||
|
||||
@mock.patch('karborclient.common.http.HTTPClient.json_request')
|
||||
def test_quota_class_update(self, mock_request):
|
||||
mock_request.return_value = mock_request_return
|
||||
cs.quota_classes.update('default', {'plans': 50})
|
||||
mock_request.assert_called_with(
|
||||
'PUT',
|
||||
'/quota_classes/default',
|
||||
data={'quota_class': {'plans': 50}}, headers={})
|
||||
|
||||
@mock.patch('karborclient.common.http.HTTPClient.json_request')
|
||||
def test_show_quota_class(self, mock_request):
|
||||
mock_request.return_value = mock_request_return
|
||||
cs.quota_classes.get('default')
|
||||
mock_request.assert_called_with(
|
||||
'GET',
|
||||
'/quota_classes/default',
|
||||
headers={})
|
||||
@@ -18,6 +18,7 @@ from karborclient.v1 import operation_logs
|
||||
from karborclient.v1 import plans
|
||||
from karborclient.v1 import protectables
|
||||
from karborclient.v1 import providers
|
||||
from karborclient.v1 import quota_classes
|
||||
from karborclient.v1 import quotas
|
||||
from karborclient.v1 import restores
|
||||
from karborclient.v1 import scheduled_operations
|
||||
@@ -52,3 +53,4 @@ class Client(object):
|
||||
self.http_client)
|
||||
self.services = services.ServiceManager(self.http_client)
|
||||
self.quotas = quotas.QuotaManager(self.http_client)
|
||||
self.quota_classes = quota_classes.QuotaClassManager(self.http_client)
|
||||
|
||||
42
karborclient/v1/quota_classes.py
Normal file
42
karborclient/v1/quota_classes.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# 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 karborclient.common import base
|
||||
|
||||
|
||||
class QuotaClass(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<QuotaClass %s>" % self._info
|
||||
|
||||
|
||||
class QuotaClassManager(base.ManagerWithFind):
|
||||
resource_class = QuotaClass
|
||||
|
||||
def list(self):
|
||||
pass
|
||||
|
||||
def update(self, class_name, data):
|
||||
|
||||
body = {"quota_class": data}
|
||||
|
||||
return self._update('/quota_classes/{class_name}'
|
||||
.format(class_name=class_name),
|
||||
body, "quota_class")
|
||||
|
||||
def get(self, class_name, session_id=None):
|
||||
if session_id:
|
||||
headers = {'X-Configuration-Session': session_id}
|
||||
else:
|
||||
headers = {}
|
||||
url = "/quota_classes/{class_name}".format(
|
||||
class_name=class_name)
|
||||
return self._get(url, response_key="quota_class", headers=headers)
|
||||
@@ -1354,3 +1354,33 @@ def do_quota_defaults(cs, args):
|
||||
|
||||
result = cs.quotas.defaults(project_id)
|
||||
_quota_set_pretty_show(result)
|
||||
|
||||
|
||||
@utils.arg(
|
||||
'class_name',
|
||||
metavar='<class_name>',
|
||||
help='Name of quota class to list the quotas for.')
|
||||
def do_quota_class_show(cs, args):
|
||||
"""List the quotas for a quota class."""
|
||||
result = cs.quota_classes.get(args.class_name)
|
||||
_quota_set_pretty_show(result)
|
||||
|
||||
|
||||
@utils.arg(
|
||||
'class_name',
|
||||
metavar='<class_name>',
|
||||
help='Name of quota class to set the quotas for.')
|
||||
@utils.arg(
|
||||
'--plans',
|
||||
metavar='<plans>',
|
||||
type=int,
|
||||
default=None,
|
||||
help='New value for the "plans" quota.')
|
||||
def do_quota_class_update(cs, args):
|
||||
"""Update the quotas for a quota class (Admin only)."""
|
||||
class_name = args.class_name
|
||||
data = {
|
||||
"plans": args.plans,
|
||||
}
|
||||
result = cs.quota_classes.update(class_name, data)
|
||||
_quota_set_pretty_show(result)
|
||||
|
||||
Reference in New Issue
Block a user