Skip to content

Commit e00e486

Browse files
Ramkishor ChaladiRamkishor Chaladi
authored andcommitted
added features cache description, Example, https port, compression, dynamic-path and prefetching
1 parent 1f2d7e9 commit e00e486

File tree

5 files changed

+99
-43
lines changed

5 files changed

+99
-43
lines changed

SoftLayer/CLI/cdn/origin_add.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
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]")
3230
@click.option('--https-port', '-s',
3331
type=click.INT,
34-
help="The https port number."
32+
help="The https port number. [http or https is required]"
3533
)
3634
@click.option('--protocol', '-P',
3735
type=click.STRING,
@@ -44,12 +42,15 @@
4442
default='web',
4543
show_default=True)
4644
@click.option('--dynamic-path', '-d',
47-
help="The path that Akamai edge servers periodically fetch the test object from. example = /detection-test-object.html")
45+
help="The path that Akamai edge servers periodically fetch the test object from."
46+
"example = /detection-test-object.html")
4847
@click.option('--compression', '-i',
4948
help="Enable or disable compression of JPEG images for requests over certain network conditions.",
49+
default='true',
5050
show_default=True)
5151
@click.option('--prefetching', '-g',
5252
help="Enable or disable the embedded object prefetching feature.",
53+
default='true',
5354
show_default=True)
5455
@click.option('--extensions', '-e',
5556
type=click.STRING,
@@ -62,7 +63,7 @@
6263
show_default=True)
6364
@environment.pass_env
6465
def cli(env, unique_id, origin, path, origin_type, header,
65-
bucket_name, port, https_port, protocol, optimize_for,
66+
bucket_name, http_port, https_port, protocol, optimize_for,
6667
dynamic_path, compression, prefetching,
6768
extensions, cache_query):
6869
"""Create an origin path for an existing CDN mapping.
@@ -77,7 +78,7 @@ def cli(env, unique_id, origin, path, origin_type, header,
7778
raise exceptions.ArgumentError('[-b | --bucket-name] is required when [-t | --origin-type] is "storage"')
7879

7980
result = manager.add_origin(unique_id, origin, path, dynamic_path, origin_type=origin_type,
80-
header=header, port=port, https_port=https_port, protocol=protocol,
81+
header=header, http_port=http_port, https_port=https_port, protocol=protocol,
8182
bucket_name=bucket_name, file_extensions=extensions,
8283
optimize_for=optimize_for,
8384
compression=compression, prefetching=prefetching,
@@ -94,8 +95,11 @@ def cli(env, unique_id, origin, path, origin_type, header,
9495

9596
table.add_row(['Origin', result['origin']])
9697
table.add_row(['Origin Type', result['originType']])
98+
table.add_row(['Header', result['header']])
9799
table.add_row(['Path', result['path']])
98-
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']])
99103
table.add_row(['Configuration', result['performanceConfiguration']])
100104
table.add_row(['Status', result['status']])
101105

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: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,34 @@ def get_origins(self, unique_id, **kwargs):
6565
return self.cdn_path.listOriginPath(unique_id, **kwargs)
6666

6767
def add_origin(self, unique_id, origin, path, dynamic_path, origin_type="server", header=None,
68-
port=80, https_port=None, protocol='http', bucket_name=None, file_extensions=None,
68+
http_port=80, https_port=None, protocol='http', bucket_name=None, file_extensions=None,
6969
optimize_for="web", compression=None, prefetching=None,
7070
cache_query="include all"):
7171
"""Creates an origin path for an existing CDN.
7272
7373
:param str unique_id: The unique ID associated with the CDN.
7474
: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
7577
:param str origin: ip address or hostname if origin_type=server, API endpoint for
7678
your S3 object storage if origin_type=storage
7779
:param str origin_type: it can be 'server' or 'storage' types.
7880
:param str header: the edge server uses the host header to communicate with the origin.
7981
It defaults to hostname. (optional)
80-
: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
8184
:param str protocol: the protocol of the origin (default: HTTP)
8285
:param str bucket_name: name of the available resource
8386
:param str file_extensions: file extensions that can be stored in the CDN, e.g. "jpg,png"
8487
:param str optimize_for: performance configuration, available options: web, video, and file where:
8588
86-
- 'web' = 'General web delivery'
87-
- 'video' = 'Video on demand optimization'
88-
- '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.
8996
:param str cache_query: rules with the following formats: 'include-all', 'ignore-all',
9097
'include: space separated query-names',
9198
'ignore: space separated query-names'.'
@@ -104,17 +111,19 @@ def add_origin(self, unique_id, origin, path, dynamic_path, origin_type="server"
104111
'path': path,
105112
'origin': origin,
106113
'originType': types.get(origin_type),
107-
'httpPort': port,
114+
'httpPort': http_port,
108115
'httpsPort': https_port,
109116
'protocol': protocol.upper(),
110-
'performanceConfiguration': performance_config.get(optimize_for, 'General web delivery'),
111-
'cacheKeyQueryRule': cache_query
117+
'performanceConfiguration': performance_config.get(optimize_for),
118+
'cacheKeyQueryRule': cache_query,
112119
}
113120

