173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
break
elif not hasattr("address",options):
print >>sys.stderr,"Addess or search pattern for device is not specified"
sys.exit(1)
else:
return options.address
def get_host_devices():
f=os.popen("lsusb","r")
l=[]
for dev in f:
m=re.match('Bus (\d+) Device (\d+): (.*)$',dev)
if m:
l.append((m.group(1)+"."+m.group(2),m.group(3)))
f.close()
return l
def get_vm_devices(sock):
answer=send_command(sock,"info usb")
l=[]
for dev in answer.split("\n"):
m=re.match('Device (\d+\.\d), .*?, Product (.*)$',dev)
if m:
l.append((m.group(1),m.group(2)))
return l
def cmd_usb_insert(options):
address=find_usb(options,get_host_devices())
answer=send_command(options.sock,"usb_add host:%s" % address)
print answer
def cmd_usb_list(options):
os.system("lsusb")
def cmd_usb_remove(options):
address=find_usb(options,get_vm_devices(options.sock))
answer=send_command(options.sock,"usb_del %s" % address)
print answer
def cmd_usb_attached(options):
for t in get_vm_devices(options.sock):
|
>
|
>
>
|
>
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
break
elif not hasattr("address",options):
print >>sys.stderr,"Addess or search pattern for device is not specified"
sys.exit(1)
else:
return options.address
def get_host_devices():
global config
f=os.popen(config.get('tools',"lsusb"),"r")
l=[]
for dev in f:
m=re.match('Bus (\d+) Device (\d+): (.*)$',dev)
if m:
if m.group(3).endswith("root hub"):
continue
l.append((m.group(1)+"."+m.group(2),m.group(3)))
f.close()
return l
def get_vm_devices(sock):
answer=send_command(sock,"info usb")
l=[]
for dev in answer.split("\n"):
m=re.match('Device (\d+\.\d), .*?, Product (.*)$',dev)
if m:
l.append((m.group(1),m.group(2)))
return l
def cmd_usb_insert(options):
address=find_usb(options,get_host_devices())
answer=send_command(options.sock,"usb_add host:%s" % address)
print answer
def cmd_usb_list(options):
for addr,descr in get_host_devices():
print addr,": ",descr
def cmd_usb_remove(options):
address=find_usb(options,get_vm_devices(options.sock))
answer=send_command(options.sock,"usb_del %s" % address)
print answer
def cmd_usb_attached(options):
for t in get_vm_devices(options.sock):
|
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
|
p=cmds.add_parser(name,**kwargs)
p.add_argument('machine',type=str,help='name of vm to operate on')
return p
#
# arg parsing
#
config=ConfigParser({'SharedVMs':'/var/cache/vws/shared',
'AutoStartVMs':'/var/cache/vws/autostart'})
config.add_section('directories')
config.read(['/etc/vws.conf',os.environ['HOME']+'/.vwsrc'])
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')
p.add_argument("--addr",action='store_const',const=True,default=False,
dest='addr',help='Show mac address and spice port')
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
|
|
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
|
p=cmds.add_parser(name,**kwargs)
p.add_argument('machine',type=str,help='name of vm to operate on')
return p
#
# arg parsing
#
arch=os.uname()[4]
if re.match("i[3-9]86",arch):
arch="i386"
elif arch.startswith("arm"):
arch="arm"
config=ConfigParser({'SharedVMs':'/var/cache/vws/shared',
'AutoStartVMs':'/var/cache/vws/autostart'})
config.add_section('directories')
config.add_section('create options')
for option,value in [('net','user'),('size','20G'),('mem','1G'),
('diskif','virtio'),('sound','hda'),('arch',arch),
('vga','qxl')]:
config.set('create options',option,value)
config.add_section('tools')
config.set('tools','viewer','remote-viewer %s')
config.set('tools','bridge_list','/sbin/brctl show')
config.set('tools','lsusb','lsusb')
config.read(['/etc/vws.conf',os.environ['HOME']+'/.vwsrc'])
print config
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')
p.add_argument("--addr",action='store_const',const=True,default=False,
dest='addr',help='Show mac address and spice port')
|
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
|
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')
# 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="20G");
p.add_argument("--arch",metavar='cputype',help="Emulated architecture",dest="arch",default='x86_64');
p.add_argument("--no-sound",help="Disable sound card",action='store_const',const = None,default='hda', dest="sound")
p.add_argument("--sound",metavar='cardtype',help="Specify sound card type",dest='sound',default='hda')
p.add_argument("--vga",metavar='cardtype',help="specify video card type (cirrus,std,vmwae,qxl) default qxl",dest="vga",default="qxl")
p.add_argument("--net",help="Network - 'user' or bridge name",dest='net',default="user")
p.add_argument("--mem",metavar='size',help="Size of memory",dest="mem",default="1024M")
p.add_argument("--diskif",metavar='interface-type',help="Disk interface (virtio, scsi, ide)",choices=['virtio','scsi','ide'],dest="diskif",default="virtio")
p.add_argument('--shared',help='Create shared VW instead of private one',action='store_const',const= True,dest='shared',default=False)
p.add_argument('--image',metavar='filename',help='Existing disk image to import',dest='image',default=None)
p.add_argument('--install',metavar='filename.iso',help='ISO image to install OS from',dest='install',default=None)
# Miscellenia
p=new_command(cmds,'monitor',help='connect stdin/stdout to monitor of VM')
p=new_command(cmds,'spiceuri',help='Output spice URI of machine')
parsed_args=args.parse_args(sys.argv[1:])
# Create command is totally different, so it is handled separately
|
|
>
|
>
|
>
|
>
|
>
>
|
>
|
>
|
>
>
|
>
|
>
|
>
|
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
|
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')
# 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",
dest="arch", default=config.get('create options','arch'));
p.add_argument("--no-sound",help="Disable sound card", action='store_const',
const=None, default=config.get('create options', 'sound'), dest="sound")
p.add_argument("--sound",metavar='cardtype',help="Specify sound card type",
dest='sound',default=config.get('create options','sound'))
p.add_argument("--vga",metavar='cardtype',
help="specify video card type (cirrus,std,vmwae,qxl) default qxl",
dest="vga",default=config.get('create options','vga'))
p.add_argument("--net",help="Network - 'user' or bridge name",
dest='net',default=config.get('create options','net'))
p.add_argument("--mem",metavar='size',help="Size of memory",
dest="mem",default=config.get('create options','mem'))
p.add_argument("--diskif",metavar='interface-type',
help="Disk interface (virtio, scsi, ide)",choices=['virtio','scsi','ide'],
dest="diskif",default=config.get('create options','diskif'))
p.add_argument('--shared',help='Create shared VW instead of private one',
action='store_const',const= True,dest='shared',default=False)
p.add_argument('--image',metavar='filename',help='Existing disk image to import',
dest='image',default=None)
p.add_argument('--install',metavar='filename.iso',
help='ISO image to install OS from',dest='install',default=None)
# Miscellenia
p=new_command(cmds,'monitor',help='connect stdin/stdout to monitor of VM')
p=new_command(cmds,'spiceuri',help='Output spice URI of machine')
parsed_args=args.parse_args(sys.argv[1:])
# Create command is totally different, so it is handled separately
|