1111# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212# License for the specific language governing permissions and limitations
1313# under the License.
14- #
1514
1615"""Quota action implementations"""
1716
@@ -130,18 +129,12 @@ def get_compute_quotas(
130129 app ,
131130 project_id ,
132131 * ,
133- quota_class = False ,
134132 detail = False ,
135133 default = False ,
136134):
137135 try :
138136 client = app .client_manager .compute
139- if quota_class :
140- # NOTE(stephenfin): The 'project' argument here could be anything
141- # as the nova API doesn't care what you pass in. We only pass the
142- # project in to avoid weirding people out :)
143- quota = client .quota_classes .get (project_id )
144- elif default :
137+ if default :
145138 quota = client .quotas .defaults (project_id )
146139 else :
147140 quota = client .quotas .get (project_id , detail = detail )
@@ -156,15 +149,12 @@ def get_volume_quotas(
156149 app ,
157150 project_id ,
158151 * ,
159- quota_class = False ,
160152 detail = False ,
161153 default = False ,
162154):
163155 try :
164156 client = app .client_manager .volume
165- if quota_class :
166- quota = client .quota_classes .get (project_id )
167- elif default :
157+ if default :
168158 quota = client .quotas .defaults (project_id )
169159 else :
170160 quota = client .quotas .get (project_id , usage = detail )
@@ -180,7 +170,6 @@ def get_network_quotas(
180170 app ,
181171 project_id ,
182172 * ,
183- quota_class = False ,
184173 detail = False ,
185174 default = False ,
186175):
@@ -207,11 +196,6 @@ def _network_quota_to_dict(network_quota, detail=False):
207196
208197 return result
209198
210- # neutron doesn't have the concept of quota classes and if we're using
211- # nova-network we already fetched this
212- if quota_class :
213- return {}
214-
215199 # we have nothing to return if we are not using neutron
216200 if not app .client_manager .is_network_endpoint_enabled ():
217201 return {}
@@ -227,34 +211,14 @@ def _network_quota_to_dict(network_quota, detail=False):
227211
228212
229213class ListQuota (command .Lister ):
230- _description = _ (
231- "List quotas for all projects with non-default quota values or "
232- "list detailed quota information for requested project"
233- )
214+ """List quotas for all projects with non-default quota values.
215+
216+ Empty output means all projects are using default quotas, which can be
217+ inspected with 'openstack quota show --default'.
218+ """
234219
235220 def get_parser (self , prog_name ):
236221 parser = super ().get_parser (prog_name )
237- # TODO(stephenfin): Remove in OSC 8.0
238- parser .add_argument (
239- '--project' ,
240- metavar = '<project>' ,
241- help = _ (
242- "**Deprecated** List quotas for this project <project> "
243- "(name or ID). "
244- "Use 'quota show' instead."
245- ),
246- )
247- # TODO(stephenfin): Remove in OSC 8.0
248- parser .add_argument (
249- '--detail' ,
250- dest = 'detail' ,
251- action = 'store_true' ,
252- default = False ,
253- help = _ (
254- "**Deprecated** Show details about quotas usage. "
255- "Use 'quota show --usage' instead."
256- ),
257- )
258222 option = parser .add_mutually_exclusive_group (required = True )
259223 option .add_argument (
260224 '--compute' ,
@@ -276,102 +240,13 @@ def get_parser(self, prog_name):
276240 )
277241 return parser
278242
279- def _get_detailed_quotas (self , parsed_args ):
280- project_info = get_project (self .app , parsed_args .project )
281- project = project_info ['id' ]
282-
283- quotas = {}
284-
285- if parsed_args .compute :
286- quotas .update (
287- get_compute_quotas (
288- self .app ,
289- project ,
290- detail = parsed_args .detail ,
291- )
292- )
293-
294- if parsed_args .network :
295- quotas .update (
296- get_network_quotas (
297- self .app ,
298- project ,
299- detail = parsed_args .detail ,
300- )
301- )
302-
303- if parsed_args .volume :
304- quotas .update (
305- get_volume_quotas (
306- self .app ,
307- parsed_args ,
308- detail = parsed_args .detail ,
309- ),
310- )
311-
312- result = []
313- for resource , values in quotas .items ():
314- # NOTE(slaweq): there is no detailed quotas info for some resources
315- # and it shouldn't be displayed here
316- if isinstance (values , dict ):
317- result .append (
318- {
319- 'resource' : resource ,
320- 'in_use' : values .get ('in_use' ),
321- 'reserved' : values .get ('reserved' ),
322- 'limit' : values .get ('limit' ),
323- }
324- )
325-
326- columns = (
327- 'resource' ,
328- 'in_use' ,
329- 'reserved' ,
330- 'limit' ,
331- )
332- column_headers = (
333- 'Resource' ,
334- 'In Use' ,
335- 'Reserved' ,
336- 'Limit' ,
337- )
338-
339- return (
340- column_headers ,
341- (utils .get_dict_properties (s , columns ) for s in result ),
342- )
343-
344243 def take_action (self , parsed_args ):
345- if parsed_args .detail :
346- msg = _ (
347- "The --detail option has been deprecated. "
348- "Use 'openstack quota show --usage' instead."
349- )
350- self .log .warning (msg )
351- elif parsed_args .project : # elif to avoid being too noisy
352- msg = _ (
353- "The --project option has been deprecated. "
354- "Use 'openstack quota show' instead."
355- )
356- self .log .warning (msg )
357-
358244 result = []
359- project_ids = []
360- if parsed_args .project is None :
361- for p in self .app .client_manager .identity .projects .list ():
362- project_ids .append (getattr (p , 'id' , '' ))
363- else :
364- identity_client = self .app .client_manager .identity
365- project = utils .find_resource (
366- identity_client .projects ,
367- parsed_args .project ,
368- )
369- project_ids .append (getattr (project , 'id' , '' ))
245+ project_ids = [
246+ p .id for p in self .app .client_manager .identity .projects .list ()
247+ ]
370248
371249 if parsed_args .compute :
372- if parsed_args .detail :
373- return self ._get_detailed_quotas (parsed_args )
374-
375250 compute_client = self .app .client_manager .compute
376251 for p in project_ids :
377252 try :
@@ -434,9 +309,6 @@ def take_action(self, parsed_args):
434309 )
435310
436311 if parsed_args .volume :
437- if parsed_args .detail :
438- return self ._get_detailed_quotas (parsed_args )
439-
440312 volume_client = self .app .client_manager .volume
441313 for p in project_ids :
442314 try :
@@ -488,9 +360,6 @@ def take_action(self, parsed_args):
488360 )
489361
490362 if parsed_args .network :
491- if parsed_args .detail :
492- return self ._get_detailed_quotas (parsed_args )
493-
494363 client = self .app .client_manager .network
495364 for p in project_ids :
496365 try :
@@ -728,22 +597,24 @@ def take_action(self, parsed_args):
728597 "Network quotas are ignored since quota classes are not "
729598 "supported."
730599 )
731- else :
732- project = utils .find_resource (
733- identity_client .projects ,
734- parsed_args .project ,
735- ).id
736600
737- if compute_kwargs :
738- compute_client .quotas .update (project , ** compute_kwargs )
739- if volume_kwargs :
740- volume_client .quotas .update (project , ** volume_kwargs )
741- if (
742- network_kwargs
743- and self .app .client_manager .is_network_endpoint_enabled ()
744- ):
745- network_client = self .app .client_manager .network
746- network_client .update_quota (project , ** network_kwargs )
601+ return
602+
603+ project = utils .find_resource (
604+ identity_client .projects ,
605+ parsed_args .project ,
606+ ).id
607+
608+ if compute_kwargs :
609+ compute_client .quotas .update (project , ** compute_kwargs )
610+ if volume_kwargs :
611+ volume_client .quotas .update (project , ** volume_kwargs )
612+ if (
613+ network_kwargs
614+ and self .app .client_manager .is_network_endpoint_enabled ()
615+ ):
616+ network_client = self .app .client_manager .network
617+ network_client .update_quota (project , ** network_kwargs )
747618
748619
749620class ShowQuota (command .Lister ):
@@ -758,29 +629,14 @@ def get_parser(self, prog_name):
758629 parser = super ().get_parser (prog_name )
759630 parser .add_argument (
760631 'project' ,
761- metavar = '<project/class >' ,
632+ metavar = '<project>' ,
762633 nargs = '?' ,
763634 help = _ (
764- 'Show quotas for this project or class (name or ID) '
635+ 'Show quotas for this project (name or ID) '
765636 '(defaults to current project)'
766637 ),
767638 )
768639 type_group = parser .add_mutually_exclusive_group ()
769- # TODO(stephenfin): Remove in OSC 8.0
770- type_group .add_argument (
771- '--class' ,
772- dest = 'quota_class' ,
773- action = 'store_true' ,
774- default = False ,
775- help = _ (
776- '**Deprecated** Show quotas for <class>. '
777- 'Deprecated as quota classes were never fully implemented '
778- 'and only the default class is supported. '
779- 'Use --default instead which is also supported by the network '
780- 'service. '
781- '(compute and volume only)'
782- ),
783- )
784640 type_group .add_argument (
785641 '--default' ,
786642 dest = 'default' ,
@@ -832,20 +688,8 @@ def get_parser(self, prog_name):
832688 return parser
833689
834690 def take_action (self , parsed_args ):
835- project = parsed_args .project
836-
837- if parsed_args .quota_class :
838- msg = _ (
839- "The '--class' option has been deprecated. Quota classes were "
840- "never fully implemented and the compute and volume services "
841- "only support a single 'default' quota class while the "
842- "network service does not support quota classes at all. "
843- "Please use 'openstack quota show --default' instead."
844- )
845- self .log .warning (msg )
846- else :
847- project_info = get_project (self .app , parsed_args .project )
848- project = project_info ['id' ]
691+ project_info = get_project (self .app , parsed_args .project )
692+ project = project_info ['id' ]
849693
850694 compute_quota_info = {}
851695 volume_quota_info = {}
@@ -861,23 +705,20 @@ def take_action(self, parsed_args):
861705 self .app ,
862706 project ,
863707 detail = parsed_args .usage ,
864- quota_class = parsed_args .quota_class ,
865708 default = parsed_args .default ,
866709 )
867710 if parsed_args .service in {'all' , 'volume' }:
868711 volume_quota_info = get_volume_quotas (
869712 self .app ,
870713 project ,
871714 detail = parsed_args .usage ,
872- quota_class = parsed_args .quota_class ,
873715 default = parsed_args .default ,
874716 )
875717 if parsed_args .service in {'all' , 'network' }:
876718 network_quota_info = get_network_quotas (
877719 self .app ,
878720 project ,
879721 detail = parsed_args .usage ,
880- quota_class = parsed_args .quota_class ,
881722 default = parsed_args .default ,
882723 )
883724
0 commit comments