Skip to content

Commit 0f409be

Browse files
author
Fernando Ojeda
committed
Refactor code review.
1 parent 721442d commit 0f409be

File tree

6 files changed

+22
-15
lines changed

6 files changed

+22
-15
lines changed

SoftLayer/CLI/cdn/detail.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010

1111
@click.command()
1212
@click.argument('unique_id')
13-
@click.option('--last_days',
14-
default=30,
15-
help='cdn overview last days less than 90 days, because it is the maximum e.g 7, 15, 30, 60, 89')
13+
@click.option('--history',
14+
default=30, type=click.IntRange(1, 89),
15+
help='Bandwidth, Hits, Ratio counted over history number of days ago. 89 is the maximum. ')
1616
@environment.pass_env
17-
def cli(env, unique_id, last_days):
17+
def cli(env, unique_id, history):
1818
"""Detail a CDN Account."""
1919

2020
manager = SoftLayer.CDNManager(env.client)
2121

2222
cdn_mapping = manager.get_cdn(unique_id)
23-
cdn_metrics = manager.get_usage_metrics(unique_id, days=last_days)
23+
cdn_metrics = manager.get_usage_metrics(unique_id, history=history)
2424

2525
# usage metrics
26-
total_bandwidth = str(cdn_metrics['totals'][0]) + " GB"
27-
total_hits = str(cdn_metrics['totals'][1])
28-
hit_radio = str(cdn_metrics['totals'][2]) + " %"
26+
total_bandwidth = "%s GB" % cdn_metrics['totals'][0]
27+
total_hits = cdn_metrics['totals'][1]
28+
hit_ratio = "%s %%" % cdn_metrics['totals'][2]
2929

3030
table = formatting.KeyValueTable(['name', 'value'])
3131
table.align['name'] = 'r'
@@ -41,6 +41,6 @@ def cli(env, unique_id, last_days):
4141
table.add_row(['status', cdn_mapping['status']])
4242
table.add_row(['total_bandwidth', total_bandwidth])
4343
table.add_row(['total_hits', total_hits])
44-
table.add_row(['hit_radio', hit_radio])
44+
table.add_row(['hit_radio', hit_ratio])
4545

4646
env.fout(table)

SoftLayer/CLI/cdn/origin_add.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@
5151
@environment.pass_env
5252
def cli(env, unique_id, origin, path, origin_type, header,
5353
bucket_name, port, protocol, optimize_for, extensions, cache_query):
54-
"""Create an origin path for an existing CDN mapping."""
54+
"""Create an origin path for an existing CDN mapping.
55+
56+
For more information see the following documentation: \n
57+
https://cloud.ibm.com/docs/infrastructure/CDN?topic=CDN-manage-your-cdn#adding-origin-path-details
58+
"""
5559

5660
manager = SoftLayer.CDNManager(env.client)
5761

SoftLayer/CLI/cdn/purge.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def cli(env, unique_id, path):
1717
1818
Example:
1919
slcli cdn purge 9779455 /article/file.txt
20+
21+
For more information see the following documentation: \n
22+
https://cloud.ibm.com/docs/infrastructure/CDN?topic=CDN-manage-your-cdn#purging-cached-content
2023
"""
2124

2225
manager = SoftLayer.CDNManager(env.client)

SoftLayer/managers/cdn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,18 @@ def purge_content(self, unique_id, path):
137137

138138
return self.cdn_purge.createPurge(unique_id, path)
139139

140-
def get_usage_metrics(self, unique_id, days=30, frequency="aggregate"):
140+
def get_usage_metrics(self, unique_id, history=30, frequency="aggregate"):
141141
"""Retrieves the cdn usage metrics.
142142
143143
It uses the 'days' argument if start_date and end_date are None.
144144
145145
:param int unique_id: The CDN uniqueId from which the usage metrics will be obtained.
146-
:param int days: Last N days, default days is 30.
146+
:param int history: Last N days, default days is 30.
147147
:param str frequency: It can be day, week, month and aggregate. The default is "aggregate".
148148
:returns: A Container_Network_CdnMarketplace_Metrics object
149149
"""
150150

151-
_start = utils.days_to_datetime(days)
151+
_start = utils.days_to_datetime(history)
152152
_end = utils.days_to_datetime(0)
153153

154154
_start_date = utils.timestamp(_start)

tests/CLI/modules/cdn_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_list_accounts(self):
2626
)
2727

2828
def test_detail_account(self):
29-
result = self.run_command(['cdn', 'detail', '--last_days=30', '1245'])
29+
result = self.run_command(['cdn', 'detail', '--history=30', '1245'])
3030

3131
self.assert_no_fail(result)
3232
self.assertEqual(json.loads(result.output),

tests/managers/cdn_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_detail_cdn(self):
2929
args=args)
3030

3131
def test_detail_usage_metric(self):
32-
self.cdn_client.get_usage_metrics(12345, days=30, frequency="aggregate")
32+
self.cdn_client.get_usage_metrics(12345, history=30, frequency="aggregate")
3333

3434
_start = utils.days_to_datetime(30)
3535
_end = utils.days_to_datetime(0)

0 commit comments

Comments
 (0)