This repository was archived by the owner on Jun 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathxmlrpc-test.py
More file actions
executable file
·146 lines (124 loc) · 4.99 KB
/
xmlrpc-test.py
File metadata and controls
executable file
·146 lines (124 loc) · 4.99 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/python3
import sys
import xmlrpc.client
# Change to valid data
apikey = "<apikey>"
address = "http://localhost/php-virt-control/xmlrpc.php"
selections = ['Information', 'Domain', 'Get network information']
info_types = ['connection', 'node', 'cpustats', 'eachcpustats', 'memstats', 'system']
domactions = ['Start', 'Stop', 'Reboot', 'Dump', 'Migrate', 'Get screenshot']
request = {'apikey': apikey,
'connection': {'uri': 'qemu:///system'}
}
# Should bail on this
connection_uri2 = 'qemu:///system';
request_info = request
request_info['data'] = {'type': 'unknown'}
request_name = request
request_name['data'] = {'name': 'x'}
def choose(prompt, chooser, types):
print("\n%s types:\n" % chooser)
num = 0
for onetype in types:
print("\t%s) %s" % (num + 1, types[num]))
num += 1
print("\n")
line = input(prompt)
try:
return int(line) - 1
except:
return -1
try:
print("XML RPC Proxy is set to %s" % address)
if input("Is that OK? (Y/n) ") == "n":
address = input("Enter new address: ")
proxy = xmlrpc.client.ServerProxy(address)
request['connection']['uri'] = 'list'
conns = proxy.Information.get(request)
conns_s = sorted(conns)
print("\n")
for connection in conns_s:
print("%s) %s" % (int(connection) + 1, conns[connection]['name']))
print("\n")
line = input("Choose connection: ")
try:
conn = int(line) - 1
except:
sys.exit(1)
conn = str(conn)
request['connection']['uri'] = conns[conn]['uri']
request_info['connection']['uri'] = request['connection']['uri']
request_name['connection']['uri'] = request['connection']['uri']
print("\nConnection URI: %s" % request['connection']['uri'])
num = choose("Enter type: ", "Type", selections)
if num == 0:
num = choose("Enter your choice: ", "Information", info_types)
if num > -1:
request['data']['type'] = info_types[num]
print("Result is: %s" % proxy.Information.get(request_info))
elif num == 1:
l = proxy.Domain.list(request)
print("Domains:\n")
for d in l:
print("%s) %s" % (int(d) + 1, l[d]))
print("\n")
line = input("Choose domain index: ")
try:
idx = int(line) - 1
except:
sys.exit(1)
# Assign the name to request_name dictionary
name = l[str(idx)]
request_name['data']['name'] = name
l = proxy.Domain.info(request_name)
print("\nDomain information:\n\nName: %s\nvCPUs: %s\nState: %s\nMemory: %s MiB (max %s MiB)\nCPUUsed: %s" %
(name, l['nrVirtCpu'], l['state'], l['memory'] / 1024, l['maxMem'] / 1024, l['cpuUsed']))
print("\nFeatures: %s\nMultimedia:\n\tInput: %s\n\tVideo: %s\n\tConsole: %s\n\tGraphics: %s\nHost devices: %s\nBoot devices: %s\n" %
(l['features'], l['multimedia']['input'], l['multimedia']['video'], l['multimedia']['console'],
l['multimedia']['graphics'], l['devices'], l['boot_devices']))
num = choose("Enter your choice: ", "Domain actions", domactions)
if num == -1:
sys.exit(1)
# Process actions
if num == 0:
print("Starting up domain %s" % name)
print("Method returned: %s" % proxy.Domain.start(request_name)['msg'])
elif num == 1:
print("Stopping domain %s" % name)
print("Method returned: %s" % proxy.Domain.stop(request_name)['msg'])
elif num == 2:
print("Rebooting %s" % name)
print("Method returned: %s" % proxy.Domain.reboot(request_name)['msg'])
elif num == 3:
print("Dumping %s" % name)
print("Method returned:\n%s" % proxy.Domain.dump(request_name)['msg'])
elif num == 4:
print("Migrating %s" % name)
request_domain_migrate = request_name
request_domain_migrate['data']['destination'] = {'uri': connection_uri2}
print("Method returned: %s" % proxy.Domain.migrate(request_domain_migrate)['msg'])
elif num == 5:
print("Getting screenshot of %s" % name)
print("Method returned: %s" % proxy.Domain.get_screenshot(request_name)['msg'])
elif num == 2:
l = proxy.Network.list(request)
print("Network:\n")
for d in l:
print("%s) %s" % (int(d) + 1, l[d]))
print("\n")
line = input("Choose network index: ")
try:
idx = int(line) - 1
except:
sys.exit(1)
# Assign the name to request_name dictionary
name = l[str(idx)]
request_name['data']['name'] = name
print("Getting information about %s" % name)
print("Method returned: %s" % proxy.Network.info(request_name))
except xmlrpc.client.ProtocolError as err:
print("A protocol error occurred")
print("URL: %s" % err.url)
print("HTTP/HTTPS headers: %s" % err.headers)
print("Error code: %d" % err.errcode)
print("Error message: %s" % err.errmsg)