11"""Displays information about the bandwidth pools"""
22# :license: MIT, see LICENSE for more details.
3+ import concurrent .futures as cf
4+ import logging
5+ import time
6+
37import click
48
59from SoftLayer .CLI .command import SLCommand as SLCommand
812from SoftLayer .managers .account import AccountManager as AccountManager
913from SoftLayer import utils
1014
15+ LOGGER = logging .getLogger (__name__ )
16+
1117
1218@click .command (cls = SLCommand , )
1319@environment .pass_env
@@ -21,6 +27,7 @@ def cli(env):
2127 """
2228
2329 manager = AccountManager (env .client )
30+
2431 items = manager .get_bandwidth_pools ()
2532
2633 table = formatting .Table ([
@@ -35,31 +42,39 @@ def cli(env):
3542 "Deletion"
3643 ], title = "Bandwidth Pools" )
3744 table .align = 'l'
38- for item in items :
39- id_bandwidth = item .get ('id' )
40- name = item .get ('name' )
41- region = utils .lookup (item , 'locationGroup' , 'name' )
42- servers = manager .get_bandwidth_pool_counts (identifier = item .get ('id' ))
43- allocation = f"{ item .get ('totalBandwidthAllocated' , 0 )} GB"
4445
45- current = utils .lookup (item , 'billingCyclePublicBandwidthUsage' , 'amountOut' )
46- if current is not None :
47- current = f"{ current } GB"
48- else :
49- current = "0 GB"
46+ start_m = time .perf_counter ()
47+
48+ with cf .ThreadPoolExecutor (max_workers = 5 ) as executor :
49+ for item , servers in zip (items , executor .map (manager .get_bandwidth_pool_counts ,
50+ [item .get ('id' ) for item in items ])):
51+
52+ id_bandwidth = item .get ('id' )
53+ name = item .get ('name' )
54+ region = utils .lookup (item , 'locationGroup' , 'name' )
55+
56+ allocation = f"{ item .get ('totalBandwidthAllocated' , 0 )} GB"
57+
58+ current = utils .lookup (item , 'billingCyclePublicBandwidthUsage' , 'amountOut' )
59+ if current is not None :
60+ current = f"{ current } GB"
61+ else :
62+ current = "0 GB"
5063
51- projected = f"{ item .get ('projectedPublicBandwidthUsage' , 0 )} GB"
64+ projected = f"{ item .get ('projectedPublicBandwidthUsage' , 0 )} GB"
5265
53- cost = utils .lookup (item , 'billingItem' , 'nextInvoiceTotalRecurringAmount' )
54- if cost is not None :
55- cost = f"${ cost } "
56- else :
57- cost = "$0.0"
66+ cost = utils .lookup (item , 'billingItem' , 'nextInvoiceTotalRecurringAmount' )
67+ if cost is not None :
68+ cost = f"${ cost } "
69+ else :
70+ cost = "$0.0"
5871
59- deletion = utils .clean_time (item .get ('endDate' ))
72+ deletion = utils .clean_time (item .get ('endDate' ))
73+ if deletion == '' :
74+ deletion = formatting .blank ()
6075
61- if deletion == '' :
62- deletion = formatting .blank ()
76+ table .add_row ([id_bandwidth , name , region , servers , allocation , current , projected , cost , deletion ])
6377
64- table .add_row ([id_bandwidth , name , region , servers , allocation , current , projected , cost , deletion ])
78+ end_m = time .perf_counter ()
79+ LOGGER .debug ('Total API Call time %s' , end_m - start_m )
6580 env .fout (table )
0 commit comments