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
|
#!/usr/bin/python
""" vws - script to control QEMU/KVM virtual workstations """
# pylint: disable=bad-builtin
# pylint: good-names: i,j,k,f,r,ex
from ConfigParser import ConfigParser
from argparse import ArgumentParser, Namespace
import fcntl
import socket, select
import errno
import re
import os, sys, time, os.path
VERSION = 0.2
def find_vm(name):
""" Search and return VM directory """
search_path = [os.path.join(os.environ['HOME'], "VWs"),
config.get("directories", "SharedVMs"),
config.get("directories", "AutostartVMs")]
for dirname in search_path:
if not os.access(dirname, os.X_OK):
continue
if (name in os.listdir(dirname) and
os.access(os.path.join(dirname, name, "start"), os.X_OK)):
return os.path.join(dirname, name)
raise ValueError("Machine %s not found." % name)
def connect_vm(vm_dir):
""" Connects to monitor of VM in vm_dir and returns connected socket"""
sock = socket.socket(socket.AF_UNIX)
monitor_path = os.path.join(vm_dir, "monitor")
|
<
|
|
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
|
#!/usr/bin/python
""" vws - script to control QEMU/KVM virtual workstations """
# pylint: disable=bad-builtin
from ConfigParser import ConfigParser
from argparse import ArgumentParser, Namespace
import fcntl
import socket, select
import errno
import re
import os, sys, time, os.path
VERSION = 0.2
def find_vm(name):
""" Search and return VM directory """
search_path = [os.path.join(os.environ['HOME'], "VWs"),
config.get("directories", "SharedVMs"),
config.get("directories", "AutostartVMs")]
for dirname in search_path:
if not os.access(dirname, os.X_OK):
continue
if (name in os.listdir(dirname) and
os.access(os.path.join(dirname, name, "start"), os.X_OK)):
return os.path.join(dirname, name)
raise ValueError("Machine %s not found." % name)
def connect_vm(vm_dir):
""" Connects to monitor of VM in vm_dir and returns connected socket"""
sock = socket.socket(socket.AF_UNIX)
monitor_path = os.path.join(vm_dir, "monitor")
|
︙ | | | ︙ | |
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
print >>sys.stderr, "No sound recording in progress"
sys.exit(1)
else:
print send_command(options.sock, "stopcapture " + match.group(1))
def cmd_sendkey(options):
""" vws sendkey """
print send_command(options.sock,"sendkey "+options.keyspec);
def cmd_version(dummy_options):
""" vws cersion """
print VERSION
def cmd_snapshot(options):
""" vws snapshot - create snapshot """
|
|
|
|
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
print >>sys.stderr, "No sound recording in progress"
sys.exit(1)
else:
print send_command(options.sock, "stopcapture " + match.group(1))
def cmd_sendkey(options):
""" vws sendkey """
print send_command(options.sock, "sendkey " + options.keyspec)
def cmd_version(dummy_options):
""" vws cersion """
print VERSION
def cmd_snapshot(options):
""" vws snapshot - create snapshot """
|
︙ | | | ︙ | |
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
-device usb-redir,chardev=usbredirchardev1,id=usbredirdev1 \\
-daemonize -pidfile pid
"""
def cmd_create(parsed_args):
""" vws create - create new VM """
BADSIZE = "Invalid size of %s specifed %s. Should have K, M or G suffix"
global TEMPLATE
if not parsed_args.image and not validate_size(parsed_args.size):
print >>sys.stderr, BADSIZE % ("disk", parsed_args.size)
sys.exit(1)
if not validate_size(parsed_args.mem):
print >>sys.stderr, BADSIZE % ("memory", parsed_args.size)
sys.exit(1)
drivename = "drive0.qcow2"
|
|
|
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
-device usb-redir,chardev=usbredirchardev1,id=usbredirdev1 \\
-daemonize -pidfile pid
"""
def cmd_create(parsed_args):
""" vws create - create new VM """
BADSIZE = "Invalid size of %s specifed %s. Should have K, M or G suffix"
global TEMPLATE
if not parsed_args.image and not validate_size(parsed_args.size):
print >>sys.stderr, BADSIZE % ("disk", parsed_args.size)
sys.exit(1)
if not validate_size(parsed_args.mem):
print >>sys.stderr, BADSIZE % ("memory", parsed_args.size)
sys.exit(1)
drivename = "drive0.qcow2"
|
︙ | | | ︙ | |
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
|
print >>sys.stderr, ("No such bridge %s. Available ones %s" %
(parsed_args.net, ", ".join(bridges)))
sys.exit(1)
options["net"] = ("-net nic,macaddr=%s -net bridge,br=%s" %
(macaddr, parsed_args.net))
else:
options["net"] = "-net nic,macaddr=%s -net user" % (macaddr,)
options["qemubinary"] = 'qemu-system-'+parsed_args.arch
options["vga"] = parsed_args.vga
NOACCEL = "KVM acceleration disabled due to "
if not parsed_args.arch in ('i386', 'x86_64'):
print >>sys.stderr, NOACCEL + "target architecture"
options.accel = ''
elif not os.access("/dev/kvm", os.W_OK):
print >>sys.stderr, NOACCEL + "unavailability on the host system"
|
|
|
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
|
print >>sys.stderr, ("No such bridge %s. Available ones %s" %
(parsed_args.net, ", ".join(bridges)))
sys.exit(1)
options["net"] = ("-net nic,macaddr=%s -net bridge,br=%s" %
(macaddr, parsed_args.net))
else:
options["net"] = "-net nic,macaddr=%s -net user" % (macaddr,)
options["qemubinary"] = 'qemu-system-' + parsed_args.arch
options["vga"] = parsed_args.vga
NOACCEL = "KVM acceleration disabled due to "
if not parsed_args.arch in ('i386', 'x86_64'):
print >>sys.stderr, NOACCEL + "target architecture"
options.accel = ''
elif not os.access("/dev/kvm", os.W_OK):
print >>sys.stderr, NOACCEL + "unavailability on the host system"
|
︙ | | | ︙ | |
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
"something on the way")
sys.exit(1)
# Creating directory for VM
os.makedirs(machinedir, dirmode)
driveopts = {"interface":parsed_args.diskif, "image":drivename}
if parsed_args.install:
install_image = os.path.abspath(parsed_args.install)
if parsed_args.image:
# Copying image file
print >>sys.stderr, ("Copying %s to %s" %
(parsed_args.image,
os.path.join(machinedir, drivename)))
os.system("qemu-img convert -O qcow2 -p %s %s" %
(parsed_args.image,
|
|
|
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
"something on the way")
sys.exit(1)
# Creating directory for VM
os.makedirs(machinedir, dirmode)
driveopts = {"interface":parsed_args.diskif, "image":drivename}
if parsed_args.install:
install_image = os.path.abspath(parsed_args.install)
if parsed_args.image:
# Copying image file
print >>sys.stderr, ("Copying %s to %s" %
(parsed_args.image,
os.path.join(machinedir, drivename)))
os.system("qemu-img convert -O qcow2 -p %s %s" %
(parsed_args.image,
|
︙ | | | ︙ | |
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
|
# Screenshoits and recording
p = new_command(cmds, 'screenshot', help='take a screenshot')
p.add_argument('filename', help='PPM image filename to write screenshot to')
p = new_command(cmds, 'record', help='Record audio output from VM')
p.add_argument('filename', help='wav file to record autdio to')
new_command(cmds, 'stoprecord', help='stop recording audio')
p = new_command(cmds, 'sendkey', help='Send a keystroke to VM')
p.add_argument('keyspec',help='key specification like ctrl-alt-delete');
# Create new VM
p = new_command(cmds, 'create', help="Create new VW")
p.add_argument("--no-usb", help="Disable USB controller", action='store_const',
const=False, default=True, dest="usb")
p.add_argument("--size", metavar='size', help="Size of primary disk images",
dest="size", default=config.get('create options', 'size'))
p.add_argument("--arch", metavar='cputype', help="Emulated architecture",
|
|
|
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
|
# Screenshoits and recording
p = new_command(cmds, 'screenshot', help='take a screenshot')
p.add_argument('filename', help='PPM image filename to write screenshot to')
p = new_command(cmds, 'record', help='Record audio output from VM')
p.add_argument('filename', help='wav file to record autdio to')
new_command(cmds, 'stoprecord', help='stop recording audio')
p = new_command(cmds, 'sendkey', help='Send a keystroke to VM')
p.add_argument('keyspec', help='key specification like ctrl-alt-delete')
# Create new VM
p = new_command(cmds, 'create', help="Create new VW")
p.add_argument("--no-usb", help="Disable USB controller", action='store_const',
const=False, default=True, dest="usb")
p.add_argument("--size", metavar='size', help="Size of primary disk images",
dest="size", default=config.get('create options', 'size'))
p.add_argument("--arch", metavar='cputype', help="Emulated architecture",
|
︙ | | | ︙ | |