-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
81 lines (64 loc) · 1.88 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import asyncio
import sys
from argparse import ArgumentParser
import XenAPI
from XenGarden.VM import VM
parser = ArgumentParser(
description="XenGarden Test Script",
)
parser.add_argument(
"--host",
dest="host",
type=str,
default="127.0.0.1",
help="The Destination Xenhost (default: 127.0.0.1)",
)
parser.add_argument(
"--username",
dest="username",
type=str,
default="root",
help="Username of Xenhost (default: root)",
)
parser.add_argument(
"--password",
dest="password",
default=None,
help="Password of Xen host",
)
async def main(url="http://127.0.0.1/", username="root", password=""):
print("XenGarden: ./test.py")
print("Copyright (c) 2021 Stella IT Inc.")
# First acquire a valid session by logging in:
session = XenAPI.Session(url)
try:
session.xenapi.login_with_password(username, password)
print("login successful")
await test(session)
except XenAPI.Failure as f:
print("Failed to acquire a session: %s" % f.details)
sys.exit(1)
finally:
session.xenapi.session.logout()
print("Test Complete")
async def test(session):
uuid = "2988e088-ff23-f543-334e-454352a6024a"
vm = VM.get_by_uuid(session, uuid)
print(await vm.get_record())
"""
vm = session.xenapi.VM.get_by_uuid(uuid)
task = session.xenapi.Async.VM.start(vm, False, False)
data = await Common.xenapi_task_handler(session, task)
print("started!")
task = session.xenapi.Async.VM.shutdown(vm)
data = await Common.xenapi_task_handler(session, task)
print("shutdown!")
"""
if __name__ == "__main__":
args = parser.parse_args()
password = args.password
if password is None:
password = input("Enter your password:")
loop = asyncio.get_event_loop()
asyncio.ensure_future(main(args.host, args.username, password), loop=loop)
loop.run_forever()