def cdnetworks_flush(padname, path): import urllib import json from urlparse import urlparse parser = load_config() params = urllib.urlencode({ 'user': parser.get('main', 'cdn_user'), 'pass': parser.get('main', 'cdn_passwd'), 'pad': padname, 'type': 'item', 'output': 'json', 'path': path} ) try: cdnetworks_api = urlparse(parser.get('main', 'cdn_uri')) conn = httplib.HTTPSConnection(parser.get('main', 'proxy_host'), int(parser.get('main', 'proxy_port'))) conn.set_tunnel(cdnetworks_api.netloc, 443) conn.request('POST', cdnetworks_api.path, params) resp = conn.getresponse() if resp.status == 200: json_resp = json.loads(resp.read()) if json_resp['resultCode'] == 200: logger.info("flushing http://%s/%s (%s) done" % ( padname, path, cdnetworks_api.netloc )) else: logger.error("Error: flushing http://%s/%s (%s) failed (%d - %s)" % ( padname, path, cdnetworks_api.netloc, json_resp['resultCode'], json_resp['details'], )) else: logger.error("Error: %s" % resp.reason) except Exception, e: logger.error("Error: %s" % e)
def static_purge(domain_name, path): parser = load_config() for static_host in [x.strip() for x in parser.get('main', 'static_host').split(',')]: try: logger.debug('Connecting to %s' % static_host.split('.')[0]) conn = httplib.HTTPConnection(static_host, timeout=2) conn.request('PURGE', path, headers=dict(Host=domain_name)) resp = conn.getresponse() if resp.status == 200: logger.info("flushing http://%s/%s (%s) done" % ( domain_name, path, static_host.split('.')[0] )) else: logger.error("Error: %s" % resp.reason) except Exception, e: logger.error("Error: %s" % e)