2024-06-07 10:16:54 +08:00
|
|
|
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
|
2024-06-07 15:08:22 +08:00
|
|
|
else:
|
|
|
|
return None
|
2024-06-07 10:16:54 +08:00
|
|
|
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)
|
2024-06-07 15:08:22 +08:00
|
|
|
if domain_id == None:
|
|
|
|
return None
|
2024-06-07 10:16:54 +08:00
|
|
|
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()
|