@@ -47,23 +47,25 @@ def _get_pooled_bandwidth(env, start, end):
4747 label = 'Calculating for bandwidth pools' ,
4848 file = sys .stderr ) as pools :
4949 for pool in pools :
50- if not pool .get ('metricTrackingObjectId' ):
51- continue
52-
53- yield {
54- 'id' : pool ['id' ],
50+ pool_detail = {
51+ 'id' : pool .get ('id' ),
5552 'type' : 'pool' ,
56- 'name' : pool ['name' ],
57- 'data' : env .client .call (
53+ 'name' : pool .get ('name' ),
54+ 'data' : []
55+ }
56+ if pool .get ('metricTrackingObjectId' ):
57+ bw_data = env .client .call (
5858 'Metric_Tracking_Object' ,
5959 'getSummaryData' ,
6060 start .strftime ('%Y-%m-%d %H:%M:%S %Z' ),
6161 end .strftime ('%Y-%m-%d %H:%M:%S %Z' ),
6262 types ,
6363 300 ,
64- id = pool ['metricTrackingObjectId' ],
65- ),
66- }
64+ id = pool .get ('metricTrackingObjectId' ),
65+ )
66+ pool_detail ['data' ] = bw_data
67+
68+ yield pool_detail
6769
6870
6971def _get_hardware_bandwidth (env , start , end ):
@@ -172,28 +174,20 @@ def _get_virtual_bandwidth(env, start, end):
172174
173175
174176@click .command (short_help = "Bandwidth report for every pool/server" )
175- @click .option (
176- '--start' ,
177- callback = _validate_datetime ,
178- default = (datetime .datetime .now () - datetime .timedelta (days = 30 )
179- ).strftime ('%Y-%m-%d' ),
180- help = "datetime in the format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'" )
181- @click .option (
182- '--end' ,
183- callback = _validate_datetime ,
184- default = datetime .datetime .now ().strftime ('%Y-%m-%d' ),
185- help = "datetime in the format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'" )
186- @click .option ('--sortby' , help = 'Column to sort by' ,
187- default = 'hostname' ,
188- show_default = True )
189- @click .option ('--virtual' , is_flag = True ,
190- help = 'Show the all bandwidth summary for each virtual server' ,
191- default = False )
192- @click .option ('--server' , is_flag = True ,
193- help = 'show the all bandwidth summary for each hardware server' ,
194- default = False )
177+ @click .option ('--start' , callback = _validate_datetime ,
178+ default = (datetime .datetime .now () - datetime .timedelta (days = 30 )).strftime ('%Y-%m-%d' ),
179+ help = "datetime in the format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'" )
180+ @click .option ('--end' , callback = _validate_datetime , default = datetime .datetime .now ().strftime ('%Y-%m-%d' ),
181+ help = "datetime in the format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'" )
182+ @click .option ('--sortby' , help = 'Column to sort by' , default = 'hostname' , show_default = True )
183+ @click .option ('--virtual' , is_flag = True , default = False ,
184+ help = 'Show only the bandwidth summary for each virtual server' )
185+ @click .option ('--server' , is_flag = True , default = False ,
186+ help = 'Show only the bandwidth summary for each hardware server' )
187+ @click .option ('--pool' , is_flag = True , default = False ,
188+ help = 'Show only the bandwidth pool summary.' )
195189@environment .pass_env
196- def cli (env , start , end , sortby , virtual , server ):
190+ def cli (env , start , end , sortby , virtual , server , pool ):
197191 """Bandwidth report for every pool/server.
198192
199193 This reports on the total data transfered for each virtual sever, hardware
@@ -243,6 +237,9 @@ def _input_to_table(item):
243237 for item in itertools .chain (_get_pooled_bandwidth (env , start , end ),
244238 _get_hardware_bandwidth (env , start , end )):
245239 _input_to_table (item )
240+ elif pool :
241+ for item in _get_pooled_bandwidth (env , start , end ):
242+ _input_to_table (item )
246243 else :
247244 for item in itertools .chain (_get_pooled_bandwidth (env , start , end ),
248245 _get_hardware_bandwidth (env , start , end ),
0 commit comments