@@ -241,182 +241,194 @@ def get_parser(self, prog_name):
241241 )
242242 return parser
243243
244- def take_action (self , parsed_args ):
244+ def _list_quota_compute (self , parsed_args , project_ids ):
245+ compute_client = self .app .client_manager .compute
245246 result = []
246- project_ids = [
247- p .id for p in self .app .client_manager .identity .projects .list ()
248- ]
249247
250- if parsed_args .compute :
251- compute_client = self .app .client_manager .compute
252- for p in project_ids :
253- try :
254- data = compute_client .quotas .get (p )
255- except Exception as ex :
256- if (
257- type (ex ).__name__ == 'NotFound'
258- or ex .http_status >= 400
259- and ex .http_status <= 499
260- ):
261- # Project not found, move on to next one
262- LOG .warning (f"Project { p } not found: { ex } " )
263- continue
264- else :
265- raise
266-
267- result_data = _xform_get_quota (
268- data ,
269- p ,
270- COMPUTE_QUOTAS .keys (),
271- )
272- default_data = compute_client .quotas .defaults (p )
273- result_default = _xform_get_quota (
274- default_data ,
275- p ,
276- COMPUTE_QUOTAS .keys (),
277- )
278- if result_default != result_data :
279- result += result_data
280-
281- columns = (
282- 'id' ,
283- 'cores' ,
284- 'injected_files' ,
285- 'injected_file_content_bytes' ,
286- 'injected_file_path_bytes' ,
287- 'instances' ,
288- 'key_pairs' ,
289- 'metadata_items' ,
290- 'ram' ,
291- 'server_groups' ,
292- 'server_group_members' ,
248+ for p in project_ids :
249+ try :
250+ data = compute_client .quotas .get (p )
251+ except Exception as ex :
252+ if (
253+ type (ex ).__name__ == 'NotFound'
254+ or ex .http_status >= 400
255+ and ex .http_status <= 499
256+ ):
257+ # Project not found, move on to next one
258+ LOG .warning (f"Project { p } not found: { ex } " )
259+ continue
260+ else :
261+ raise
262+
263+ result_data = _xform_get_quota (
264+ data ,
265+ p ,
266+ COMPUTE_QUOTAS .keys (),
293267 )
294- column_headers = (
295- 'Project ID' ,
296- 'Cores' ,
297- 'Injected Files' ,
298- 'Injected File Content Bytes' ,
299- 'Injected File Path Bytes' ,
300- 'Instances' ,
301- 'Key Pairs' ,
302- 'Metadata Items' ,
303- 'Ram' ,
304- 'Server Groups' ,
305- 'Server Group Members' ,
306- )
307- return (
308- column_headers ,
309- (utils .get_dict_properties (s , columns ) for s in result ),
268+ default_data = compute_client .quotas .defaults (p )
269+ result_default = _xform_get_quota (
270+ default_data ,
271+ p ,
272+ COMPUTE_QUOTAS .keys (),
310273 )
274+ if result_default != result_data :
275+ result += result_data
311276
312- if parsed_args .volume :
313- volume_client = self .app .client_manager .volume
314- for p in project_ids :
315- try :
316- data = volume_client .quotas .get (p )
317- except Exception as ex :
318- if type (ex ).__name__ == 'NotFound' :
319- # Project not found, move on to next one
320- LOG .warning (f"Project { p } not found: { ex } " )
321- continue
322- else :
323- raise
324-
325- result_data = _xform_get_quota (
326- data ,
327- p ,
328- VOLUME_QUOTAS .keys (),
329- )
330- default_data = volume_client .quotas .defaults (p )
331- result_default = _xform_get_quota (
332- default_data ,
333- p ,
334- VOLUME_QUOTAS .keys (),
335- )
336- if result_default != result_data :
337- result += result_data
338-
339- columns = (
340- 'id' ,
341- 'backups' ,
342- 'backup_gigabytes' ,
343- 'gigabytes' ,
344- 'per_volume_gigabytes' ,
345- 'snapshots' ,
346- 'volumes' ,
277+ columns = (
278+ 'id' ,
279+ 'cores' ,
280+ 'injected_files' ,
281+ 'injected_file_content_bytes' ,
282+ 'injected_file_path_bytes' ,
283+ 'instances' ,
284+ 'key_pairs' ,
285+ 'metadata_items' ,
286+ 'ram' ,
287+ 'server_groups' ,
288+ 'server_group_members' ,
289+ )
290+ column_headers = (
291+ 'Project ID' ,
292+ 'Cores' ,
293+ 'Injected Files' ,
294+ 'Injected File Content Bytes' ,
295+ 'Injected File Path Bytes' ,
296+ 'Instances' ,
297+ 'Key Pairs' ,
298+ 'Metadata Items' ,
299+ 'Ram' ,
300+ 'Server Groups' ,
301+ 'Server Group Members' ,
302+ )
303+ return (
304+ column_headers ,
305+ (utils .get_dict_properties (s , columns ) for s in result ),
306+ )
307+
308+ def _list_quota_volume (self , parsed_args , project_ids ):
309+ volume_client = self .app .client_manager .volume
310+ result = []
311+
312+ for p in project_ids :
313+ try :
314+ data = volume_client .quotas .get (p )
315+ except Exception as ex :
316+ if type (ex ).__name__ == 'NotFound' :
317+ # Project not found, move on to next one
318+ LOG .warning (f"Project { p } not found: { ex } " )
319+ continue
320+ else :
321+ raise
322+
323+ result_data = _xform_get_quota (
324+ data ,
325+ p ,
326+ VOLUME_QUOTAS .keys (),
347327 )
348- column_headers = (
349- 'Project ID' ,
350- 'Backups' ,
351- 'Backup Gigabytes' ,
352- 'Gigabytes' ,
353- 'Per Volume Gigabytes' ,
354- 'Snapshots' ,
355- 'Volumes' ,
328+ default_data = volume_client .quotas .defaults (p )
329+ result_default = _xform_get_quota (
330+ default_data ,
331+ p ,
332+ VOLUME_QUOTAS .keys (),
356333 )
334+ if result_default != result_data :
335+ result += result_data
357336
358- return (
359- column_headers ,
360- (utils .get_dict_properties (s , columns ) for s in result ),
361- )
337+ columns = (
338+ 'id' ,
339+ 'backups' ,
340+ 'backup_gigabytes' ,
341+ 'gigabytes' ,
342+ 'per_volume_gigabytes' ,
343+ 'snapshots' ,
344+ 'volumes' ,
345+ )
346+ column_headers = (
347+ 'Project ID' ,
348+ 'Backups' ,
349+ 'Backup Gigabytes' ,
350+ 'Gigabytes' ,
351+ 'Per Volume Gigabytes' ,
352+ 'Snapshots' ,
353+ 'Volumes' ,
354+ )
362355
363- if parsed_args .network :
364- client = self .app .client_manager .network
365- for p in project_ids :
366- try :
367- data = client .get_quota (p )
368- except Exception as ex :
369- if type (ex ).__name__ == 'NotFound' :
370- # Project not found, move on to next one
371- LOG .warning (f"Project { p } not found: { ex } " )
372- continue
373- else :
374- raise
375-
376- result_data = _xform_get_quota (
377- data ,
378- p ,
379- NETWORK_KEYS ,
380- )
381- default_data = client .get_quota_default (p )
382- result_default = _xform_get_quota (
383- default_data ,
384- p ,
385- NETWORK_KEYS ,
386- )
387- if result_default != result_data :
388- result += result_data
389-
390- columns = (
391- 'id' ,
392- 'floating_ips' ,
393- 'networks' ,
394- 'ports' ,
395- 'rbac_policies' ,
396- 'routers' ,
397- 'security_groups' ,
398- 'security_group_rules' ,
399- 'subnets' ,
400- 'subnet_pools' ,
356+ return (
357+ column_headers ,
358+ (utils .get_dict_properties (s , columns ) for s in result ),
359+ )
360+
361+ def _list_quota_network (self , parsed_args , project_ids ):
362+ client = self .app .client_manager .network
363+ result = []
364+
365+ for p in project_ids :
366+ try :
367+ data = client .get_quota (p )
368+ except Exception as ex :
369+ if type (ex ).__name__ == 'NotFound' :
370+ # Project not found, move on to next one
371+ LOG .warning (f"Project { p } not found: { ex } " )
372+ continue
373+ else :
374+ raise
375+
376+ result_data = _xform_get_quota (
377+ data ,
378+ p ,
379+ NETWORK_KEYS ,
401380 )
402- column_headers = (
403- 'Project ID' ,
404- 'Floating IPs' ,
405- 'Networks' ,
406- 'Ports' ,
407- 'RBAC Policies' ,
408- 'Routers' ,
409- 'Security Groups' ,
410- 'Security Group Rules' ,
411- 'Subnets' ,
412- 'Subnet Pools' ,
381+ default_data = client .get_quota_default (p )
382+ result_default = _xform_get_quota (
383+ default_data ,
384+ p ,
385+ NETWORK_KEYS ,
413386 )
387+ if result_default != result_data :
388+ result += result_data
414389
415- return (
416- column_headers ,
417- (utils .get_dict_properties (s , columns ) for s in result ),
418- )
390+ columns = (
391+ 'id' ,
392+ 'floating_ips' ,
393+ 'networks' ,
394+ 'ports' ,
395+ 'rbac_policies' ,
396+ 'routers' ,
397+ 'security_groups' ,
398+ 'security_group_rules' ,
399+ 'subnets' ,
400+ 'subnet_pools' ,
401+ )
402+ column_headers = (
403+ 'Project ID' ,
404+ 'Floating IPs' ,
405+ 'Networks' ,
406+ 'Ports' ,
407+ 'RBAC Policies' ,
408+ 'Routers' ,
409+ 'Security Groups' ,
410+ 'Security Group Rules' ,
411+ 'Subnets' ,
412+ 'Subnet Pools' ,
413+ )
414+
415+ return (
416+ column_headers ,
417+ (utils .get_dict_properties (s , columns ) for s in result ),
418+ )
419+
420+ def take_action (self , parsed_args ):
421+ project_ids = [
422+ p .id for p in self .app .client_manager .identity .projects .list ()
423+ ]
424+ if parsed_args .compute :
425+ return self ._list_quota_compute (parsed_args , project_ids )
426+ elif parsed_args .volume :
427+ return self ._list_quota_volume (parsed_args , project_ids )
428+ elif parsed_args .network :
429+ return self ._list_quota_network (parsed_args , project_ids )
419430
431+ # will never get here
420432 return ((), ())
421433
422434
0 commit comments