Skip to content

Commit ed809e0

Browse files
author
Steve Martinelli
committed
Add quota v1 support for volume
added dhellmann's suggestions created entry points in setup.py added show/set/list quotas for v1 volume Change-Id: I8ed6a9518007b31cafeaa70a54d5bf54a549195b
1 parent 287c23c commit ed809e0

2 files changed

Lines changed: 116 additions & 0 deletions

File tree

‎openstackclient/volume/v1/quota.py‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Copyright 2012-2013 OpenStack, LLC.
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+
"""Volume v1 Quota action implementations"""
17+
18+
import logging
19+
20+
from cliff import command
21+
from cliff import show
22+
23+
from openstackclient.common import utils
24+
25+
26+
class ListQuota(show.ShowOne):
27+
"""List quota command"""
28+
29+
api = 'volume'
30+
log = logging.getLogger(__name__ + '.ListQuota')
31+
32+
def get_parser(self, prog_name):
33+
parser = super(ListQuota, self).get_parser(prog_name)
34+
parser.add_argument(
35+
'tenant',
36+
metavar='<tenant>',
37+
help='ID of tenant to list the default quotas for')
38+
return parser
39+
40+
def take_action(self, parsed_args):
41+
self.log.debug('take_action(%s)' % parsed_args)
42+
volume_client = self.app.client_manager.volume
43+
defaults = volume_client.quotas.defaults(parsed_args.tenant)
44+
45+
return zip(*sorted(defaults._info.iteritems()))
46+
47+
48+
class SetQuota(command.Command):
49+
"""Set quota command"""
50+
51+
api = 'volume'
52+
log = logging.getLogger(__name__ + '.SetQuota')
53+
54+
def get_parser(self, prog_name):
55+
parser = super(SetQuota, self).get_parser(prog_name)
56+
parser.add_argument(
57+
'tenant',
58+
metavar='<tenant>',
59+
help='ID of tenant to set the quotas for')
60+
parser.add_argument(
61+
'--volumes',
62+
metavar='<new-volumes>',
63+
type=int,
64+
help='New value for the volumes quota')
65+
parser.add_argument(
66+
'--gigabytes',
67+
metavar='<new-gigabytes>',
68+
type=int,
69+
help='New value for the gigabytes quota')
70+
return parser
71+
72+
def take_action(self, parsed_args):
73+
self.log.debug('take_action(%s)' % parsed_args)
74+
75+
kwargs = {}
76+
if parsed_args.volumes:
77+
kwargs['volumes'] = parsed_args.volumes
78+
if parsed_args.gigabytes:
79+
kwargs['gigabytes'] = parsed_args.gigabytes
80+
81+
if kwargs == {}:
82+
stdout.write("Quota not updated, no arguments present")
83+
return
84+
85+
volume_client = self.app.client_manager.volume
86+
volume_client.quotas.update(parsed_args.tenant,
87+
parsed_args.volumes,
88+
parsed_args.gigabytes)
89+
90+
return
91+
92+
93+
class ShowQuota(show.ShowOne):
94+
"""Show quota command"""
95+
96+
api = 'volume'
97+
log = logging.getLogger(__name__ + '.ShowQuota')
98+
99+
def get_parser(self, prog_name):
100+
parser = super(ShowQuota, self).get_parser(prog_name)
101+
parser.add_argument(
102+
'tenant',
103+
metavar='<tenant>',
104+
help='ID of tenant to list the quotas for')
105+
return parser
106+
107+
def take_action(self, parsed_args):
108+
self.log.debug('take_action(%s)' % parsed_args)
109+
volume_client = self.app.client_manager.volume
110+
quota = utils.find_resource(volume_client.quotas,
111+
parsed_args.tenant)
112+
113+
return zip(*sorted(quota._info.iteritems()))

‎setup.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ def read(fname):
147147
'create_type=openstackclient.volume.v1.type:CreateType',
148148
'delete_type=openstackclient.volume.v1.type:DeleteType',
149149
'list_type=openstackclient.volume.v1.type:ListType',
150+
'show_quota=openstackclient.volume.v1.quota:ShowQuota',
151+
'list_quota=openstackclient.volume.v1.quota:ListQuota',
152+
'set_quota=openstackclient.volume.v1.quota:SetQuota',
150153
]
151154
}
152155
)

0 commit comments

Comments
 (0)