43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
import requests
|
|
import json
|
|
def get_domain(ip, token):
|
|
url = "http://" + ip + ":5000/v3/domains"
|
|
headers = {'X-Auth-Token': token}
|
|
response = requests.get(url, headers=headers)
|
|
return response.json()
|
|
def get_domain_id(ip, token, domain_name):
|
|
url = "http://" + ip + ":5000/v3/domains"
|
|
headers = {'X-Auth-Token': token}
|
|
response = requests.get(url, headers=headers)
|
|
for i in response.json()['domains']:
|
|
if i['name'] == domain_name:
|
|
domain_id = i['id']
|
|
return domain_id
|
|
else:
|
|
return None
|
|
def create_domain(ip, token, domain_name, description):
|
|
url = "http://" + ip + ":5000/v3/domains"
|
|
headers = {'X-Auth-Token': token}
|
|
data = {
|
|
"domain": {
|
|
"description": description,
|
|
"enabled": True,
|
|
"name": domain_name
|
|
}
|
|
}
|
|
response = requests.post(url, headers=headers, data=json.dumps(data))
|
|
return response.json()
|
|
def show_domain(ip, token,domain_name):
|
|
domain_id = get_domain_id(ip, token, domain_name)
|
|
if domain_id == None:
|
|
return None
|
|
url = "http://" + ip + ":5000/v3/domains/" + domain_id
|
|
headers = {'X-Auth-Token': token}
|
|
response = requests.get(url, headers=headers)
|
|
return response.json()
|
|
def delete_domain(ip, token, domain_name):
|
|
domain_id = get_domain_id(ip, token, domain_name)
|
|
url = "http://" + ip + ":5000/v3/domains/" + domain_id
|
|
headers = {'X-Auth-Token': token}
|
|
response = requests.delete(url, headers=headers)
|
|
return response.json() |