Skip to content

Commit b4e6d4c

Browse files
Merge pull request #1151 from FernandoOjeda/fo_cdn
- Replaces legacy swift cdn with IBM Cloud Object Storage cdn
2 parents 0803951 + 0f409be commit b4e6d4c

18 files changed

+542
-378
lines changed

SoftLayer/CLI/cdn/detail.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,38 @@
99

1010

1111
@click.command()
12-
@click.argument('account_id')
12+
@click.argument('unique_id')
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. ')
1316
@environment.pass_env
14-
def cli(env, account_id):
17+
def cli(env, unique_id, history):
1518
"""Detail a CDN Account."""
1619

1720
manager = SoftLayer.CDNManager(env.client)
18-
account = manager.get_account(account_id)
21+
22+
cdn_mapping = manager.get_cdn(unique_id)
23+
cdn_metrics = manager.get_usage_metrics(unique_id, history=history)
24+
25+
# usage metrics
26+
total_bandwidth = "%s GB" % cdn_metrics['totals'][0]
27+
total_hits = cdn_metrics['totals'][1]
28+
hit_ratio = "%s %%" % cdn_metrics['totals'][2]
1929

2030
table = formatting.KeyValueTable(['name', 'value'])
2131
table.align['name'] = 'r'
2232
table.align['value'] = 'l'
2333

24-
table.add_row(['id', account['id']])
25-
table.add_row(['account_name', account['cdnAccountName']])
26-
table.add_row(['type', account['cdnSolutionName']])
27-
table.add_row(['status', account['status']['name']])
28-
table.add_row(['created', account['createDate']])
29-
table.add_row(['notes',
30-
account.get('cdnAccountNote', formatting.blank())])
34+
table.add_row(['unique_id', cdn_mapping['uniqueId']])
35+
table.add_row(['hostname', cdn_mapping['domain']])
36+
table.add_row(['protocol', cdn_mapping['protocol']])
37+
table.add_row(['origin', cdn_mapping['originHost']])
38+
table.add_row(['origin_type', cdn_mapping['originType']])
39+
table.add_row(['path', cdn_mapping['path']])
40+
table.add_row(['provider', cdn_mapping['vendorName']])
41+
table.add_row(['status', cdn_mapping['status']])
42+
table.add_row(['total_bandwidth', total_bandwidth])
43+
table.add_row(['total_hits', total_hits])
44+
table.add_row(['hit_radio', hit_ratio])
3145

3246
env.fout(table)

SoftLayer/CLI/cdn/list.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,33 @@
1111
@click.command()
1212
@click.option('--sortby',
1313
help='Column to sort by',
14-
type=click.Choice(['id',
15-
'datacenter',
16-
'host',
17-
'cores',
18-
'memory',
19-
'primary_ip',
20-
'backend_ip']))
14+
type=click.Choice(['unique_id',
15+
'domain',
16+
'origin',
17+
'vendor',
18+
'cname',
19+
'status']))
2120
@environment.pass_env
2221
def cli(env, sortby):
2322
"""List all CDN accounts."""
2423

2524
manager = SoftLayer.CDNManager(env.client)
26-
accounts = manager.list_accounts()
25+
accounts = manager.list_cdn()
2726

28-
table = formatting.Table(['id',
29-
'account_name',
30-
'type',
31-
'created',
32-
'notes'])
27+
table = formatting.Table(['unique_id',
28+
'domain',
29+
'origin',
30+
'vendor',
31+
'cname',
32+
'status'])
3333
for account in accounts:
3434
table.add_row([
35-
account['id'],
36-
account['cdnAccountName'],
37-
account['cdnSolutionName'],
38-
account['createDate'],
39-
account.get('cdnAccountNote', formatting.blank())
35+
account['uniqueId'],
36+
account['domain'],
37+
account['originHost'],
38+
account['vendorName'],
39+
account['cname'],
40+
account['status']
4041
])
4142

4243
table.sortby = sortby

SoftLayer/CLI/cdn/load.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

SoftLayer/CLI/cdn/origin_add.py

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,82 @@
55

66
import SoftLayer
77
from SoftLayer.CLI import environment
8-
9-
# pylint: disable=redefined-builtin
8+
from SoftLayer.CLI import exceptions
9+
from SoftLayer.CLI import formatting
1010

