|
9 | 9 | from SoftLayer.CLI import formatting |
10 | 10 | from SoftLayer import utils |
11 | 11 |
|
| 12 | +from pprint import pprint as pp |
12 | 13 |
|
13 | 14 | # pylint: disable=unused-argument |
14 | 15 | def _validate_datetime(ctx, param, value): |
@@ -47,23 +48,25 @@ def _get_pooled_bandwidth(env, start, end): |
47 | 48 | label='Calculating for bandwidth pools', |
48 | 49 | file=sys.stderr) as pools: |
49 | 50 | for pool in pools: |
50 | | - if not pool.get('metricTrackingObjectId'): |
51 | | - continue |
52 | | - |
53 | | - yield { |
54 | | - 'id': pool['id'], |
| 51 | + pool_detail = { |
| 52 | + 'id': pool.get('id'), |
55 | 53 | 'type': 'pool', |
56 | | - 'name': pool['name'], |
57 | | - 'data': env.client.call( |
| 54 | + 'name': pool.get('name'), |
| 55 | + 'data': [] |
| 56 | + } |
| 57 | + if pool.get('metricTrackingObjectId'): |
| 58 | + bw_data = env.client.call( |
58 | 59 | 'Metric_Tracking_Object', |
59 | 60 | 'getSummaryData', |
60 | 61 | start.strftime('%Y-%m-%d %H:%M:%S %Z'), |
61 | 62 | end.strftime('%Y-%m-%d %H:%M:%S %Z'), |
62 | 63 | types, |
63 | 64 | 300, |
64 | | - id=pool['metricTrackingObjectId'], |
65 | | - ), |
66 | | - } |
| 65 | + id=pool.get('metricTrackingObjectId'), |
| 66 | + ) |
| 67 | + pool_detail['data'] = bw_data |
| 68 | + |
| 69 | + yield pool_detail |
67 | 70 |
|
68 | 71 |
|
69 | 72 | def _get_hardware_bandwidth(env, start, end): |
@@ -172,28 +175,20 @@ def _get_virtual_bandwidth(env, start, end): |
172 | 175 |
|
173 | 176 |
|
174 | 177 | @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) |
| 178 | +@click.option('--start', callback=_validate_datetime, |
| 179 | + default=(datetime.datetime.now() - datetime.timedelta(days=30)).strftime('%Y-%m-%d'), |
| 180 | + help="datetime in the format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'") |
| 181 | +@click.option('--end', callback=_validate_datetime, default=datetime.datetime.now().strftime('%Y-%m-%d'), |
| 182 | + help="datetime in the format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'") |
| 183 | +@click.option('--sortby', help='Column to sort by', default='hostname', show_default=True) |
| 184 | +@click.option('--virtual', is_flag=True, default=False, |
| 185 | + help='Show only the bandwidth summary for each virtual server') |
| 186 | +@click.option('--server', is_flag=True, default=False, |
| 187 | + help='Show only the bandwidth summary for each hardware server') |
| 188 | +@click.option('--pool', is_flag=True, default=False, |
| 189 | + help='Show only the bandwidth pool summary.') |
195 | 190 | @environment.pass_env |
196 | | -def cli(env, start, end, sortby, virtual, server): |
| 191 | +def cli(env, start, end, sortby, virtual, server, pool): |
197 | 192 | """Bandwidth report for every pool/server. |
198 | 193 |
|
199 | 194 | This reports on the total data transfered for each virtual sever, hardware |
@@ -243,6 +238,9 @@ def _input_to_table(item): |
243 | 238 | for item in itertools.chain(_get_pooled_bandwidth(env, start, end), |
244 | 239 | _get_hardware_bandwidth(env, start, end)): |
245 | 240 | _input_to_table(item) |
| 241 | + elif pool: |
| 242 | + for item in _get_pooled_bandwidth(env, start, end): |
| 243 | + _input_to_table(item) |
246 | 244 | else: |
247 | 245 | for item in itertools.chain(_get_pooled_bandwidth(env, start, end), |
248 | 246 | _get_hardware_bandwidth(env, start, end), |
|
0 commit comments