Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import json
import urllib2
from base64 import b64encode
a10_api_server = 'https://api.a10networks.com/api/v2'
def _get_session_token():
a10_user ='user@example.com'
a10_user_passwd = 'my_password'
session_request = urllib2.Request( a10_api_server + '/sessions')
cred = a10_user + ':' + a10_user_passwd
auth = "Basic " + b64encode(cred)
headers = {
"provider": "root",
"Content-Type": "application/json",
"Authorization": auth
}
for key, value in headers.items():
session_request.add_header(key, value)
response = urllib2.urlopen(session_request,
json.dumps({"userId": a10_user}))
session_json_data = json.loads(response.read())
return 'Session ' + session_json_data['id']
def create_ladc_cluster():
cluster_name = 'CULSTERNAME'
session_request = urllib2.Request( a10_api_server + '/cspcluster')
headers = {
"provider": "root",
"tenant": "Cisco",
"Content-Type": "application/json",
"Authorization": session_token
}
for key, value in headers.items():
session_request.add_header(key, value)
response = urllib2.urlopen(session_request,
json.dumps({"name": cluster_name, "state": "ACTIVE"}))
cluster_json_data = json.loads(response.read())
return cluster_json_data["clusterId"]
session_token = _get_session_token()
create_ladc_cluster()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment