| 1 |
# |
| 2 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 3 |
# not use this file except in compliance with the License. You may obtain |
| 4 |
# a copy of the License at |
| 5 |
# |
| 6 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
# |
| 8 |
# Unless required by applicable law or agreed to in writing, software |
| 9 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 |
# License for the specific language governing permissions and limitations |
| 12 |
# under the License. |
| 13 |
from cliff import show |
| 14 |
|
| 15 |
from aodhclient import exceptions |
| 16 |
from aodhclient import utils |
| 17 |
|
| 18 |
|
| 19 |
class QuotaShow(show.ShowOne): |
| 20 |
"""Show quota for a project""" |
| 21 |
|
| 22 |
def get_parser(self, prog_name): |
| 23 |
parser = super().get_parser(prog_name) |
| 24 |
parser.add_argument( |
| 25 |
"--project", |
| 26 |
help="Project ID. If not specified, get quota for the current " |
| 27 |
"project." |
| 28 |
) |
| 29 |
return parser |
| 30 |
|
| 31 |
def take_action(self, parsed_args): |
| 32 |
c = utils.get_client(self) |
| 33 |
quota = c.quota.list(project=parsed_args.project) |
| 34 |
|
| 35 |
ret = {} |
| 36 |
for q in quota['quotas']: |
| 37 |
ret[q['resource']] = q['limit'] |
| 38 |
|
| 39 |
return self.dict2columns(ret) |
| 40 |
|
| 41 |
|
| 42 |
class QuotaSet(show.ShowOne): |
| 43 |
def get_parser(self, prog_name): |
| 44 |
parser = super().get_parser(prog_name) |
| 45 |
parser.add_argument( |
| 46 |
"project", |
| 47 |
help="Project ID." |
| 48 |
) |
| 49 |
parser.add_argument( |
| 50 |
"--alarm", type=int, |
| 51 |
help="New value for the alarm quota. Value -1 means unlimited." |
| 52 |
) |
| 53 |
return parser |
| 54 |
|
| 55 |
def take_action(self, parsed_args): |
| 56 |
resource_quotas = [] |
| 57 |
if parsed_args.alarm is not None: |
| 58 |
if parsed_args.alarm < -1: |
| 59 |
raise exceptions.CommandError( |
| 60 |
'Quota limit cannot be less than -1.') |
| 61 |
resource_quotas.append( |
| 62 |
{'resource': 'alarms', 'limit': parsed_args.alarm}) |
| 63 |
|
| 64 |
c = utils.get_client(self) |
| 65 |
quota = c.quota.create(parsed_args.project, resource_quotas) |
| 66 |
|
| 67 |
ret = {} |
| 68 |
for q in quota['quotas']: |
| 69 |
ret[q['resource']] = q['limit'] |
| 70 |
|
| 71 |
return self.dict2columns(ret) |