list user files, list user vm added
This commit is contained in:
parent
a82bbb5ab1
commit
c4cf097b99
1 changed files with 32 additions and 14 deletions
46
ucloud.py
46
ucloud.py
|
@ -30,6 +30,14 @@ images_parser.add_argument("--list",
|
||||||
choices=["public", "private"],
|
choices=["public", "private"],
|
||||||
required=True)
|
required=True)
|
||||||
|
|
||||||
|
user_parser = subparser.add_parser("user")
|
||||||
|
user_subparser = user_parser.add_subparsers(dest="usercommand")
|
||||||
|
|
||||||
|
user_list_vms_parser = user_subparser.add_parser("list")
|
||||||
|
user_list_vms_parser.add_argument("--files", action='store_true')
|
||||||
|
user_list_vms_parser.add_argument("--vms", action='store_true')
|
||||||
|
add_otp(user_list_vms_parser)
|
||||||
|
|
||||||
vm_parser = subparser.add_parser("vm")
|
vm_parser = subparser.add_parser("vm")
|
||||||
vm_subparser = vm_parser.add_subparsers(dest="vmcommand")
|
vm_subparser = vm_parser.add_subparsers(dest="vmcommand")
|
||||||
|
|
||||||
|
@ -42,17 +50,15 @@ vm_create_parser.add_argument("--image_uuid", required=True)
|
||||||
vm_start_parser = vm_subparser.add_parser("start")
|
vm_start_parser = vm_subparser.add_parser("start")
|
||||||
vm_suspend_parser = vm_subparser.add_parser("suspend")
|
vm_suspend_parser = vm_subparser.add_parser("suspend")
|
||||||
vm_resume_parser = vm_subparser.add_parser("resume")
|
vm_resume_parser = vm_subparser.add_parser("resume")
|
||||||
|
vm_shutdown_parser = vm_subparser.add_parser("shutdown")
|
||||||
vm_status_parser = vm_subparser.add_parser("status")
|
vm_status_parser = vm_subparser.add_parser("status")
|
||||||
|
|
||||||
add_vmid(add_otp(vm_start_parser))
|
add_vmid(add_otp(vm_start_parser))
|
||||||
add_vmid(add_otp(vm_suspend_parser))
|
add_vmid(add_otp(vm_suspend_parser))
|
||||||
add_vmid(add_otp(vm_resume_parser))
|
add_vmid(add_otp(vm_resume_parser))
|
||||||
|
add_vmid(add_otp(vm_shutdown_parser))
|
||||||
add_vmid(add_otp(vm_status_parser))
|
add_vmid(add_otp(vm_status_parser))
|
||||||
|
|
||||||
|
|
||||||
vm_list_parser = vm_subparser.add_parser("list")
|
|
||||||
add_otp(vm_list_parser)
|
|
||||||
|
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
if args.command == "create-image-from-file":
|
if args.command == "create-image-from-file":
|
||||||
|
@ -86,16 +92,8 @@ elif args.command == "vm":
|
||||||
r = requests.post(f"{config('UCLOUD_API_SERVER')}/vm/create",
|
r = requests.post(f"{config('UCLOUD_API_SERVER')}/vm/create",
|
||||||
json=data)
|
json=data)
|
||||||
print(json.loads(r.content))
|
print(json.loads(r.content))
|
||||||
elif args.vmcommand == "list":
|
elif args.vmcommand in ["start", "suspend", "resume",
|
||||||
data = {
|
"status", "shutdown"]:
|
||||||
"name": args.name,
|
|
||||||
"realm": args.realm,
|
|
||||||
"token": TOTP(args.seed).now()
|
|
||||||
}
|
|
||||||
r = requests.get(f"{config('UCLOUD_API_SERVER')}/user/vms",
|
|
||||||
json=data)
|
|
||||||
print(json.loads(r.content))
|
|
||||||
elif args.vmcommand in ["start", "suspend", "resume", "status"]:
|
|
||||||
data = {
|
data = {
|
||||||
"name": args.name,
|
"name": args.name,
|
||||||
"realm": args.realm,
|
"realm": args.realm,
|
||||||
|
@ -107,3 +105,23 @@ elif args.command == "vm":
|
||||||
else:
|
else:
|
||||||
r = requests.post(f"{config('UCLOUD_API_SERVER')}/vm/{args.vmcommand}", json=data)
|
r = requests.post(f"{config('UCLOUD_API_SERVER')}/vm/{args.vmcommand}", json=data)
|
||||||
print(json.loads(r.content))
|
print(json.loads(r.content))
|
||||||
|
|
||||||
|
elif args.command == "user":
|
||||||
|
if args.usercommand == "list" and args.vms:
|
||||||
|
data = {
|
||||||
|
"name": args.name,
|
||||||
|
"realm": args.realm,
|
||||||
|
"token": TOTP(args.seed).now()
|
||||||
|
}
|
||||||
|
r = requests.get(f"{config('UCLOUD_API_SERVER')}/user/vms",
|
||||||
|
json=data)
|
||||||
|
print(json.loads(r.content))
|
||||||
|
elif args.usercommand == "list" and args.files:
|
||||||
|
data = {
|
||||||
|
"name": args.name,
|
||||||
|
"realm": args.realm,
|
||||||
|
"token": TOTP(args.seed).now()
|
||||||
|
}
|
||||||
|
r = requests.get(f"{config('UCLOUD_API_SERVER')}/user/files",
|
||||||
|
json=data)
|
||||||
|
print(json.loads(r.content))
|
Loading…
Reference in a new issue