Diff
Not logged in

Differences From Artifact [d944184ea2]:

To Artifact [be9a2c0531]:


247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
                idx = answer.index('\n')
                print answer[idx+1:],
                sys.stdout.flush()
            elif options.sock in readfd:
                print "UNSOLICITED MESSAGE %" + options.sock.readline().rstrip()
    except KeyboardInterrupt:
        print "Keyboard interrupt"
        sys.exit()

def cmd_reset(options):
    """ vws reset """
    print send_command(options.sock, 'system_reset')

def cmd_save(options):
    """ vws save """







<







247
248
249
250
251
252
253

254
255
256
257
258
259
260
                idx = answer.index('\n')
                print answer[idx+1:],
                sys.stdout.flush()
            elif options.sock in readfd:
                print "UNSOLICITED MESSAGE %" + options.sock.readline().rstrip()
    except KeyboardInterrupt:
        print "Keyboard interrupt"


def cmd_reset(options):
    """ vws reset """
    print send_command(options.sock, 'system_reset')

def cmd_save(options):
    """ vws save """
274
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290
291
        for dev in  re.findall("([-\\w]+): [^\n]+\n    Removable device:",
                               devlist):
            if re.search("cd", dev):
                options.id = dev
                break
    if options.id is None:
        print >>sys.stderr, "No CDROM device found among:\n" + devlist
        sys.exit(1)
    if options.file == "":

        print >>sys.stderr, "Please specify either --eject or iso image"
        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, os.path.abspath(options.file)))
    print answer








|

>

|







273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
        for dev in  re.findall("([-\\w]+): [^\n]+\n    Removable device:",
                               devlist):
            if re.search("cd", dev):
                options.id = dev
                break
    if options.id is None:
        print >>sys.stderr, "No CDROM device found among:\n" + devlist
        return 1
    if options.file == "":

        print >>sys.stderr, "Please specify either --eject or iso image"
        return 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, os.path.abspath(options.file)))
    print answer

299
300
301
302
303
304
305

306
307
308
309
310
311
312
        for dev in devices:
            if re.search(options.pattern, dev[1]):
                options.address = dev[0]
                break
    elif not hasattr("address", options):
        print >>sys.stderr, ("Address or search pattern for device " +
                             "is not specified")

        sys.exit(1)
    else:
        return options.address

def get_host_devices():
    """ Parses output of lsusb into list of tuples "address" "descr" """
    global config







>







299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
        for dev in devices:
            if re.search(options.pattern, dev[1]):
                options.address = dev[0]
                break
    elif not hasattr("address", options):
        print >>sys.stderr, ("Address or search pattern for device " +
                             "is not specified")
        options.sock.close()
        sys.exit(1)
    else:
        return options.address

def get_host_devices():
    """ Parses output of lsusb into list of tuples "address" "descr" """
    global config
546
547
548
549
550
551
552
553


554


555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588

def cmd_autostart(options):
    """
    Starts all VMs which are in the autostart directory
    """
    import pwd
    dirname =  config.get("directories", "AutostartVMs")
    os.seteuid(pwd.getpwnam(


                            config.get("permissions","autostart_user")


                            ).pw_uid)
    if not os.access(dirname,os.R_OK):
        return 
    for name in os.listdir(dirname):
        if not os.access(os.path.join(dirname,name,"start"), os.X_OK):
            continue
        machine_dir = os.path.join(dirname,name)
        sock = connect_vm(machine_dir)
        if sock:
            # Machine already running
            sock.shutdown(socket.SHUT_RDWR)
            sock.close()
            continue
        start_opts = Namespace(machine = name,
                command = 'start',
                dir = machine_dir,
                snapshot = False,
                stopped = True,
                atrgs = "",
                gui = False,
                cdrom = None)
        try:
            cmd_start(start_opts)
            print name," ",
        finally:
            # pylint: disable=no-member

            start_opts.sock.shutdown(socket.SHUT_RDWR)
    print ""

def cmd_shutdown(options):
    """ Search for all running machines and stops all of them """
    dirlist=[config.get("directories","AutostartVMs"),
             config.get("directories","SharedVms")]
    if os.getresuid()[1] == 0:  







|
>
>
|
>
>
|

















|







>
|







547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594

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)
    os.setuid(userinfo.pw_uid)
    if not os.access(dirname,os.R_OK):
        return 
    for name in os.listdir(dirname):
        if not os.access(os.path.join(dirname,name,"start"), os.X_OK):
            continue
        machine_dir = os.path.join(dirname,name)
        sock = connect_vm(machine_dir)
        if sock:
            # Machine already running
            sock.shutdown(socket.SHUT_RDWR)
            sock.close()
            continue
        start_opts = Namespace(machine = name,
                command = 'start',
                dir = machine_dir,
                snapshot = False,
                stopped = True,
                args = "",
                gui = False,
                cdrom = None)
        try:
            cmd_start(start_opts)
            print name," ",
        finally:
            # pylint: disable=no-member
            if start_opts.sock:
                start_opts.sock.shutdown(socket.SHUT_RDWR)
    print ""

def cmd_shutdown(options):
    """ Search for all running machines and stops all of them """
    dirlist=[config.get("directories","AutostartVMs"),
             config.get("directories","SharedVms")]
    if os.getresuid()[1] == 0: