Check-in [d72aaf8da4]
Not logged in
Overview
Comment:Added display of privare/public status and spice url to vws list command. Fixes 96cc307ed7
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d72aaf8da49485485befe733055f585365b6b6a0
User & Date: vitus on 2016-04-14 19:56:21
Other Links: manifest | tags
References
2016-04-14
19:57 Fixed ticket [96cc307ed7]: vws list should display status (private/public) of vm plus 5 other changes artifact: 11380ca530 user: vitus
Context
2016-04-14
20:10
documented permission setction of config file. Make autostart_user option work check-in: 57c08957e3 user: vitus tags: trunk
19:56
Added display of privare/public status and spice url to vws list command. Fixes 96cc307ed7 check-in: d72aaf8da4 user: vitus tags: trunk
14:35
Set permissions on VM files. Fixes [067fea7873] check-in: 6c894d8ca6 user: vitus tags: trunk
Changes

Modified vws from [ab478f8f41] to [c2c3e866b0].

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
            if chunk == '':
                raise IOError("Unexpected EOF From monitor")
            answer += chunk
    finally:
        fcntl.flock(sock, fcntl.LOCK_UN)
    return answer

def spiceurl(options):
    """ Returns spice URI for given (as set of parsed args) VM """
    output = send_command(options.sock, "info spice")
    url = None
    for line in output.split("\n"):
        if url is not None:
            continue
        idx = line.find("address:")
        if idx != -1:
            url = line[idx+9:]







|

|







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
            if chunk == '':
                raise IOError("Unexpected EOF From monitor")
            answer += chunk
    finally:
        fcntl.flock(sock, fcntl.LOCK_UN)
    return answer

def spiceurl(sock):
    """ Returns spice URI for given (as set of parsed args) VM """
    output = send_command(sock, "info spice")
    url = None
    for line in output.split("\n"):
        if url is not None:
            continue
        idx = line.find("address:")
        if idx != -1:
            url = line[idx+9:]
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

#
# command implementation
#

def cmd_spiceuri(options):
    """ vws spiceuri """
    print spiceurl(options)


def cmd_start(options):
    """ vws start """
    if options.stopped:
        arg = ""
        if options.cdrom:







|







114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

#
# command implementation
#

def cmd_spiceuri(options):
    """ vws spiceuri """
    print spiceurl(options.sock)


def cmd_start(options):
    """ vws start """
    if options.stopped:
        arg = ""
        if options.cdrom:
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
            print >>sys.stderr, ("Cannot change qemu options. " +
                                 "VM is already running")
        if options.cdrom:
            options.file = options.cdrom[0]
            options.id = None
            cmd_cdrom(options)
    if options.gui:
        uri = spiceurl(options)
        os.system((config.get('tools', 'viewer') + "&") % uri)
    elif not options.stopped:
        print >>sys.stderr, "VM already running"

def cmd_stop(options):
    """ vws stop """
    if snapshot_mode(options.sock) or options.hard:







|







161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
            print >>sys.stderr, ("Cannot change qemu options. " +
                                 "VM is already running")
        if options.cdrom:
            options.file = options.cdrom[0]
            options.id = None
            cmd_cdrom(options)
    if options.gui:
        uri = spiceurl(options.sock)
        os.system((config.get('tools', 'viewer') + "&") % uri)
    elif not options.stopped:
        print >>sys.stderr, "VM already running"

def cmd_stop(options):
    """ vws stop """
    if snapshot_mode(options.sock) or options.hard:
299
300
301
302
303
304
305
306
307
308



309
310
311
312
313
314
315
316
317
318
319
320

321
322
323

324

325
326
327
328

329
330
331
332
333
334
335
336
337
338
339
340
341
    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 = [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
        maxlen = 0
        vms = []
        for vmname in os.listdir(dirname):
            if os.access(dirname + "/" + vmname + "/start", os.X_OK):
                count += 1
                f = [vmname]
                if maxlen < len(vmname):
                    maxlen = len(vmname)
                if options.state:

                    sock = connect_vm(dirname + "/" + vmname)
                    if sock is None:
                        state = "stopped"

                    else:

                        sock.shutdown(socket.SHUT_RDWR)
                        sock.close()
                        state = "running"
                    f.append(state)

                vms.append(f)
        for f in sorted(vms):
            if len(f) == 2:
                print "%*s %s" % (-maxlen, f[0], f[1])
            else:
                print f[0]
    if not count:
        sys.exit(1)

def cmd_screenshot(options):
    """ vws screenshot """
    from os.path import abspath
    filename = abspath(options.filename)







|
|
|
>
>
>
|


<
<







>



>

>




>

|
|
|
|
|







299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314


315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
    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 = []
    for (vmtype,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
                f = [vmname]
                if maxlen < len(vmname):
                    maxlen = len(vmname)
                if options.state:
                    f.append(vmtype)
                    sock = connect_vm(dirname + "/" + vmname)
                    if sock is None:
                        state = "stopped"
                        uri="-"
                    else:
                        uri=spiceurl(sock)
                        sock.shutdown(socket.SHUT_RDWR)
                        sock.close()
                        state = "running"
                    f.append(state)
                    f.append(uri)
                vms.append(f)
    for f in sorted(vms):
        if len(f) == 4:
            print "%*s %s   %-9s %s" % (-maxlen, f[0], f[2], f[1], f[3])
        else:
            print f[0]
    if not count:
        sys.exit(1)

def cmd_screenshot(options):
    """ vws screenshot """
    from os.path import abspath
    filename = abspath(options.filename)