114121
if optimize_for == 'dynamic':
115-
new_origin['DetectionPath']= "/" + str(dynamic_path)
116-
new_origin['PrefetchEnabled']= prefetching
117-
new_origin['MobileImageCompressionEnabled']= compression
122+
new_origin['dynamicContentAcceleration'] = {
123+
'detectionPath': "/" + str(dynamic_path),
124+
'prefetchEnabled': bool(prefetching),
125+
'mobileImageCompressionEnabled': bool(compression)
126+
}
118127

119128
if header:
120129
new_origin['header'] = header

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'])

tests/managers/cdn_tests.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,42 +58,54 @@ def test_get_origins(self):
5858
'listOriginPath')
5959

6060
def test_add_origin(self):
61-
self.cdn_client.add_origin("12345", "10.10.10.1", "/example/videos", origin_type="server",
62-
header="test.example.com", port=80, protocol='http', optimize_for="web",
63-
cache_query="include all")
61+
self.cdn_client.add_origin("12345", "10.10.10.1", "/example/videos", dynamic_path="abc.html",
62+
origin_type="server", header="test.example.com", https_port=81,
63+
protocol='https', optimize_for="dynamic", compression=True,
64+
prefetching=True, cache_query="include all")
6465

6566
args = ({
6667
'uniqueId': "12345",
6768
'origin': '10.10.10.1',
6869
'path': '/example/videos',
69-
'originType': 'HOST_SERVER',
70-
'header': 'test.example.com',
71-
'httpPort': 80,
72-
'protocol': 'HTTP',
73-
'performanceConfiguration': 'General web delivery',
74-
'cacheKeyQueryRule': "include all"
70+
'originType': 'HOST_SERVER',
71+
'header': 'test.example.com',
72+
'httpPort': 80,
73+
'httpsPort': 81,
74+
'protocol': 'HTTPS',
75+
'performanceConfiguration': 'Dynamic content acceleration',
76+
'cacheKeyQueryRule': "include all",
77+
'dynamicContentAcceleration': {
78+
'detectionPath': "/abc.html",
79+
'prefetchEnabled': True,
80+
'mobileImageCompressionEnabled': True
81+
}
7582
},)
7683
self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path',
7784
'createOriginPath',
7885
args=args)
7986

8087
def test_add_origin_with_bucket_and_file_extension(self):
81-
self.cdn_client.add_origin("12345", "10.10.10.1", "/example/videos", origin_type="storage",
82-
bucket_name="test-bucket", file_extensions="jpg", header="test.example.com", port=80,
83-
protocol='http', optimize_for="web", cache_query="include all")
88+
self.cdn_client.add_origin("12345", "10.10.10.1", "/example/videos", dynamic_path="abc.html",
89+
origin_type="server", header="test.example.com", https_port=81,
90+
protocol='https', optimize_for="dynamic", compression=True,
91+
prefetching=True, cache_query="include all")
8492

8593
args = ({
8694
'uniqueId': "12345",
8795
'origin': '10.10.10.1',
8896
'path': '/example/videos',
89-
'originType': 'OBJECT_STORAGE',
90-
'header': 'test.example.com',
91-
'httpPort': 80,
92-
'protocol': 'HTTP',
93-
'bucketName': 'test-bucket',
94-
'fileExtension': 'jpg',
95-
'performanceConfiguration': 'General web delivery',
96-
'cacheKeyQueryRule': "include all"
97+
'originType': 'HOST_SERVER',
98+
'header': 'test.example.com',
99+
'httpPort': 80,
100+
'httpsPort': 81,
101+
'protocol': 'HTTPS',
102+
'performanceConfiguration': 'Dynamic content acceleration',
103+
'cacheKeyQueryRule': "include all",
104+
'dynamicContentAcceleration': {
105+
'detectionPath': "/abc.html",
106+
'prefetchEnabled': True,
107+
'mobileImageCompressionEnabled': True
108+
}
97109
},)
98110
self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path',
99111
'createOriginPath',

0 commit comments

Comments
 (0)