55
66 :license: MIT, see LICENSE for more details.
77"""
8-
8+ import SoftLayer
99from SoftLayer import utils
1010
1111
12+ # pylint: disable=no-self-use,too-many-lines,too-many-instance-attributes
13+
14+
1215class CDNManager (utils .IdentifierMixin , object ):
1316 """Manage Content Delivery Networks in the account.
1417
@@ -27,6 +30,7 @@ def __init__(self, client):
2730 self .cdn_path = self .client ['SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path' ]
2831 self .cdn_metrics = self .client ['Network_CdnMarketplace_Metrics' ]
2932 self .cdn_purge = self .client ['SoftLayer_Network_CdnMarketplace_Configuration_Cache_Purge' ]
33+ self .resolvers = [self ._get_ids_from_hostname ]
3034
3135 def list_cdn (self , ** kwargs ):
3236 """Lists Content Delivery Networks for the active user.
@@ -170,3 +174,90 @@ def start_data(self):
170174 def end_date (self ):
171175 """Retrieve the cdn usage metric end date."""
172176 return self ._end_date
177+
178+ def edit (self , identifier , header = None , http_port = None , origin = None ,
179+ respect_headers = None , cache = None , performance_configuration = None ):
180+ """Edit the cdn object.
181+
182+ :param string identifier: The CDN identifier.
183+ :param header: The cdn Host header.
184+ :param http_port: The cdn HTTP port.
185+ :param origin: The cdn Origin server address.
186+ :param respect_headers: The cdn Respect headers.
187+ :param cache: The cdn Cache key optimization.
188+ :param performance_configuration: The cdn performance configuration.
189+
190+ :returns: SoftLayer_Container_Network_CdnMarketplace_Configuration_Mapping[].
191+ """
192+ cdn_instance_detail = self .get_cdn (str (identifier ))
193+
194+ config = {
195+ 'uniqueId' : cdn_instance_detail .get ('uniqueId' ),
196+ 'originType' : cdn_instance_detail .get ('originType' ),
197+ 'protocol' : cdn_instance_detail .get ('protocol' ),
198+ 'path' : cdn_instance_detail .get ('path' ),
199+ 'vendorName' : cdn_instance_detail .get ('vendorName' ),
200+ 'cname' : cdn_instance_detail .get ('cname' ),
201+ 'domain' : cdn_instance_detail .get ('domain' ),
202+ 'httpPort' : cdn_instance_detail .get ('httpPort' ),
203+ 'origin' : cdn_instance_detail .get ('originHost' ),
204+ 'header' : cdn_instance_detail .get ('header' )
205+ }
206+
207+ if header :
208+ config ['header' ] = header
209+
210+ if http_port :
211+ config ['httpPort' ] = http_port
212+
213+ if origin :
214+ config ['origin' ] = origin
215+
216+ if respect_headers :
217+ config ['respectHeaders' ] = respect_headers
218+
219+ if cache :
220+ if 'include-specified' in cache ['cacheKeyQueryRule' ]:
221+ cache_key_rule = self .get_cache_key_query_rule ('include' , cache )
222+ config ['cacheKeyQueryRule' ] = cache_key_rule
223+ elif 'ignore-specified' in cache ['cacheKeyQueryRule' ]:
224+ cache_key_rule = self .get_cache_key_query_rule ('ignore' , cache )
225+ config ['cacheKeyQueryRule' ] = cache_key_rule
226+ else :
227+ config ['cacheKeyQueryRule' ] = cache ['cacheKeyQueryRule' ]
228+
229+ if performance_configuration :
230+ config ['performanceConfiguration' ] = performance_configuration
231+
232+ return self .cdn_configuration .updateDomainMapping (config )
233+
234+ def _get_ids_from_hostname (self , hostname ):
235+ """Get the cdn object detail.
236+
237+ :param string hostname: The CDN identifier.
238+ :returns: SoftLayer_Container_Network_CdnMarketplace_Configuration_Mapping[].
239+ """
240+ result = []
241+ cdn_list = self .cdn_configuration .listDomainMappings ()
242+ for cdn in cdn_list :
243+ if cdn .get ('domain' , '' ).lower () == hostname .lower ():
244+ result .append (cdn .get ('uniqueId' ))
245+ break
246+
247+ return result
248+
249+ @staticmethod
250+ def get_cache_key_query_rule (cache_type , cache ):
251+ """Get the cdn object detail.
252+
253+ :param string cache_type: Cache type.
254+ :param cache: Cache description.
255+
256+ :return: string value.
257+ """
258+ if 'description' not in cache :
259+ raise SoftLayer .SoftLayerError ('Please add a description to be able to update the'
260+ ' cache.' )
261+ cache_result = '%s: %s' % (cache_type , cache ['description' ])
262+
263+ return cache_result
0 commit comments