-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathakamai-clear-rest.py
More file actions
46 lines (40 loc) · 1.83 KB
/
Copy pathakamai-clear-rest.py
File metadata and controls
46 lines (40 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
import json
import argparse
import requests
import time
ccu_base = "https://api.ccu.akamai.com"
ccu_endpoint = ccu_base+"/ccu/v2/queues/default"
headers = {'content-type': 'application/json'}
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--cpcode", help="CP code to clear")
group.add_argument("--object", help="Object to clear (can specify multiple times)", action='append')
parser.add_argument("--user", help="Akamai user", required=True)
parser.add_argument("--passwd", help="Akamai password", required=True)
args = parser.parse_args()
if args.cpcode is not None:
postdata = json.dumps({'type': 'cpcode', 'objects': [args.cpcode]})
else:
postdata = json.dumps({'objects': args.object})
r = requests.post(ccu_endpoint, data=postdata, headers=headers, auth=(args.user, args.passwd))
if r.encoding is not None:
print "Error, unexpected data received:\n ",r.text
exit(1)
else:
resp = json.loads(r.text)
if resp['httpStatus'] < 200 or resp['httpStatus'] > 299:
print "Error, request not submitted\n\thttpStatus: ", resp['httpStatus'], "\n\ttitle: ", resp['title'], "\n\tdetail: ", resp['detail'], "\n\tdescribedBy: ", resp['describedBy']
exit(1)
else:
print "Request submitted OK\n\tEstimated time to clear: ", resp['estimatedSeconds']/60, "minutes\n\tCheck URL: ", ccu_base+resp['progressUri']
while True:
req2 = (ccu_base + resp['progressUri'])
r = requests.get(req2, headers=headers, auth=(args.user, args.passwd))
resp = json.loads(r.text)
if resp['purgeStatus'] == 'Done':
print 'purge complete,flush cdn success!'
exit(0)
else:
print time.ctime() + '\tpurge still running...'
time.sleep(30)