1111

1212
@click.command()
13-
@click.argument('account_id')
14-
@click.argument('content_url')
15-
@click.option('--type',
16-
help='The media type for this mapping (http, flash, wm, ...)',
13+
@click.argument('unique_id')
14+
@click.argument('origin')
15+
@click.argument('path')
16+
@click.option('--origin-type', '-t',
17+
type=click.Choice(['server', 'storage']),
18+
help='The origin type.',
19+
default='server',
20+
show_default=True)
21+
@click.option('--header', '-H',
22+
type=click.STRING,
23+
help='The host header to communicate with the origin.')
24+
@click.option('--bucket-name', '-b',
25+
type=click.STRING,
26+
help="The name of the available resource [required if --origin-type=storage]")
27+
@click.option('--port', '-p',
28+
type=click.INT,
29+
help="The http port number.",
30+
default=80,
31+
show_default=True)
32+
@click.option('--protocol', '-P',
33+
type=click.STRING,
34+
help="The protocol used by the origin.",
1735
default='http',
1836
show_default=True)
19-
@click.option('--cname',
20-
help='An optional CNAME to attach to the mapping')
37+
@click.option('--optimize-for', '-o',
38+
type=click.Choice(['web', 'video', 'file']),
39+
help="Performance configuration",
40+
default='web',
41+
show_default=True)
42+
@click.option('--extensions', '-e',
43+
type=click.STRING,
44+
help="File extensions that can be stored in the CDN, example: 'jpg, png, pdf'")
45+
@click.option('--cache-query', '-c',
46+
type=click.STRING,
47+
help="Cache query rules with the following formats:\n"
48+
"'ignore-all', 'include: <query-names>', 'ignore: <query-names>'",
49+
default="include-all",
50+
show_default=True)
2151
@environment.pass_env
22-
def cli(env, account_id, content_url, type, cname):
23-
"""Create an origin pull mapping."""
52+
def cli(env, unique_id, origin, path, origin_type, header,
53+
bucket_name, port, protocol, optimize_for, extensions, cache_query):
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+
"""
2459

2560
manager = SoftLayer.CDNManager(env.client)
26-
manager.add_origin(account_id, type, content_url, cname)
61+
62+
if origin_type == 'storage' and not bucket_name:
63+
raise exceptions.ArgumentError('[-b | --bucket-name] is required when [-t | --origin-type] is "storage"')
64+
65+
result = manager.add_origin(unique_id, origin, path, origin_type=origin_type,
66+
header=header, port=port, protocol=protocol,
67+
bucket_name=bucket_name, file_extensions=extensions,
68+
optimize_for=optimize_for, cache_query=cache_query)
69+
70+
table = formatting.Table(['Item', 'Value'])
71+
table.align['Item'] = 'r'
72+
table.align['Value'] = 'r'
73+
74+
table.add_row(['CDN Unique ID', result['mappingUniqueId']])
75+
76+
if origin_type == 'storage':
77+
table.add_row(['Bucket Name', result['bucketName']])
78+
79+
table.add_row(['Origin', result['origin']])
80+
table.add_row(['Origin Type', result['originType']])
81+
table.add_row(['Path', result['path']])
82+
table.add_row(['Port', result['httpPort']])
83+
table.add_row(['Configuration', result['performanceConfiguration']])
84+
table.add_row(['Status', result['status']])
85+
86+
env.fout(table)

SoftLayer/CLI/cdn/origin_list.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99

1010

1111
@click.command()
12-
@click.argument('account_id')
12+
@click.argument('unique_id')
1313
@environment.pass_env
14-
def cli(env, account_id):
15-
"""List origin pull mappings."""
14+
def cli(env, unique_id):
15+
"""List origin path for an existing CDN mapping."""
1616

1717
manager = SoftLayer.CDNManager(env.client)
18-
origins = manager.get_origins(account_id)
18+
origins = manager.get_origins(unique_id)
1919

20-
table = formatting.Table(['id', 'media_type', 'cname', 'origin_url'])
20+
table = formatting.Table(['Path', 'Origin', 'HTTP Port', 'Status'])
2121

2222
for origin in origins:
23-
table.add_row([origin['id'],
24-
origin['mediaType'],
25-
origin.get('cname', formatting.blank()),
26-
origin['originUrl']])
23+
table.add_row([origin['path'],
24+
origin['origin'],
25+
origin['httpPort'],
26+
origin['status']])
2727

2828
env.fout(table)

SoftLayer/CLI/cdn/origin_remove.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99

1010
@click.command()
11-
@click.argument('account_id')
12-
@click.argument('origin_id')
11+
@click.argument('unique_id')
12+
@click.argument('origin_path')
1313
@environment.pass_env
14-
def cli(env, account_id, origin_id):
15-
"""Remove an origin pull mapping."""
14+
def cli(env, unique_id, origin_path):
15+
"""Removes an origin path for an existing CDN mapping."""
1616

1717
manager = SoftLayer.CDNManager(env.client)
18-
manager.remove_origin(account_id, origin_id)
18+
manager.remove_origin(unique_id, origin_path)
19+
20+
click.secho("Origin with path %s has been deleted" % origin_path, fg='green')

SoftLayer/CLI/cdn/purge.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,30 @@
99

1010

1111
@click.command()
12-
@click.argument('account_id')
13-
@click.argument('content_url', nargs=-1)
12+
@click.argument('unique_id')
13+
@click.argument('path')
1414
@environment.pass_env
15-
def cli(env, account_id, content_url):
16-
"""Purge cached files from all edge nodes.
15+
def cli(env, unique_id, path):
16+
"""Creates a purge record and also initiates the purge call.
1717
18-
Examples:
19-
slcli cdn purge 97794 http://example.com/cdn/file.txt
20-
slcli cdn purge 97794 http://example.com/cdn/file.txt https://dal01.example.softlayer.net/image.png
18+
Example:
19+
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
2123
"""
2224

2325
manager = SoftLayer.CDNManager(env.client)
24-
content_list = manager.purge_content(account_id, content_url)
26+
result = manager.purge_content(unique_id, path)
2527

26-
table = formatting.Table(['url', 'status'])
28+
table = formatting.Table(['Date', 'Path', 'Saved', 'Status'])
2729

28-
for content in content_list:
30+
for data in result:
2931
table.add_row([
30-
content['url'],
31-
content['statusCode']
32+
data['date'],
33+
data['path'],
34+
data['saved'],
35+
data['status']
3236
])
3337

3438
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
('cdn', 'SoftLayer.CLI.cdn'),
5555
('cdn:detail', 'SoftLayer.CLI.cdn.detail:cli'),
5656
('cdn:list', 'SoftLayer.CLI.cdn.list:cli'),
57-
('cdn:load', 'SoftLayer.CLI.cdn.load:cli'),
5857
('cdn:origin-add', 'SoftLayer.CLI.cdn.origin_add:cli'),
5958
('cdn:origin-list', 'SoftLayer.CLI.cdn.origin_list:cli'),
6059
('cdn:origin-remove', 'SoftLayer.CLI.cdn.origin_remove:cli'),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
createPurge = []
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
listDomainMappings = [
2+
{
3+
"cname": "cdnakauuiet7s6u6.cdnedge.bluemix.net",
4+
"domain": "test.example.com",
5+
"header": "test.example.com",
6+
"httpPort": 80,
7+
"originHost": "1.1.1.1",
8+
"originType": "HOST_SERVER",
9+
"path": "/",
10+
"protocol": "HTTP",
11+
"status": "CNAME_CONFIGURATION",
12+
"uniqueId": "9934111111111",
13+
"vendorName": "akamai"
14+
}
15+
]
16+
17+
listDomainMappingByUniqueId = [
18+
{
19+
"cname": "cdnakauuiet7s6u6.cdnedge.bluemix.net",
20+
"domain": "test.example.com",
21+
"header": "test.example.com",
22+
"httpPort": 80,
23+
"originHost": "1.1.1.1",
24+
"originType": "HOST_SERVER",
25+
"path": "/",
26+
"protocol": "HTTP",
27+
"status": "CNAME_CONFIGURATION",
28+
"uniqueId": "9934111111111",
29+
"vendorName": "akamai"
30+
}
31+
]

0 commit comments

Comments
 (0)