-
-
Notifications
You must be signed in to change notification settings - Fork 570
/
Copy patha10.py
executable file
·45 lines (37 loc) · 1.55 KB
/
a10.py
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
#
# v0.2
# ericc@a10networks.com
#
import json, urllib2, ssl
def axapi_auth(host, username, password):
base_uri = 'https://'+host
auth_payload = {"credentials": {"username": username, "password": password}}
r = axapi_action(base_uri + '/axapi/v3/auth', payload=auth_payload)
signature = json.loads(r)['authresponse']['signature']
return base_uri, signature
def axapi_action(uri, payload='', signature='', method='POST'):
# PEP476 2.7.9+ / 3.4.3+ cert check
new_context = ssl._create_unverified_context()
try:
if method == 'POST':
req = urllib2.Request(uri)
req.add_header('content-type', 'application/json')
if signature:
req.add_header('Authorization', 'A10 {0}'.format(signature))
response = urllib2.urlopen(req, json.dumps(payload), context=new_context)
elif method == 'GET':
req = urllib2.Request(uri)
req.add_header('content-type', 'application/json')
if signature:
req.add_header('Authorization', 'A10 {0}'.format(signature))
response = urllib2.urlopen(req, context=new_context)
elif method == 'DELETE':
req = urllib2.Request(uri)
req.add_header('content-type', 'application/json')
req.get_method = lambda: 'DELETE'
if signature:
req.add_header('Authorization', 'A10 {0}'.format(signature))
response = urllib2.urlopen(req, context=new_context)
return response.read()
except Exception as e:
raise