Check-in [4450a86be8]
Not logged in
Overview
Comment:Fixed autostart command
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4450a86be8e99bf2103e909fa1a569181089954b
User & Date: vitus on 2016-05-28 19:19:02
Other Links: manifest | tags
Context
2016-05-30
06:36
Add chgrp for pid and monitor to startup script check-in: 3a33d29e3f user: vitus tags: trunk
2016-05-28
19:19
Fixed autostart command check-in: 4450a86be8 user: vitus tags: trunk
2016-04-19
14:02
Added documentation for create command options. Added handling of strange situation when spiceurl function is unable to return url from working socket check-in: f56bcf1c34 user: vitus tags: trunk
Changes

Modified vws from [d944184ea2] to [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: