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 ([
@@ -34,26 +41,34 @@ def cli(env):
3441 "Cost"
3542 ], title = "Bandwidth Pools" )
3643 table .align = 'l'
37- for item in items :
38- id_bandwidth = item .get ('id' )
39- name = item .get ('name' )
40- region = utils .lookup (item , 'locationGroup' , 'name' )
41- servers = manager .get_bandwidth_pool_counts (identifier = item .get ('id' ))
42- allocation = f"{ item .get ('totalBandwidthAllocated' , 0 )} GB"
43-
44- current = utils .lookup (item , 'billingCyclePublicBandwidthUsage' , 'amountOut' )
45- if current is not None :
46- current = f"{ current } GB"
47- else :
48- current = "0 GB"
49-
50- projected = f"{ item .get ('projectedPublicBandwidthUsage' , 0 )} GB"
51-
52- cost = utils .lookup (item , 'billingItem' , 'nextInvoiceTotalRecurringAmount' )
53- if cost is not None :
54- cost = f"${ cost } "
55- else :
56- cost = "$0.0"
57-
58- table .add_row ([id_bandwidth , name , region , servers , allocation , current , projected , cost ])
44+ start_m = time .perf_counter ()
45+
46+ with cf .ThreadPoolExecutor (max_workers = 5 ) as executor :
47+ for item , servers in zip (items , executor .map (manager .get_bandwidth_pool_counts ,
48+ [item .get ('id' ) for item in items ])):
49+
50+ id_bandwidth = item .get ('id' )
51+ name = item .get ('name' )
52+ region = utils .lookup (item , 'locationGroup' , 'name' )
53+
54+ allocation = f"{ item .get ('totalBandwidthAllocated' , 0 )} GB"
55+
56+ current = utils .lookup (item , 'billingCyclePublicBandwidthUsage' , 'amountOut' )
57+ if current is not None :
58+ current = f"{ current } GB"
59+ else :
60+ current = "0 GB"
61+
62+ projected = f"{ item .get ('projectedPublicBandwidthUsage' , 0 )} GB"
63+
64+ cost = utils .lookup (item , 'billingItem' , 'nextInvoiceTotalRecurringAmount' )
65+ if cost is not None :
66+ cost = f"${ cost } "
67+ else :
68+ cost = "$0.0"
69+
70+ table .add_row ([id_bandwidth , name , region , servers , allocation , current , projected , cost ])
71+
72+ end_m = time .perf_counter ()
73+ LOGGER .debug ('Total API Call time %s' , end_m - start_m )
5974 env .fout (table )
0 commit comments