209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
-
+
|
"""
Checks if there is snapshot of running vm which should be restored
Returns either id of this snapshot or None
"""
nxt = 0
with os.popen("qemu-img info \"%s\"" %
(get_drives(vmdir)[0]), "r") as f:
(os.path.join(vmdir, get_drives(vmdir)[0])), "r") as f:
for line in f:
if line == 'Snapshot list:\n':
nxt = 2
elif nxt == 2 and line.startswith('ID'):
nxt = 1
elif nxt == 1:
nxt = 0
|
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
-
+
|
if options.gui:
os.system((config.get('tools', 'viewer') + "&") % uri)
elif not options.stopped:
print("VM already running use uri %s" % uri, file=sys.stderr)
def cmd_stop(options):
""" vws stop """
if snapshot_mode(options.sock) or options.hard:
if options.hard or snapshot_mode(options.sock):
try:
send_command(options.sock, 'quit')
except IOError as ex:
# Expect IOError here
if str(ex).find("EOF from monitor"):
print("monitor socket closed")
else:
|
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
+
-
+
|
def cmd_save(options):
""" vws save """
answer = send_command(options.sock, 'savevm')
if re.search("Error", answer):
print(answer, file=sys.stderr)
sys.exit(1)
else:
options.hard = True
send_command(options.sock, 'quit')
cmd_stop(options)
def cmd_cdrom(options):
""" vws cdrom """
if options.id is None:
# Search for devices which could be interpreted as CDROM
devlist = send_command(options.sock, "info block")
for dev in re.findall("([-\\w]+): [^\n]+\n Removable device:",
|
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
+
+
+
+
-
+
-
+
-
+
|
print(answer)
def make_vm_listing(vmname, dirname, vmtype):
""" makes dict with vm properties for short index """
f = {"name":vmname, "type":vmtype}
sock = connect_vm(dirname)
if sock is None:
if check_for_snapshot(dirname):
f['state'] = "sleeping"
else:
f['state'] = 'stopped '
f.update({"state":"stopped", "uri":"-", "ip":"-"})
f.update({"uri":"-", "ip":"-"})
f.update(read_netinfo(os.path.join(dirname, "start")))
else:
uri = spiceurl(sock)
if uri is None:
f.update({"state":"problem", "uri":"None", "ip":"-"})
f.update({"state":"problem ", "uri":"None", "ip":"-"})
f.update(read_netinfo(os.path.join(dirname, "start")))
else:
f["uri"] = uri[uri.rindex(":")+1:]
f.update(get_netinfo(sock))
sock.shutdown(socket.SHUT_RDWR)
sock.close()
f["state"] = "running"
f["state"] = "running "
return f
def add_ip_address(listing):
""" Adds IP addresses from ARP into VM listing """
bridges = set()
for vminfo in listing:
|