openstack-api-manage/keystone/domain.py

39 lines
1.4 KiB
Python
Raw Normal View History

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
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)
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()