Skip to content

Commit 75dcdb0

Browse files
author
Dean Troyer
committed
Add show limits command
* This is a combination of the compute and volume API limits as they are very similar. As such, the command lives in a new command group 'openstack.common' that is unversioned. * Implements 'limits show [--absolute|--rate] Updated for https://review.openstack.org/#/c/36772/ Bug: 1172057 Change-Id: I2bd181cd0d098f7143360ae67944c2f221379af5
1 parent f0d3bf8 commit 75dcdb0

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

openstackclient/common/limits.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright 2012-2013 OpenStack Foundation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#
15+
16+
"""Limits Action Implementation"""
17+
18+
import itertools
19+
import logging
20+
21+
from cliff import lister
22+
23+
from openstackclient.common import utils
24+
25+
26+
class ShowLimits(lister.Lister):
27+
"""Show compute and volume limits"""
28+
29+
log = logging.getLogger(__name__ + '.ShowLimits')
30+
31+
def get_parser(self, prog_name):
32+
parser = super(ShowLimits, self).get_parser(prog_name)
33+
type_group = parser.add_mutually_exclusive_group()
34+
type_group.add_argument(
35+
"--absolute",
36+
dest="is_absolute",
37+
action="store_true",
38+
default=False,
39+
help="Show absolute limits")
40+
type_group.add_argument(
41+
"--rate",
42+
dest="is_rate",
43+
action="store_true",
44+
default=False,
45+
help="Show rate limits")
46+
parser.add_argument(
47+
"--reserved",
48+
dest="is_reserved",
49+
action="store_true",
50+
default=False,
51+
help="Include reservations count [only valid with --absolute]")
52+
return parser
53+
54+
def take_action(self, parsed_args):
55+
self.log.debug('take_action(%s)' % parsed_args)
56+
57+
compute_client = self.app.client_manager.compute
58+
volume_client = self.app.client_manager.volume
59+
60+
compute_limits = compute_client.limits.get(parsed_args.is_reserved)
61+
volume_limits = volume_client.limits.get()
62+
63+
if parsed_args.is_absolute:
64+
compute_limits = compute_limits.absolute
65+
volume_limits = volume_limits.absolute
66+
columns = ["Name", "Value"]
67+
return (columns, (utils.get_item_properties(s, columns)
68+
for s in itertools.chain(compute_limits, volume_limits)))
69+
70+
elif parsed_args.is_rate:
71+
compute_limits = compute_limits.rate
72+
volume_limits = volume_limits.rate
73+
columns = ["Verb", "URI", "Value", "Remain", "Unit",
74+
"Next Available"]
75+
return (columns, (utils.get_item_properties(s, columns)
76+
for s in itertools.chain(compute_limits, volume_limits)))
77+
78+
else:
79+
return ({}, {})

openstackclient/shell.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ def initialize_app(self, argv):
331331
self.command_manager.add_command_group(
332332
'openstack.' + api + version)
333333

334+
# Commands that span multiple APIs
335+
self.command_manager.add_command_group(
336+
'openstack.common')
337+
334338
# This is the naive extension implementation referred to in
335339
# blueprint 'client-extensions'
336340
# Extension modules can register their commands in an

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ console_scripts =
3131

3232
openstack.cli =
3333

34+
openstack.common =
35+
limits_show = openstackclient.common.limits:ShowLimits
36+
3437
openstack.identity.v2_0 =
3538
ec2_credentials_create = openstackclient.identity.v2_0.ec2creds:CreateEC2Creds
3639
ec2_credentials_delete = openstackclient.identity.v2_0.ec2creds:DeleteEC2Creds

0 commit comments

Comments
 (0)