Skip to content

Commit 28002af

Browse files
Merge pull request #2054 from ramkishor-ch/issue_2019
Sub features and Example were missing in slcli cdn edit, slcli cdn origin-add
2 parents 882132b + e00e486 commit 28002af

File tree

6 files changed

+144
-59
lines changed

6 files changed

+144
-59
lines changed

SoftLayer/CLI/cdn/edit.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,25 @@
3131
type=click.Choice(['1', '0']),
3232
help="Respect headers. The value 1 is On and 0 is Off."
3333
)
34-
@click.option('--cache', '-c', multiple=True, type=str,
34+
@click.option('--cache', '-c', type=str,
3535
help="Cache key optimization. These are the valid options to choose: 'include-all', 'ignore-all', "
3636
"'include-specified', 'ignore-specified'. If you select 'include-specified' or 'ignore-specified' "
37-
"please add a description too using again --cache, "
38-
"e.g --cache=include-specified --cache=description."
37+
"please add to option --cache-description.\n"
38+
" e.g --cache=include-specified --cache-description=description."
39+
)
40+
@click.option('--cache-description', '-C', type=str,
41+
help="In cache option, if you select 'include-specified' or 'ignore-specified', "
42+
"please add a description too using this option.\n"
43+
"e.g --cache include-specified --cache-description description."
3944
)
4045
@click.option('--performance-configuration', '-p',
4146
type=click.Choice(['General web delivery', 'Large file optimization', 'Video on demand optimization']),
4247
help="Optimize for, General web delivery', 'Large file optimization', 'Video on demand optimization', "
4348
"the Dynamic content acceleration option is not added because this has a special configuration."
4449
)
4550
@environment.pass_env
46-
def cli(env, identifier, header, http_port, https_port, origin, respect_headers, cache, performance_configuration):
51+
def cli(env, identifier, header, http_port, https_port, origin, respect_headers, cache,
52+
cache_description, performance_configuration):
4753
"""Edit a CDN Account.
4854
4955
Note: You can use the hostname or uniqueId as IDENTIFIER.
@@ -53,15 +59,14 @@ def cli(env, identifier, header, http_port, https_port, origin, respect_headers,
5359
cdn_id = helpers.resolve_id(manager.resolve_ids, identifier, 'CDN')
5460

5561
cache_result = {}
56-
if cache:
62+
if cache or cache_description:
5763
if len(cache) > 1:
58-
cache_result['cacheKeyQueryRule'] = cache[0]
59-
cache_result['description'] = cache[1]
64+
cache_result['cacheKeyQueryRule'] = cache
6065
else:
6166
cache_result['cacheKeyQueryRule'] = cache[0]
6267

6368
cdn_result = manager.edit(cdn_id, header=header, http_port=http_port, https_port=https_port, origin=origin,
64-
respect_headers=respect_headers, cache=cache_result,
69+
respect_headers=respect_headers, cache=cache_result, cache_description=cache_description,
6570
performance_configuration=performance_configuration)
6671

6772
table = formatting.KeyValueTable(['name', 'value'])

SoftLayer/CLI/cdn/origin_add.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,34 @@
2424
@click.option('--bucket-name', '-b',
2525
type=click.STRING,
2626
help="The name of the available resource [required if --origin-type=storage]")
27-
@click.option('--port', '-p',
27+
@click.option('--http-port', '-p',
2828
type=click.INT,
29-
help="The http port number.",
30-
default=80,
31-
show_default=True)
29+
help="The http port number. [http or https is required]")
30+
@click.option('--https-port', '-s',
31+
type=click.INT,
32+
help="The https port number. [http or https is required]"
33+
)
3234
@click.option('--protocol', '-P',
3335
type=click.STRING,
3436
help="The protocol used by the origin.",
3537
default='http',
3638
show_default=True)
3739
@click.option('--optimize-for', '-o',
38-
type=click.Choice(['web', 'video', 'file']),
40+
type=click.Choice(['web', 'video', 'file', 'dynamic']),
3941
help="Performance configuration",
4042
default='web',
4143
show_default=True)
44+
@click.option('--dynamic-path', '-d',
45+
help="The path that Akamai edge servers periodically fetch the test object from."
46+
"example = /detection-test-object.html")
47+
@click.option('--compression', '-i',
48+
help="Enable or disable compression of JPEG images for requests over certain network conditions.",
49+
default='true',
50+
show_default=True)
51+
@click.option('--prefetching', '-g',
52+
help="Enable or disable the embedded object prefetching feature.",
53+
default='true',
54+
show_default=True)
4255
@click.option('--extensions', '-e',
4356
type=click.STRING,
4457
help="File extensions that can be stored in the CDN, example: 'jpg, png, pdf'")
@@ -50,7 +63,9 @@
5063
show_default=True)
5164
@environment.pass_env
5265
def cli(env, unique_id, origin, path, origin_type, header,
53-
bucket_name, port, protocol, optimize_for, extensions, cache_query):
66+
bucket_name, http_port, https_port, protocol, optimize_for,
67+
dynamic_path, compression, prefetching,
68+
extensions, cache_query):
5469
"""Create an origin path for an existing CDN mapping.
5570
5671
For more information see the following documentation: \n
@@ -62,10 +77,12 @@ def cli(env, unique_id, origin, path, origin_type, header,
6277
if origin_type == 'storage' and not bucket_name:
6378
raise exceptions.ArgumentError('[-b | --bucket-name] is required when [-t | --origin-type] is "storage"')
6479

65-
result = manager.add_origin(unique_id, origin, path, origin_type=origin_type,
66-
header=header, port=port, protocol=protocol,
80+
result = manager.add_origin(unique_id, origin, path, dynamic_path, origin_type=origin_type,
81+
header=header, http_port=http_port, https_port=https_port, protocol=protocol,
6782
bucket_name=bucket_name, file_extensions=extensions,
68-
optimize_for=optimize_for, cache_query=cache_query)
83+
optimize_for=optimize_for,
84+
compression=compression, prefetching=prefetching,
85+
cache_query=cache_query)
6986

7087
table = formatting.Table(['Item', 'Value'])
7188
table.align['Item'] = 'r'
@@ -78,8 +95,11 @@ def cli(env, unique_id, origin, path, origin_type, header,
7895

7996
table.add_row(['Origin', result['origin']])
8097
table.add_row(['Origin Type', result['originType']])
98+
table.add_row(['Header', result['header']])
8199
table.add_row(['Path', result['path']])
82-
table.add_row(['Port', result['httpPort']])
100+
table.add_row(['Http Port', result['httpPort']])
101+
table.add_row(['Https Port', result['httpsPort']])
102+
table.add_row(['Cache Key Rule', result['cacheKeyQueryRule']])
83103
table.add_row(['Configuration', result['performanceConfiguration']])
84104
table.add_row(['Status', result['status']])
85105

SoftLayer/fixtures/SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,23 @@
2121

2222
createOriginPath = [
2323
{
24-
"header": "test.example.com",
2524
"httpPort": 80,
25+
"httpsPort": 81,
2626
"mappingUniqueId": "993419389425697",
2727
"origin": "10.10.10.1",
2828
"originType": "HOST_SERVER",
29+
"header": "test.example.com",
2930
"path": "/example",
3031
"status": "RUNNING",
3132
"bucketName": "test-bucket",
3233
'fileExtension': 'jpg',
33-
"performanceConfiguration": "General web delivery"
34+
"performanceConfiguration": "Dynamic content acceleration",
35+
"dynamicContentAcceleration": {
36+
"detectionPath": "/abc.html",
37+
"prefetchEnabled": True,
38+
"mobileImageCompressionEnabled": True
39+
},
40+
"cacheKeyQueryRule": "include-all"
3441
}
3542
]
3643

SoftLayer/managers/cdn.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,35 @@ def get_origins(self, unique_id, **kwargs):
6464

6565
return self.cdn_path.listOriginPath(unique_id, **kwargs)
6666

67-
def add_origin(self, unique_id, origin, path, origin_type="server", header=None,
68-
port=80, protocol='http', bucket_name=None, file_extensions=None,
69-
optimize_for="web", cache_query="include all"):
67+
def add_origin(self, unique_id, origin, path, dynamic_path, origin_type="server", header=None,
68+
http_port=80, https_port=None, protocol='http', bucket_name=None, file_extensions=None,
69+
optimize_for="web", compression=None, prefetching=None,
70+
cache_query="include all"):
7071
"""Creates an origin path for an existing CDN.
7172
7273
:param str unique_id: The unique ID associated with the CDN.
7374
:param str path: relative path to the domain provided, e.g. "/articles/video"
75+
:param str dynamic_path: The path that Akamai edge servers periodically fetch the test object from.
76+
example = /detection-test-object.html
7477
:param str origin: ip address or hostname if origin_type=server, API endpoint for
7578
your S3 object storage if origin_type=storage
7679
:param str origin_type: it can be 'server' or 'storage' types.
7780
:param str header: the edge server uses the host header to communicate with the origin.
7881
It defaults to hostname. (optional)
79-
:param int port: the http port number (default: 80)
82+
:param int http_port: the http port number (default: 80)
83+
:param int https_port: the https port number
8084
:param str protocol: the protocol of the origin (default: HTTP)
8185
:param str bucket_name: name of the available resource
8286
:param str file_extensions: file extensions that can be stored in the CDN, e.g. "jpg,png"
8387
:param str optimize_for: performance configuration, available options: web, video, and file where:
8488
85-
- 'web' = 'General web delivery'
86-
- 'video' = 'Video on demand optimization'
87-
- 'file' = 'Large file optimization'
89+
- 'web' = 'General web delivery'
90+
- 'video' = 'Video on demand optimization'
91+
- 'file' = 'Large file optimization'
92+
- 'dynamic' = 'Dynamic content acceleration'
93+
:param bool compression: Enable or disable compression of JPEG images for requests over
94+
certain network conditions.
95+
:param bool prefetching: Enable or disable the embedded object prefetching feature.
8896
:param str cache_query: rules with the following formats: 'include-all', 'ignore-all',
8997
'include: space separated query-names',
9098
'ignore: space separated query-names'.'
@@ -94,20 +102,29 @@ def add_origin(self, unique_id, origin, path, origin_type="server", header=None,
94102
performance_config = {
95103
'web': 'General web delivery',
96104
'video': 'Video on demand optimization',
97-
'file': 'Large file optimization'
105+
'file': 'Large file optimization',
106+
"dynamic": "Dynamic content acceleration"
98107
}
99108

100109
new_origin = {
101110
'uniqueId': unique_id,
102111
'path': path,
103112
'origin': origin,
104113
'originType': types.get(origin_type),
105-
'httpPort': port,
114+
'httpPort': http_port,
115+
'httpsPort': https_port,
106116
'protocol': protocol.upper(),
107-
'performanceConfiguration': performance_config.get(optimize_for, 'General web delivery'),
108-
'cacheKeyQueryRule': cache_query
117+
'performanceConfiguration': performance_config.get(optimize_for),
118+
'cacheKeyQueryRule': cache_query,
109119
}
110120

121+
if optimize_for == 'dynamic':
122+
new_origin['dynamicContentAcceleration'] = {
123+
'detectionPath': "/" + str(dynamic_path),
124+
'prefetchEnabled': bool(prefetching),
125+
'mobileImageCompressionEnabled': bool(compression)
126+
}
127+
111128
if header:
112129
new_origin['header'] = header
113130

@@ -175,7 +192,7 @@ def end_date(self):
175192
return self._end_date
176193

177194
def edit(self, identifier, header=None, http_port=None, https_port=None, origin=None,
178-
respect_headers=None, cache=None, performance_configuration=None):
195+
respect_headers=None, cache=None, cache_description=None, performance_configuration=None):
179196
"""Edit the cdn object.
180197
181198
:param string identifier: The CDN identifier.
@@ -223,12 +240,12 @@ def edit(self, identifier, header=None, http_port=None, https_port=None, origin=
223240
if respect_headers:
224241
config['respectHeaders'] = respect_headers
225242

226-
if cache:
243+
if cache or cache_description:
227244
if 'include-specified' in cache['cacheKeyQueryRule']:
228-
cache_key_rule = self.get_cache_key_query_rule('include', cache)
245+
cache_key_rule = self.get_cache_key_query_rule('include', cache_description)
229246
config['cacheKeyQueryRule'] = cache_key_rule
230247
elif 'ignore-specified' in cache['cacheKeyQueryRule']:
231-
cache_key_rule = self.get_cache_key_query_rule('ignore', cache)
248+
cache_key_rule = self.get_cache_key_query_rule('ignore', cache_description)
232249
config['cacheKeyQueryRule'] = cache_key_rule
233250
else:
234251
config['cacheKeyQueryRule'] = cache['cacheKeyQueryRule']
@@ -254,18 +271,18 @@ def _get_ids_from_hostname(self, hostname):
254271
return result
255272

256273
@staticmethod
257-
def get_cache_key_query_rule(cache_type, cache):
274+
def get_cache_key_query_rule(cache_type, cache_description):
258275
"""Get the cdn object detail.
259276
260277
:param string cache_type: Cache type.
261278
:param cache: Cache description.
262279
263280
:return: string value.
264281
"""
265-
if 'description' not in cache:
282+
if cache_description is None:
266283
raise SoftLayer.SoftLayerError('Please add a description to be able to update the'
267284
' cache.')
268-
cache_result = '%s: %s' % (cache_type, cache['description'])
285+
cache_result = '%s: %s' % (cache_type, cache_description)
269286

270287
return cache_result
271288

tests/CLI/modules/cdn_tests.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,30 @@ def test_add_origin_server(self):
6666

6767
self.assert_no_fail(result)
6868

69+
def test_add_origin_server_dynamic(self):
70+
result = self.run_command(
71+
['cdn', 'origin-add', '-t', 'server', '-H=test.example.com', '-s', 81, '-o', 'dynamic', '-c=include-all',
72+
'-P', 'HTTPS', '-d', 'abc.html', '-g', True, '-i', True, '1234', '10.10.10.1', '/example/videos2', ])
73+
74+
self.assert_no_fail(result)
75+
6976
def test_add_origin_storage(self):
7077
result = self.run_command(['cdn', 'origin-add', '-t', 'storage', '-b=test-bucket', '-H=test.example.com',
7178
'-p', 80, '-o', 'web', '-c=include-all', '1234', '10.10.10.1', '/example/videos2'])
7279

7380
self.assert_no_fail(result)
7481

82+
def test_add_origin_storage_dynamic(self):
83+
result = self.run_command(['cdn', 'origin-add', '-t', 'storage', '-b=test-bucket', '-H=test.example.com',
84+
'-s', 81, '-o', 'dynamic', '-c=include-all', '1234', '10.10.10.1',
85+
'/example/videos2', '-g', True, '-i', True])
86+
87+
self.assert_no_fail(result)
88+
7589
def test_add_origin_without_storage(self):
7690
result = self.run_command(['cdn', 'origin-add', '-t', 'storage', '-H=test.example.com', '-p', 80,
77-
'-o', 'web', '-c=include-all', '1234', '10.10.10.1', '/example/videos2'])
91+
'-P', 'HTTPS', '-o', 'web', '-c=include-all',
92+
'1234', '10.10.10.1', '/example/videos2'])
7893

7994
self.assertEqual(result.exit_code, 2)
8095
self.assertIsInstance(result.exception, exceptions.ArgumentError)
@@ -86,6 +101,15 @@ def test_add_origin_storage_with_file_extensions(self):
86101

87102
self.assert_no_fail(result)
88103

104+
def test_add_origin_storage_with_file_extensions_dynamic(self):
105+
result = self.run_command(
106+
['cdn', 'origin-add', '-t', 'storage', '-b=test-bucket', '-e', 'jpg', '-H=test.example.com', '-s', 81,
107+
'-P', 'HTTPS', '-o', 'dynamic', '-d', 'abc.html', '-g', True, '-i', True,
108+
'-c=include-all', '1234', '10.10.10.1', '/example/videos2',
109+
])
110+
111+
self.assert_no_fail(result)
112+
89113
def test_remove_origin(self):
90114
result = self.run_command(['cdn', 'origin-remove', '1234',
91115
'/example1'])

0 commit comments

Comments
 (0)