54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
-
+
-
+
|
if chunk == '':
raise IOError("Unexpected EOF From monitor")
answer += chunk
finally:
fcntl.flock(sock, fcntl.LOCK_UN)
return answer
def spiceurl(options):
def spiceurl(sock):
""" Returns spice URI for given (as set of parsed args) VM """
output = send_command(options.sock, "info spice")
output = send_command(sock, "info spice")
url = None
for line in output.split("\n"):
if url is not None:
continue
idx = line.find("address:")
if idx != -1:
url = line[idx+9:]
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
-
+
|
#
# command implementation
#
def cmd_spiceuri(options):
""" vws spiceuri """
print spiceurl(options)
print spiceurl(options.sock)
def cmd_start(options):
""" vws start """
if options.stopped:
arg = ""
if options.cdrom:
|
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
-
+
|
print >>sys.stderr, ("Cannot change qemu options. " +
"VM is already running")
if options.cdrom:
options.file = options.cdrom[0]
options.id = None
cmd_cdrom(options)
if options.gui:
uri = spiceurl(options)
uri = spiceurl(options.sock)
os.system((config.get('tools', 'viewer') + "&") % uri)
elif not options.stopped:
print >>sys.stderr, "VM already running"
def cmd_stop(options):
""" vws stop """
if snapshot_mode(options.sock) or options.hard:
|
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
-
-
-
-
+
+
+
+
+
+
+
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
|
address = find_usb(options, get_vm_devices(options.sock))
answer = send_command(options.sock, "usb_del %s" % address)
print answer
def cmd_list(options):
""" vws list """
count = 0
search_path = [os.environ['HOME'] + "/VWs",
config.get("directories", "SharedVMs"),
config.get("directories", "AutostartVMs")]
for dirname in search_path:
search_path = [("private",os.environ['HOME'] + "/VWs"),
("shared",config.get("directories", "SharedVMs")),
("autostart",config.get("directories", "AutostartVMs"))]
maxlen = 0
vms = []
for (vmtype,dirname) in search_path:
if not os.access(dirname + "/.", os.X_OK):
continue
maxlen = 0
vms = []
for vmname in os.listdir(dirname):
if os.access(dirname + "/" + vmname + "/start", os.X_OK):
count += 1
f = [vmname]
if maxlen < len(vmname):
maxlen = len(vmname)
if options.state:
f.append(vmtype)
sock = connect_vm(dirname + "/" + vmname)
if sock is None:
state = "stopped"
uri="-"
else:
uri=spiceurl(sock)
sock.shutdown(socket.SHUT_RDWR)
sock.close()
state = "running"
f.append(state)
f.append(uri)
vms.append(f)
for f in sorted(vms):
if len(f) == 2:
print "%*s %s" % (-maxlen, f[0], f[1])
else:
print f[0]
for f in sorted(vms):
if len(f) == 4:
print "%*s %s %-9s %s" % (-maxlen, f[0], f[2], f[1], f[3])
else:
print f[0]
if not count:
sys.exit(1)
def cmd_screenshot(options):
""" vws screenshot """
from os.path import abspath
filename = abspath(options.filename)
|