openstack-api-manage/keystone/group.py

50 lines
1.8 KiB
Python
Raw Normal View History

2024-06-07 10:16:54 +08:00
import requests
import json
def create_group(ip, token, group_name, description):
url = "http://" + ip + ":5000/v3/groups"
headers = {'X-Auth-Token': token}
data = {
"group": {
"name": group_name,
"domain_id": "default",
"description": description
}
}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json()
def get_group_id(ip, token, group_name):
url = "http://" + ip + ":5000/v3/groups"
headers = {'X-Auth-Token': token}
response = requests.get(url, headers=headers)
for i in response.json()['groups']:
if i['name'] == group_name:
return i['id']
def show_group(ip, token, group_name):
group_id = get_group_id(ip, token, group_name)
url = "http://" + ip + ":5000/v3/groups/" + group_id
headers = {'X-Auth-Token': token}
response = requests.get(url, headers=headers)
return response.json()
def delete_group(ip, token, group_name):
group_id = get_group_id(ip, token, group_name)
url = "http://" + ip + ":5000/v3/groups/" + group_id
headers = {'X-Auth-Token': token}
response = requests.delete(url, headers=headers)
return response.json()
def get_group(ip, token):
url = "http://" + ip + ":5000/v3/groups"
headers = {'X-Auth-Token': token}
response = requests.get(url, headers=headers)
return response.json()
def update_group(ip, token, group_name, new_group_name, new_description):
group_id = get_group_id(ip, token, group_name)
url = "http://" + ip + ":5000/v3/groups/" + group_id
headers = {'X-Auth-Token': token}
data = {
"group": {
"name": new_group_name,
"description": new_description
}
}
response = requests.patch(url, headers=headers, data=json.dumps(data))
return response.json()