1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#!/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.4
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)):
|
>
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#!/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
import pwd
VERSION = 0.4
def find_vm(name):
""" Search and return VM directory """
search_path = [os.path.join(pwd.getpwuid(os.getuid()).pw_dir, "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)):
|
︙ | | | ︙ | |
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
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 = [("private",os.environ['HOME'] + "/VWs"),
("shared",config.get("directories", "SharedVMs")),
("autostart",config.get("directories", "AutostartVMs"))]
maxlen = 0
vms = []
bridges = set()
for (vmtype,dirname) in search_path:
|
|
|
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
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 = [("private",os.path.join(pwd.getpwuid(os.getuid()).pw_dir, "VWs")),
("shared",config.get("directories", "SharedVMs")),
("autostart",config.get("directories", "AutostartVMs"))]
maxlen = 0
vms = []
bridges = set()
for (vmtype,dirname) in search_path:
|
︙ | | | ︙ | |
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
|
print >>sys.stderr, "VM is not running in snapshot mode"
sys.exit(1)
def cmd_autostart(options):
"""
Starts all VMs which are in the autostart directory
"""
import pwd
dirname = config.get("directories", "AutostartVMs")
userinfo=pwd.getpwnam(config.get("permissions","autostart_user"))
if not userinfo:
print >>sys.stderr, ("User %s doesn't exists %s" %
config.get("permissions","autostart_user"))
sys.exit(1)
os.setgid(userinfo.pw_gid)
|
<
|
546
547
548
549
550
551
552
553
554
555
556
557
558
559
|
print >>sys.stderr, "VM is not running in snapshot mode"
sys.exit(1)
def cmd_autostart(options):
"""
Starts all VMs which are in the autostart directory
"""
dirname = config.get("directories", "AutostartVMs")
userinfo=pwd.getpwnam(config.get("permissions","autostart_user"))
if not userinfo:
print >>sys.stderr, ("User %s doesn't exists %s" %
config.get("permissions","autostart_user"))
sys.exit(1)
os.setgid(userinfo.pw_gid)
|
︙ | | | ︙ | |
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
|
"usb":"-usb"}
macaddr = ":".join(["%02x" % ord(x) for x in chr(0x52) + os.urandom(5)])
if parsed_args.shared:
machinedir = os.path.join(config.get("directories", "SharedVMs"),
parsed_args.machine)
dirmode = 0775
else:
machinedir = os.path.join(os.environ["HOME"], "VWs",
parsed_args.machine)
dirmode = 0775
if parsed_args.net != 'user':
bridges = list_bridges()
if not parsed_args.net in bridges:
print >>sys.stderr, ("No such bridge %s. Available ones %s" %
|
|
|
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
|
"usb":"-usb"}
macaddr = ":".join(["%02x" % ord(x) for x in chr(0x52) + os.urandom(5)])
if parsed_args.shared:
machinedir = os.path.join(config.get("directories", "SharedVMs"),
parsed_args.machine)
dirmode = 0775
else:
machinedir = os.path.join(pwd.getpwuid(os.getuid()).pw_dir, "VWs",
parsed_args.machine)
dirmode = 0775
if parsed_args.net != 'user':
bridges = list_bridges()
if not parsed_args.net in bridges:
print >>sys.stderr, ("No such bridge %s. Available ones %s" %
|
︙ | | | ︙ | |
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
|
config.set('tools', 'lsusb', 'lsusb')
config.set('tools', 'arp', '/usr/sbin/arp')
config.add_section('permissions')
config.set('permissions','vm_group','kvm')
config.set('permissions','autostart_user','root')
config.set('permissions','setgid_vm','yes')
# Read configration files
config.read(['/etc/vws.conf', os.environ['HOME'] + '/.vwsrc'])
# Parse argument
args = ArgumentParser(description="Manage Virtual Workstations")
cmds = args.add_subparsers(dest='command', help="sub-command help")
p = cmds.add_parser("list", help="List existing VWs",
description="List existing VWs")
p.add_argument("--state", action='store_const', const=True, default=False,
dest='state', help='Show state of the machine')
|
>
>
>
|
|
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
|
config.set('tools', 'lsusb', 'lsusb')
config.set('tools', 'arp', '/usr/sbin/arp')
config.add_section('permissions')
config.set('permissions','vm_group','kvm')
config.set('permissions','autostart_user','root')
config.set('permissions','setgid_vm','yes')
# Read configration files
if os.getuid() != 0:
config.read(['/etc/vws.conf',os.path.join(pwd.getpwuid(os.getuid()).pw_dir + '.vwsrc')])
else:
config.read(['/etc/vws.conf'])
# Parse argument
args = ArgumentParser(description="Manage Virtual Workstations")
cmds = args.add_subparsers(dest='command', help="sub-command help")
p = cmds.add_parser("list", help="List existing VWs",
description="List existing VWs")
p.add_argument("--state", action='store_const', const=True, default=False,
dest='state', help='Show state of the machine')
|
︙ | | | ︙ | |