Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a flags in the report bandwidth #1420

Merged
merged 8 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SoftLayer/CLI/config/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from SoftLayer.CLI import formatting


def get_api_key(client, username, secret):
def get_api_key(client, username, secret): # pylint: disable=inconsistent-return-statements
"""Attempts API-Key and password auth to get an API key.

This will also generate an API key if one doesn't exist
Expand Down
1 change: 1 addition & 0 deletions SoftLayer/CLI/custom_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import click


# pylint: disable=inconsistent-return-statements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to disable in the method convert as:
def convert(self, value, param, ctx): # pylint: disable=R1710

class NetworkParamType(click.ParamType):
"""Validates a network parameter type and converts to a tuple.

Expand Down
58 changes: 38 additions & 20 deletions SoftLayer/CLI/report/bandwidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ def _get_virtual_bandwidth(env, start, end):
@click.option(
'--start',
callback=_validate_datetime,
default=(
datetime.datetime.now() - datetime.timedelta(days=30)
).strftime('%Y-%m-%d'),
default=(datetime.datetime.now() - datetime.timedelta(days=30)
).strftime('%Y-%m-%d'),
help="datetime in the format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'")
@click.option(
'--end',
Expand All @@ -187,8 +186,14 @@ def _get_virtual_bandwidth(env, start, end):
@click.option('--sortby', help='Column to sort by',
default='hostname',
show_default=True)
@click.option('--virtual', is_flag=True,
help='Show the all bandwidth summary for each virtual server',
default=False)
@click.option('--server', is_flag=True,
help='show the all bandwidth summary for each hardware server',
default=False)
@environment.pass_env
def cli(env, start, end, sortby):
def cli(env, start, end, sortby, virtual, server):
"""Bandwidth report for every pool/server.

This reports on the total data transfered for each virtual sever, hardware
Expand All @@ -213,23 +218,36 @@ def f_type(key, results):
return (result['counter'] for result in results
if result['type'] == key)

def _input_to_table(item):
"Input metric data to table"
pub_in = int(sum(f_type('publicIn_net_octet', item['data'])))
pub_out = int(sum(f_type('publicOut_net_octet', item['data'])))
pri_in = int(sum(f_type('privateIn_net_octet', item['data'])))
pri_out = int(sum(f_type('privateOut_net_octet', item['data'])))
table.add_row([
item['type'],
item['name'],
formatting.b_to_gb(pub_in),
formatting.b_to_gb(pub_out),
formatting.b_to_gb(pri_in),
formatting.b_to_gb(pri_out),
item.get('pool') or formatting.blank(),
])

try:
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
_get_virtual_bandwidth(env, start, end),
_get_hardware_bandwidth(env, start, end)):
pub_in = int(sum(f_type('publicIn_net_octet', item['data'])))
pub_out = int(sum(f_type('publicOut_net_octet', item['data'])))
pri_in = int(sum(f_type('privateIn_net_octet', item['data'])))
pri_out = int(sum(f_type('privateOut_net_octet', item['data'])))
table.add_row([
item['type'],
item['name'],
formatting.b_to_gb(pub_in),
formatting.b_to_gb(pub_out),
formatting.b_to_gb(pri_in),
formatting.b_to_gb(pri_out),
item.get('pool') or formatting.blank(),
])
if virtual:
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
_get_virtual_bandwidth(env, start, end)):
_input_to_table(item)
elif server:
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
_get_hardware_bandwidth(env, start, end)):
_input_to_table(item)
else:
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
_get_hardware_bandwidth(env, start, end),
_get_virtual_bandwidth(env, start, end)):
_input_to_table(item)
except KeyboardInterrupt:
env.err("Printing collected results and then aborting.")

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from setuptools import setup, find_packages

# pylint: disable=inconsistent-return-statements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to disable in the method get_api_key as:
def get_api_key(client, username, secret): # pylint: disable=R1710


DESCRIPTION = "A library for SoftLayer's API"

if os.path.exists('README.rst'):
Expand Down
Loading