2024-06-17 16:57:51 +08:00
|
|
|
from keystone import get_token, group
|
|
|
|
from keystone import user
|
|
|
|
from keystone import domain
|
|
|
|
from keystone import project
|
2024-06-20 20:03:52 +08:00
|
|
|
|
|
|
|
ip = ""
|
|
|
|
token =""
|
2024-06-17 16:57:51 +08:00
|
|
|
import time
|
2024-06-17 16:58:18 +08:00
|
|
|
def keystone_main():
|
2024-06-17 16:57:51 +08:00
|
|
|
print("====================")
|
|
|
|
print("选择一个操作:")
|
|
|
|
print("====================")
|
|
|
|
print("Keystone操作")
|
|
|
|
print("1. 用户管理")
|
|
|
|
print("2. 组管理")
|
|
|
|
print("3. 域管理")
|
|
|
|
print("4. 项目管理")
|
|
|
|
print("5. 获取token")
|
|
|
|
print("====================")
|
|
|
|
choice = input("输入选项 (1-3): ")
|
2024-06-20 20:03:52 +08:00
|
|
|
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
if choice == '1':
|
|
|
|
print("====================")
|
|
|
|
print("选择一个操作:")
|
|
|
|
print("1. 创建用户")
|
|
|
|
print("2. 获取所有用户")
|
|
|
|
print("3. 获取特定用户信息")
|
|
|
|
print("4. 删除用户")
|
|
|
|
print("5. 更新用户密码")
|
|
|
|
print("====================")
|
|
|
|
choice = input("输入选项 (1-5): ")
|
|
|
|
print("====================")
|
|
|
|
if choice == '1':
|
|
|
|
user_name = input("请输入用户名: ")
|
|
|
|
password = input("请输入密码: ")
|
|
|
|
email=input("请输入邮箱: ")
|
|
|
|
domain_name=input("请输入域名: ")
|
|
|
|
default_project_name=input("请输入默认项目: ")
|
|
|
|
description = input("请输入描述: ")
|
|
|
|
result = user.create_user(ip, token, user_name,password, email,domain_name,default_project_name, description)
|
|
|
|
print(result)
|
|
|
|
print("====================")
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '2':
|
|
|
|
result = user.get_users(ip, token)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '3':
|
|
|
|
user_name = input("请输入用户名: ")
|
|
|
|
result = user.get_user(ip, token, user_name)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '4':
|
|
|
|
user_name = input("请输入用户名: ")
|
|
|
|
result = user.delete_user(ip, token, user_name)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '5':
|
|
|
|
user_name = input("请输入用户名: ")
|
|
|
|
new_password = input("请输入新密码: ")
|
|
|
|
original_password = input("请输入原始密码: ")
|
|
|
|
result = user.update_user_password(ip, token, user_name, new_password, original_password)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
else:
|
|
|
|
print("无效选项")
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '2':
|
|
|
|
print("====================")
|
|
|
|
print("选择一个操作:")
|
|
|
|
print("1. 创建组")
|
|
|
|
print("2. 获取所有组")
|
|
|
|
print("3. 获取特定组信息")
|
|
|
|
print("4. 删除组")
|
|
|
|
print("5. 更新组信息")
|
|
|
|
print("====================")
|
|
|
|
choice = input("输入选项 (1-5): ")
|
|
|
|
print("====================")
|
|
|
|
if choice == '1':
|
|
|
|
group_name = input("请输入组名: ")
|
|
|
|
domain_name = input("请输入域: ")
|
|
|
|
description = input("请输入描述: ")
|
|
|
|
result = group.create_group(ip, token,group_name,domain_name, description)
|
|
|
|
print(result)
|
|
|
|
print("====================")
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '2':
|
|
|
|
result = group.get_group(ip, token)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '3':
|
|
|
|
group_name = input("请输入组名: ")
|
|
|
|
result = group.show_group(ip, token,group_name)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '4':
|
|
|
|
group_name:str = input("请输入组名: ")
|
|
|
|
result = group.delete_group(ip, token, group_name)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '5':
|
|
|
|
group_name = input("请输入原组名: ")
|
|
|
|
new_group_name= input("请输入新组名: ")
|
|
|
|
new_domain_name = input("请输入新域名: ")
|
|
|
|
new_description = input("请输入新描述: ")
|
|
|
|
result = group.update_group(ip, token,group_name,new_group_name,new_domain_name, new_description)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
else:
|
|
|
|
print("无效选项")
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
#
|
|
|
|
elif choice == '3':
|
|
|
|
print("====================")
|
|
|
|
print("选择一个操作:")
|
|
|
|
print("1. 创建域")
|
|
|
|
print("2. 获取所有域信息")
|
|
|
|
print("3. 获取特定域信息")
|
|
|
|
print("4. 删除域")
|
|
|
|
print("5. 更新用户密码")
|
|
|
|
print("====================")
|
|
|
|
choice = input("输入选项 (1-5): ")
|
|
|
|
print("====================")
|
|
|
|
if choice == '1':
|
|
|
|
user_name = input("请输入用户名: ")
|
|
|
|
password = input("请输入密码: ")
|
|
|
|
email = input("请输入邮箱: ")
|
|
|
|
domain_name = input("请输入域名: ")
|
|
|
|
default_project_name = input("请输入默认项目: ")
|
|
|
|
description = input("请输入描述: ")
|
|
|
|
result = user.create_user(ip, token, user_name, password, email, domain_name, default_project_name,description)
|
|
|
|
print(result)
|
|
|
|
print("====================")
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '2':
|
|
|
|
result = user.get_users(ip, token)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '3':
|
|
|
|
user_name = input("请输入用户名: ")
|
|
|
|
result = user.get_user(ip, token, user_name)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '4':
|
|
|
|
user_name = input("请输入用户名: ")
|
|
|
|
result = user.delete_user(ip, token, user_name)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
elif choice == '5':
|
|
|
|
user_name = input("请输入用户名: ")
|
|
|
|
new_password = input("请输入新密码: ")
|
|
|
|
original_password = input("请输入原始密码: ")
|
|
|
|
result = user.update_user_password(ip, token, user_name, new_password, original_password)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
|
|
|
|
else:
|
|
|
|
print("无效选项")
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
#
|
|
|
|
elif choice == '4':
|
|
|
|
print("====================")
|
|
|
|
print("选择一个操作:")
|
|
|
|
print("1. 创建项目")
|
|
|
|
print("2. 获取所有项目信息")
|
|
|
|
print("3. 获取特定项目信息")
|
|
|
|
print("4. 删除项目")
|
|
|
|
print("5. 更新项目信息")
|
|
|
|
print("====================")
|
|
|
|
choice = input("输入选项 (1-5): ")
|
|
|
|
print("====================")
|
|
|
|
if choice == '1':
|
|
|
|
project_name = input("请输入项目名: ")
|
|
|
|
domain_name = input("请输入域: ")
|
|
|
|
description = input("请输入描述: ")
|
|
|
|
result = project.create_project(ip, token, project_name,domain_name, description)
|
|
|
|
print(result)
|
|
|
|
print("====================")
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
elif choice == '2':
|
|
|
|
result = project.get_project(ip, token)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
elif choice == '3':
|
|
|
|
project_name = input("请输入项目名: ")
|
|
|
|
result = project.show_project(ip, token,project_name)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
elif choice == '4':
|
|
|
|
project_name = input("请输入项目名: ")
|
|
|
|
result = project.delete_project(ip, token, project_name)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
elif choice == '5':
|
|
|
|
project_name = input("请输入原项目名: ")
|
|
|
|
new_project_name = input("请输入新项目名: ")
|
|
|
|
new_domain_id = input("请输入新域: ")
|
|
|
|
new_description = input("请输入新描述: ")
|
|
|
|
result = project.update_project(ip, token,project_name, new_project_name,new_domain_id, new_description)
|
|
|
|
print(result)
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|
2024-06-17 16:57:51 +08:00
|
|
|
#2
|
|
|
|
elif choice == '5':
|
|
|
|
print(token)
|
|
|
|
else:
|
|
|
|
print("无效选项")
|
2024-06-17 16:58:18 +08:00
|
|
|
keystone_main()
|