Skip to content

Commit 4156741

Browse files
Merge pull request #1420 from caberos/issue1419
add a flags in the report bandwidth
2 parents 5e4fd4b + 427294d commit 4156741

File tree

5 files changed

+300
-30
lines changed

5 files changed

+300
-30
lines changed

SoftLayer/CLI/config/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from SoftLayer.CLI import formatting
1313

1414

15-
def get_api_key(client, username, secret):
15+
def get_api_key(client, username, secret): # pylint: disable=inconsistent-return-statements
1616
"""Attempts API-Key and password auth to get an API key.
1717
1818
This will also generate an API key if one doesn't exist

SoftLayer/CLI/custom_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import click
1010

1111

12+
# pylint: disable=inconsistent-return-statements
1213
class NetworkParamType(click.ParamType):
1314
"""Validates a network parameter type and converts to a tuple.
1415

SoftLayer/CLI/report/bandwidth.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ def _get_virtual_bandwidth(env, start, end):
175175
@click.option(
176176
'--start',
177177
callback=_validate_datetime,
178-
default=(
179-
datetime.datetime.now() - datetime.timedelta(days=30)
180-
).strftime('%Y-%m-%d'),
178+
default=(datetime.datetime.now() - datetime.timedelta(days=30)
179+
).strftime('%Y-%m-%d'),
181180
help="datetime in the format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'")
182181
@click.option(
183182
'--end',
@@ -187,8 +186,14 @@ def _get_virtual_bandwidth(env, start, end):
187186
@click.option('--sortby', help='Column to sort by',
188187
default='hostname',
189188
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)
190195
@environment.pass_env
191-
def cli(env, start, end, sortby):
196+
def cli(env, start, end, sortby, virtual, server):
192197
"""Bandwidth report for every pool/server.
193198
194199
This reports on the total data transfered for each virtual sever, hardware
@@ -213,23 +218,36 @@ def f_type(key, results):
213218
return (result['counter'] for result in results
214219
if result['type'] == key)
215220

221+
def _input_to_table(item):
222+
"Input metric data to table"
223+
pub_in = int(sum(f_type('publicIn_net_octet', item['data'])))
224+
pub_out = int(sum(f_type('publicOut_net_octet', item['data'])))
225+
pri_in = int(sum(f_type('privateIn_net_octet', item['data'])))
226+
pri_out = int(sum(f_type('privateOut_net_octet', item['data'])))
227+
table.add_row([
228+
item['type'],
229+
item['name'],
230+
formatting.b_to_gb(pub_in),
231+
formatting.b_to_gb(pub_out),
232+
formatting.b_to_gb(pri_in),
233+
formatting.b_to_gb(pri_out),
234+
item.get('pool') or formatting.blank(),
235+
])
236+
216237
try:
217-
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
218-
_get_virtual_bandwidth(env, start, end),
219-
_get_hardware_bandwidth(env, start, end)):
220-
pub_in = int(sum(f_type('publicIn_net_octet', item['data'])))
221-
pub_out = int(sum(f_type('publicOut_net_octet', item['data'])))
222-
pri_in = int(sum(f_type('privateIn_net_octet', item['data'])))
223-
pri_out = int(sum(f_type('privateOut_net_octet', item['data'])))
224-
table.add_row([
225-
item['type'],
226-
item['name'],
227-
formatting.b_to_gb(pub_in),
228-
formatting.b_to_gb(pub_out),
229-
formatting.b_to_gb(pri_in),
230-
formatting.b_to_gb(pri_out),
231-
item.get('pool') or formatting.blank(),
232-
])
238+
if virtual:
239+
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
240+
_get_virtual_bandwidth(env, start, end)):
241+
_input_to_table(item)
242+
elif server:
243+
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
244+
_get_hardware_bandwidth(env, start, end)):
245+
_input_to_table(item)
246+
else:
247+
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
248+
_get_hardware_bandwidth(env, start, end),
249+
_get_virtual_bandwidth(env, start, end)):
250+
_input_to_table(item)
233251
except KeyboardInterrupt:
234252
env.err("Printing collected results and then aborting.")
235253

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from setuptools import setup, find_packages
66

7+
# pylint: disable=inconsistent-return-statements
8+
79
DESCRIPTION = "A library for SoftLayer's API"
810

911
if os.path.exists('README.rst'):

0 commit comments

Comments
 (0)