Overview
Comment: | Implemented monitor. started usb code |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
48132590a1753fef4f0cb87298ac260d |
User & Date: | vitus on 2015-11-17 06:52:16 |
Other Links: | manifest | tags |
Context
2015-11-17
| ||
15:36 | Skip unexisting dirs in find_vm check-in: 2d6b5b3575 user: vitus tags: trunk | |
06:52 | Implemented monitor. started usb code check-in: 48132590a1 user: vitus tags: trunk | |
2015-11-13
| ||
16:29 | Fixed launch of the viewer in start command check-in: cb26ea490c user: vitus tags: trunk | |
Changes
Modified vws from [42c047dc9a] to [150ee1b1ab].
1 2 3 4 | #!/usr/bin/python from ConfigParser import ConfigParser from argparse import ArgumentParser import fcntl | | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #!/usr/bin/python from ConfigParser import ConfigParser from argparse import ArgumentParser import fcntl import socket,select import errno import re import os,sys,time VERSION=0.1 def find_vm(name): search_path=[os.environ['HOME']+"/VWs", config.get("directories","SharedVMs"), config.get("directories","AutostartVMs")] for dirname in search_path: if name in os.listdir(dirname): return dirname+"/"+name |
︙ | ︙ | |||
72 73 74 75 76 77 78 | time.sleep(2) options.sock = connect_vm(options.dir) if options.gui: uri = spiceurl(options) os.system("remote-viewer %s &" % uri) elif not options.stopped: print >>sys.stderr,"VM already running" | < | > > > > > > > > > > > > > > > > | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | time.sleep(2) options.sock = connect_vm(options.dir) if options.gui: uri = spiceurl(options) os.system("remote-viewer %s &" % uri) elif not options.stopped: print >>sys.stderr,"VM already running" def cmd_stop(options): print send_command(options.sock,'system_powerdown') def cmd_monitor(options): try: print "(qemu) ", sys.stdout.flush() while True: r,w,x=select.select([sys.stdin,options.sock],[],[]) if sys.stdin in r: cmd = sys.stdin.readline().rstrip() answer=send_command(options.sock,cmd) n=answer.index('\n') print answer[n+1:], sys.stdout.flush() elif options.sock in r: print "UNSOLICITED MESSAGE %"+options.sock.readline().rstrip() except KeyboardInterrupt: print "Keyboard interrupt" sys.exit() def cmd_reset(options): print send_command(options.sock,'system_reset') def cmd_cdrom(options): 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:",devlist): |
︙ | ︙ | |||
98 99 100 101 102 103 104 105 | sys.exit(1) if options.file is None: answer=send_command(options.sock,"eject "+options.id) else: answer=send_command(options.sock, "change %s %s" % (options.id, options.file)) print answer def cmd_usb_insert(options): | > > > > > > > > > > | | < > > > | | > | 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | sys.exit(1) if options.file is None: answer=send_command(options.sock,"eject "+options.id) else: answer=send_command(options.sock, "change %s %s" % (options.id, options.file)) print answer def find_usb(options,devices): if hasattr("pattern",options): pass 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 cmd_usb_insert(options): address=find_usb(options) 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) answer=send_command(options.sock,"usb_del %s" % address) print answer def cmd_usb_attached(options): answer=send_command(options.sock,"info usb") print answer def cmd_list(options): count = 0 search_path=[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 for vmname in os.listdir(dirname): if os.access(dirname+"/"+vmname+"/start",os.X_OK): count += 1 print vmname if not count: sys.exit(1) def cmd_version(options): print VERSION # # Utility functions for arg parsing # def new_command(cmds,name,**kwargs): """ Adds a subparser and adds a machine name argument to it """ |
︙ | ︙ | |||
151 152 153 154 155 156 157 | args=ArgumentParser() cmds=args.add_subparsers(dest='command',help="sub-command help") p=cmds.add_parser("list",help="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') | | | | | 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 213 214 215 216 217 | args=ArgumentParser() cmds=args.add_subparsers(dest='command',help="sub-command help") p=cmds.add_parser("list",help="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') p=cmds.add_parser("version",help="show vws version") # Power management p=new_command(cmds,'start',help='Start VM and connect to console') p.add_argument('--no-gui',dest='gui',action='store_const',const=False, default=True,help='do not open console window') p.add_argument('--cdrom',dest='cdrom',nargs=1, help='connect specified iso image to VMs cdrom on start') # Following commands don't need extra args new_command(cmds,'stop',help='Shut down virtual machine') new_command(cmds,'save',help='Save VM state and stop emulation') new_command(cmds,'reset',help='Reboot a guest OS') # Removable devices management p=new_command(cmds,'cdrom',help='manage CDROM Drive') p.add_argument('--id',type=str,default=None, help='Identifier of CDROM drive if VM has more than one') p.add_argument('file',nargs="?",default='',help='ISO image or special file to connect to drive') p.add_argument('--eject',dest='file',action='store_const',const=None) usb=cmds.add_parser('usb').add_subparsers(dest='subcommand',help='manage USB devices') p=new_command(usb,'insert',help='attach device to the virtual machine') p.add_argument('pattern',help='Pattern of device name to look up in lsusb') p.add_argument('--address',type=str,dest='address',nargs=1,help='exact address bus:device') p=new_command(usb,'remove',help='detach connected usb device') p.add_argument('pattern',help='Pattern of device name to look up in lsusb') p.add_argument('--address',type=str,dest='address',nargs=1,help='exact address bus:device') p=new_command(usb,'attached',help='list devices attached to vm') usb.add_parser('list',help='list devices available in the host system') # Snapshot management p=new_command(cmds,'snapshot',help='Create new snapshot') p=new_command(cmds,'revert',help='Revert to last snapshot') p=new_command(cmds,'commit',help='Commit snapshot changes into backing file') p=new_command(cmds,'snapshots',help='List existing snapshots') |
︙ | ︙ |