openstack-api-manage/main.py

127 lines
3.9 KiB
Python
Raw Normal View History

2024-06-07 10:16:54 +08:00
from keystone import get_token
from keystone import user
from keystone import domain
import time
def main():
print("====================")
print("选择一个操作:")
print("====================")
print("Keystone操作")
print("1. 用户管理")
print("2. 组管理")
print("3. 域管理")
print("====================")
choice = input("输入选项 (1-3): ")
ip = "172.30.26.171"
token = get_token.get_token(ip,'demo','admin','admin','000000')
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("请输入密码: ")
description = input("请输入描述: ")
result = user.create_user(ip, token, user_name, password, description)
print(result)
print("====================")
main()
elif choice == '2':
result = user.get_users(ip, token)
print(result)
main()
elif choice == '3':
user_name = input("请输入用户名: ")
result = user.get_user(ip, token, user_name)
print(result)
main()
elif choice == '4':
user_name = input("请输入用户名: ")
result = user.delete_user(ip, token, user_name)
print(result)
main()
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)
main()
else:
print("无效选项")
main()
elif choice == '2':
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("请输入域: ")
description = input("请输入描述: ")
result = user.create_user(ip, token, user_name, password, description)
print(result)
print("====================")
main()
elif choice == '2':
result = user.get_users(ip, token)
print(result)
main()
elif choice == '3':
user_name = input("请输入用户名: ")
result = user.get_user(ip, token, user_name)
print(result)
main()
elif choice == '4':
user_name = input("请输入用户名: ")
result = user.delete_user(ip, token, user_name)
print(result)
main()
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)
main()
else:
print("无效选项")
main()
#
# elif choice == '3':
#
# elif choice == '4':
#
# elif choice == '5':
else:
print("无效选项")
main()
if __name__ == "__main__":
main()