Check-in [5b974714bc]
Not logged in
Overview
Comment:vws list --state now outputs IP and mac addresses
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5b974714bc5e5e3fc6534932de5766876018faa3
User & Date: vitus on 2016-04-15 12:23:56
Other Links: manifest | tags
Context
2016-04-15
14:28
Implemented shutdown command. Added systemd servcice file check-in: f1d54672c8 user: vitus tags: trunk
12:23
vws list --state now outputs IP and mac addresses check-in: 5b974714bc user: vitus tags: trunk
2016-04-14
20:10
documented permission setction of config file. Make autostart_user option work check-in: 57c08957e3 user: vitus tags: trunk
Changes

Modified Makefile from [e05303f1dd] to [c8d4867043].

9
10
11
12
13
14
15
16
17
18



19
20
21
22
23
9
10
11
12
13
14
15



16
17
18
19
20
21
22
23







-
-
-
+
+
+





%.1:%.mkd
	pandoc -s -t man -o $@ $+

clean:
	rm *.1

install: vws vws.1 find_free_port.1 vws.conf
	$(INSTALL) -d -m 755 -o root $(DESTDIR)$(bindir)
	$(INSTALL) -d -m 755 -o root $(DESTDIR)$(mandir)
	$(INSTALL) -d -m 755 -o root $(DESTDIR)$(mandir)/man1
	[ -d $(DESTDIR)$(bindir) ] || $(INSTALL) -d -m 755 -o root $(DESTDIR)$(bindir)
	[ -d $(DESTDIR)$(mandir) ] || $(INSTALL) -d -m 755 -o root $(DESTDIR)$(mandir)
	[ -d $(DESTDIR)$(mandir)/man1 ]||$(INSTALL) -d -m 755 -o root $(DESTDIR)$(mandir)/man1
	$(INSTALL) -c -m 755 -o root find_free_port $(DESTDIR)$(bindir)
	$(INSTALL) -c -m 755 -o root vws $(DESTDIR)$(bindir)
	[ -f $(DESTDIR)$(sysconfdir)/vws.conf ]|| $(INSTALL) -c -m 644 -o root vws.conf $(DESTDIR)$(sysconfdir)
	$(INSTALL) -c -m 644 -o root vws.1 $(DESTDIR)$(mandir)/man1
	$(INSTALL) -c -m 644 -o root find_free_port.1 $(DESTDIR)$(mandir)/man1

Modified vws from [e599101b46] to [f9837316dc].

85
86
87
88
89
90
91

















92
93
94
95
96
97
98
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







            if idx <= 0:
                continue
            name = line[:idx]
            if name == "bridge name":
                continue
            lst.append(name)
    return lst

def parse_arp(iface):
    """
    Returns map which maps mac addresses to IPs for specified interface"
    """
    addr_map = {}
    pipe = os.popen(config.get("tools","arp")+" -n -i "+iface, "r")
    for line in pipe:
        data = line.split() 
        mac=data[2]
        if mac == "HWAddress":
            continue
        if mac == iface:
            # Foind line with (incomplete) entry
            continue
        addr_map[data[2]]=data[0]
    return addr_map

def validate_size(size):
    """ Checks if size argument has proper format """
    return re.match('\\d+[KMG]', size) is not None

def get_drives(vm_dir):
    """ Return list of drive files in the VW directory """
107
108
109
110
111
112
113
114





























115
116
117
118
119
120
121
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
166







-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    return result

def snapshot_mode(sock):
    """ Returns True if VM is running in snapshot mode """
    answer = send_command(sock, "info block")
    return re.search(": /tmp", answer) is not None


def read_netinfo(filename):
    """ Reads network information from start script """
    with open(filename,"r") as f:
       for line in f:
          match=re.search("-net nic,macaddr=(\\S+) -net ([^,]+)",line)
          if match:
              f={"mac":match.group(1)}
              if match.group(2) == "user":
                   f["iface"]="user"
              elif match.group(2) == "bridge":
                   f["iface"]=re.search("br=(\\S+)",line).group(1)
              else:
                   f["iface"]="unknown";
              return f
    return {"iface":"unknown","mac":"?","ip":"?"}
