Skip to content

Commit 0584690

Browse files
Ramkishor ChaladiRamkishor Chaladi
authored andcommitted
added --cache-description sub feature of cdn edit
1 parent bd95421 commit 0584690

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
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/managers/cdn.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def end_date(self):
175175
return self._end_date
176176

177177
def edit(self, identifier, header=None, http_port=None, https_port=None, origin=None,
178-
respect_headers=None, cache=None, performance_configuration=None):
178+
respect_headers=None, cache=None, cache_description=None, performance_configuration=None):
179179
"""Edit the cdn object.
180180
181181
:param string identifier: The CDN identifier.
@@ -223,12 +223,12 @@ def edit(self, identifier, header=None, http_port=None, https_port=None, origin=
223223
if respect_headers:
224224
config['respectHeaders'] = respect_headers
225225

226-
if cache:
226+
if cache or cache_description:
227227
if 'include-specified' in cache['cacheKeyQueryRule']:
228-
cache_key_rule = self.get_cache_key_query_rule('include', cache)
228+
cache_key_rule = self.get_cache_key_query_rule('include', cache_description)
229229
config['cacheKeyQueryRule'] = cache_key_rule
230230
elif 'ignore-specified' in cache['cacheKeyQueryRule']:
231-
cache_key_rule = self.get_cache_key_query_rule('ignore', cache)
231+
cache_key_rule = self.get_cache_key_query_rule('ignore', cache_description)
232232
config['cacheKeyQueryRule'] = cache_key_rule
233233
else:
234234
config['cacheKeyQueryRule'] = cache['cacheKeyQueryRule']
@@ -254,18 +254,18 @@ def _get_ids_from_hostname(self, hostname):
254254
return result
255255

256256
@staticmethod
257-
def get_cache_key_query_rule(cache_type, cache):
257+
def get_cache_key_query_rule(cache_type, cache_description):
258258
"""Get the cdn object detail.
259259
260260
:param string cache_type: Cache type.
261261
:param cache: Cache description.
262262
263263
:return: string value.
264264
"""
265-
if 'description' not in cache:
265+
if cache_description is None:
266266
raise SoftLayer.SoftLayerError('Please add a description to be able to update the'
267267
' cache.')
268-
cache_result = '%s: %s' % (cache_type, cache['description'])
268+
cache_result = '%s: %s' % (cache_type, cache_description)
269269

270270
return cache_result
271271

0 commit comments

Comments
 (0)