Added Quota Commands
openstack project quota show - Shows overview of current quotas for all region openstack project quota show --region REGIONNAME - Shows details for specified region openstack project quota tasks - lists completed and in progress quota updates openstack project quota sizes - Shows details of sizes for quotas openstack project quota update <size> --regions regionOne regionTwo - Submits a quota update request for the specified sizes - If regions are not specifed will default to all regions stacktask quota - returns data from the get request, including all quota sizes and the current quota values for all of the regions stacktask quota --regions <RegionName> - returns data from the quota get request but only returns quota data specific to the region Change-Id: I506befd7749100ebf8b8cc2c11f444f067e200d3
This commit is contained in:
committed by
Adrian Turjak
parent
e5f4d56748
commit
decc4ed309
157
adjutantclient/osc/v1/quota.py
Normal file
157
adjutantclient/osc/v1/quota.py
Normal file
@@ -0,0 +1,157 @@
|
||||
# Copyright (c) 2016 Catalyst IT Ltd.
|
||||
#
|
||||
# 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 logging
|
||||
import six
|
||||
|
||||
from osc_lib.command import command
|
||||
from osc_lib.i18n import _
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class QuotaShow(command.Lister):
|
||||
"""
|
||||
Displays current quota information.
|
||||
If not given a region it will print basic details of the state of
|
||||
the quotas. If given a region it will print all details for it.
|
||||
"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(QuotaShow, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'--region', metavar='<region>', required=False,
|
||||
help=_("Single region to display details on."))
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.registration
|
||||
|
||||
if not parsed_args.region:
|
||||
quota_data = client.quota.get()
|
||||
|
||||
headers = [
|
||||
'Region', 'Current Size', 'Preapproved Sizes']
|
||||
|
||||
rows = []
|
||||
for region in quota_data['regions']:
|
||||
rows.append([
|
||||
region['region'],
|
||||
region['current_quota_size'],
|
||||
", ".join(region['quota_change_options']),
|
||||
])
|
||||
return headers, rows
|
||||
else:
|
||||
quota_data = client.quota.get(regions=parsed_args.region)
|
||||
headers = ['Service', 'Resource', 'Current Quota', 'Current Usage']
|
||||
region = quota_data['regions'][0]
|
||||
|
||||
rows = []
|
||||
for service, service_detail in six.iteritems(
|
||||
region['current_usage']):
|
||||
for resource, value in six.iteritems(service_detail):
|
||||
current_quota = region['current_quota'][service].get(
|
||||
resource)
|
||||
rows.append([service, resource, current_quota, value])
|
||||
return headers, rows
|
||||
|
||||
|
||||
class QuotaSizes(command.Lister):
|
||||
"""
|
||||
Displays possible quota sizes.
|
||||
"""
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.registration
|
||||
|
||||
quota_data = client.quota.get()
|
||||
|
||||
headers = [
|
||||
'Size Name', 'Service', 'Resource', 'Value']
|
||||
|
||||
rows = []
|
||||
for size, size_details in six.iteritems(quota_data['quota_sizes']):
|
||||
for service, service_details in six.iteritems(size_details):
|
||||
for resource, value in six.iteritems(service_details):
|
||||
rows.append([size, service, resource, value])
|
||||
|
||||
return headers, rows
|
||||
|
||||
|
||||
class QuotaTasks(command.Lister):
|
||||
"""
|
||||
Displays quota tasks.
|
||||
"""
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.registration
|
||||
|
||||
quota_data = client.quota.get()
|
||||
|
||||
headers = [
|
||||
'ID', 'Regions', 'Proposed Size', 'Requested By', 'Created On',
|
||||
'valid', 'status',
|
||||
]
|
||||
|
||||
rows = []
|
||||
for task in quota_data['active_quota_tasks']:
|
||||
rows.append([
|
||||
task['id'],
|
||||
", ".join(task['regions']),
|
||||
task['size'],
|
||||
task['request_user'],
|
||||
task['task_created'],
|
||||
task['valid'],
|
||||
task['status'],
|
||||
])
|
||||
|
||||
return headers, rows
|
||||
|
||||
|
||||
class QuotaUpdate(command.Command):
|
||||
"""Submits a quota update task."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(QuotaUpdate, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'size', metavar='<size>',
|
||||
help=_("The size to update to."))
|
||||
parser.add_argument(
|
||||
'--regions', metavar='<regions>', nargs='+', required=False,
|
||||
help=_("Regions to update the quota on."))
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.registration
|
||||
if parsed_args.regions:
|
||||
status = client.quota.update(parsed_args.size, parsed_args.regions)
|
||||
else:
|
||||
# NOTE(amelia): regions aren't set the API will update all of them
|
||||
status = client.quota.update(parsed_args.size)
|
||||
status_code = status.status_code
|
||||
|
||||
if status_code == 200:
|
||||
if parsed_args.regions:
|
||||
print("Regions: %s quota updated to size %s."
|
||||
% (parsed_args.regions, parsed_args.size))
|
||||
else:
|
||||
print("All regions' quota updated to size %s."
|
||||
% (parsed_args.size))
|
||||
elif status_code == 202:
|
||||
print("The task has been created however requires admin approval"
|
||||
" before executing.")
|
||||
@@ -20,6 +20,7 @@ from adjutantclient.v1 import status
|
||||
from adjutantclient.v1 import tasks
|
||||
from adjutantclient.v1 import tokens
|
||||
from adjutantclient.v1 import users
|
||||
from adjutantclient.v1 import quota
|
||||
|
||||
|
||||
class Client(object):
|
||||
@@ -45,3 +46,4 @@ class Client(object):
|
||||
self.notifications = notifications.NotificationManager(
|
||||
self.http_client)
|
||||
self.status = status.StatusManager(self.http_client)
|
||||
self.quota = quota.QuotaManager(self.http_client)
|
||||
|
||||
40
adjutantclient/v1/quota.py
Normal file
40
adjutantclient/v1/quota.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (C) 2016 Catalyst IT Ltd
|
||||
#
|
||||
# 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 six.moves.urllib import parse
|
||||
|
||||
from adjutantclient.common import base
|
||||
|
||||
|
||||
class QuotaManager(base.BaseManager):
|
||||
|
||||
def get(self, regions=None):
|
||||
""" Gets data about current quota settings """
|
||||
url = '/openstack/quotas/'
|
||||
if regions:
|
||||
url += '?%s' % parse.urlencode({
|
||||
'regions': regions
|
||||
})
|
||||
return self.client.get(url).json()
|
||||
|
||||
def update(self, size, regions=None):
|
||||
""" Updates the quota to a specified size.
|
||||
If region is not set it will update all regions
|
||||
"""
|
||||
url = '/openstack/quotas/'
|
||||
fields = {
|
||||
'size': size,
|
||||
'regions': regions
|
||||
}
|
||||
return self.client.post(url, data=fields)
|
||||
@@ -47,6 +47,10 @@ openstack.registration.v1 =
|
||||
project_user_role_add = adjutantclient.osc.v1.users:UserRoleAdd
|
||||
project_user_role_remove = adjutantclient.osc.v1.users:UserRoleRemove
|
||||
project_manageable_roles = adjutantclient.osc.v1.users:ManageableRolesList
|
||||
project_quota_show = adjutantclient.osc.v1.quota:QuotaShow
|
||||
project_quota_sizes = adjutantclient.osc.v1.quota:QuotaSizes
|
||||
project_quota_tasks = adjutantclient.osc.v1.quota:QuotaTasks
|
||||
project_quota_update = adjutantclient.osc.v1.quota:QuotaUpdate
|
||||
password_forgot = adjutantclient.osc.v1.users:PasswordForgot
|
||||
password_reset = adjutantclient.osc.v1.users:PasswordReset
|
||||
signup = adjutantclient.osc.v1.signup:Signup
|
||||
|
||||
Reference in New Issue
Block a user