def get_netinfo(sock):
    """ Gets network information from the running VM """
    answer = send_command(sock, "info network")
    match=re.search("bridge\\.0:.*,br=(\\S+).*macaddr=(\\S+)", answer, re.S)
    if match:
        return {"iface":match.group(1), "mac":match.group(2)}
    else:
        match = re.search("user.0:.*net=([^,]+).*\n.*macaddr=(\\S+)",answer)
        if match:
           return {"iface":"user", "ip":match.group(1), 
                    "mac":match.group(2)}
        else:
           print >>sys.stderr,answer
           return {"iface":"unknown","ip":"?","mac":"?","card":"?"}
#
# command implementation
#

def cmd_spiceuri(options):
    """ vws spiceuri """
    print spiceurl(options.sock)
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363

364
365
366
367

368
369
370


371
372
373
374
375
376
377
378
379
380

381


382
383
384
385



386
387
388
389
390
391
392
393
394
395

396
397
398
399
400
401
402
403







+






-
+



-
+


-
-
+
+


+
+
+
+


-
+
-
-

+
+
+
-
-
-
+
+
+
+
+
+
+
+
+

-
+







    count = 0
    search_path = [("private",os.environ['HOME'] + "/VWs"),
                   ("shared",config.get("directories", "SharedVMs")),
                   ("autostart",config.get("directories", "AutostartVMs"))]

    maxlen = 0
    vms = []
    bridges = set()
    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]
                f = {"name":vmname}
                if maxlen < len(vmname):
                    maxlen = len(vmname)
                if options.state:
                    f.append(vmtype)
                    f["type"]=vmtype
                    sock = connect_vm(dirname + "/" + vmname)
                    if sock is None:
                        state = "stopped"
                        uri="-"
                        f.update({"state":"stopped","uri":"-","ip":"-"})
                        f.update(read_netinfo(dirname + "/" + vmname + "/start"))
                    else:
                        uri=spiceurl(sock)
                        f["uri"]=uri[uri.rindex(":")+1:]
                        f.update(get_netinfo(sock))
                        if "ip" not in f:
                            bridges.add(f["iface"])
                        sock.shutdown(socket.SHUT_RDWR)
                        sock.close()
                        state = "running"
                        f["state"] = "running"
                    f.append(state)
                    f.append(uri)
                vms.append(f)
    arp_data={}
    for bridge in bridges:
        arp_data.update(parse_arp(bridge))
    for f in sorted(vms):
        if len(f) == 4:
            print "%*s %s   %-9s %s" % (-maxlen, f[0], f[2], f[1], f[3])
    for f in sorted(vms,key=lambda x: x["name"]):
        if "state" in f:
            if "mac" in f and not "ip" in f:
                if f["mac"] in arp_data:
                    f["ip"] = arp_data[f["mac"]]
                else:
                    f["ip"] = "-"
            f["name"] = f["name"].ljust(maxlen)
            print "%(name)s %(state)s   %(type)-9s %(uri)-4s %(iface)-5s %(mac)s %(ip)s " % f
        else:
            print f[0]
            print f["name"]
    if not count:
        sys.exit(1)

def cmd_screenshot(options):
    """ vws screenshot """
    from os.path import abspath
    filename = abspath(options.filename)
698
699
700
701
702
703
704

705
706
707
708
709
710
711
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769







+







                      ('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.set('tools', 'arp', '/usr/sbin/arp')
config.add_section('permissions')
config.set('permissions','vm_group','kvm')
config.set('permissions','autostart_user','root')
config.set('permissions','setgid_vm','yes')
# Read configration files
config.read(['/etc/vws.conf', os.environ['HOME'] + '/.vwsrc'])
# Parse argument

Modified vws.mkd from [dc1c3f9b66] to [5f40be7393].

262
263
264
265
266
267
268
269

270
271



272
273
274
275
276
277
278
262
263
264
265
266
267
268

269
270

271
272
273
274
275
276
277
278
279
280







-
+

-
+
+
+







**vws stoprecord** *machine*

Stop recording sound.

**vws monitor** *machine*

Attaches to the machine monitor and allows user to send monitor commands
from the keyboard and see output. Uses lockin common to all **vws**
from the keyboard and see output. Uses locking common to all **vws**
command, so you can use other **vws** command in parallel with
**monitor** command running.
**monitor** command running. Use **Ctrl-D** to exit monitor mode, because if
you send **quit** command it would quit virtual machine, not the
interaction with it.

**vws spiceuri** *machine*

Prints out URI you should feed into your spice viewer to access this
machine.

**vws list** [ **--state** ]