Skip to content

Commit 3ef580e

Browse files
author
Fernando Ojeda
committed
Feature cdn network.
1 parent 33cfbfd commit 3ef580e

14 files changed

+462
-318
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('--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')
1316
@environment.pass_env
14-
def cli(env, account_id):
17+
def cli(env, unique_id, last_days):
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, days=last_days)
24+
25+
# 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]) + " %"
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_radio])
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/origin_add.py

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,78 @@
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."""
2455

2556
manager = SoftLayer.CDNManager(env.client)
26-
manager.add_origin(account_id, type, content_url, cname)
57+
58+
if origin_type == 'storage' and not bucket_name:
59+
raise exceptions.ArgumentError('[-b | --bucket-name] is required when [-t | --origin-type] is "storage"')
60+
61+
result = manager.add_origin(unique_id, origin, path, origin_type=origin_type,
62+
header=header, port=port, protocol=protocol,
63+
bucket_name=bucket_name, file_extensions=extensions,
64+
optimize_for=optimize_for, cache_query=cache_query)
65+
66+
table = formatting.Table(['Item', 'Value'])
67+
table.align['Item'] = 'r'
68+
table.align['Value'] = 'r'
69+
70+
table.add_row(['CDN Unique ID', result['mappingUniqueId']])
71+
72+
if origin_type == 'storage':
73+
table.add_row(['Bucket Name', result['bucketName']])
74+
75+
table.add_row(['Origin', result['origin']])
76+
table.add_row(['Origin Type', result['originType']])
77+
table.add_row(['Path', result['path']])
78+
table.add_row(['Port', result['httpPort']])
79+
table.add_row(['Configuration', result['performanceConfiguration']])
80+
table.add_row(['Status', result['status']])
81+
82+
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: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,27 @@
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
2120
"""
2221

2322
manager = SoftLayer.CDNManager(env.client)
24-
content_list = manager.purge_content(account_id, content_url)
23+
result = manager.purge_content(unique_id, path)
2524

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

28-
for content in content_list:
27+
for data in result:
2928
table.add_row([
30-
content['url'],
31-
content['statusCode']
29+
data['date'],
30+
data['path'],
31+
data['saved'],
32+
data['status']
3233
])
3334

3435
env.fout(table)
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+
]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
listOriginPath = [
2+
{
3+
"header": "test.example.com",
4+
"httpPort": 80,
5+
"mappingUniqueId": "993419389425697",
6+
"origin": "10.10.10.1",
7+
"originType": "HOST_SERVER",
8+
"path": "/example",
9+
"status": "RUNNING"
10+
},
11+
{
12+
"header": "test.example.com",
13+
"httpPort": 80,
14+
"mappingUniqueId": "993419389425697",
15+
"origin": "10.10.10.1",
16+
"originType": "HOST_SERVER",
17+
"path": "/example1",
18+
"status": "RUNNING"
19+
}
20+
]
21+
22+
createOriginPath = [
23+
{
24+
"header": "test.example.com",
25+
"httpPort": 80,
26+
"mappingUniqueId": "993419389425697",
27+
"origin": "10.10.10.1",
28+
"originType": "HOST_SERVER",
29+
"path": "/example",
30+
"status": "RUNNING",
31+
"performanceConfiguration": "General web delivery"
32+
}
33+
]
34+
35+
deleteOriginPath = "Origin with path /example/videos/* has been deleted"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
getMappingUsageMetrics = [
2+
{
3+
"names": [
4+
"TotalBandwidth",
5+
"TotalHits",
6+
"HitRatio"
7+
],
8+
"totals": [
9+
"0.0",
10+
"0",
11+
"0.0"
12+
],
13+
"type": "TOTALS"
14+
}
15+
]

0 commit comments

Comments
 (0)