Diff
Not logged in

Differences From Artifact [c5b995c8c3]:

To Artifact [2460d33837]:


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import shlex
import shutil
import sys
import time
import pwd
import grp

VERSION = 0.8
def find_vm(name):
    """ Search and return VM directory """
    search_path = [os.path.join(pwd.getpwuid(os.getuid()).pw_dir, "VWs"),
                   config.get("directories", "SharedVMs"),
                   config.get("directories", "AutostartVMs")]
    for dirname in search_path:
        if not os.access(dirname, os.X_OK):







|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import shlex
import shutil
import sys
import time
import pwd
import grp

VERSION = "0.8.1"
def find_vm(name):
    """ Search and return VM directory """
    search_path = [os.path.join(pwd.getpwuid(os.getuid()).pw_dir, "VWs"),
                   config.get("directories", "SharedVMs"),
                   config.get("directories", "AutostartVMs")]
    for dirname in search_path:
        if not os.access(dirname, os.X_OK):
142
143
144
145
146
147
148

149
150
151
152
153
154
155
                match = re.search("file=([^,\\s]*)", line)
                if match:
                    result.append(match.group(1))
    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:







>







142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
                match = re.search("file=([^,\\s]*)", line)
                if match:
                    result.append(match.group(1))
    return result

def snapshot_mode(sock):
    """ Returns True if VM is running in snapshot mode """
    print("Entering snapshot_mode", file=sys.stderr)
    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:
170
171
172
173
174
175
176




177
178
179
180
181
182
183
    match = re.search("bridge\\.0:.*,br=(\\S+).*macaddr=(\\S+)", answer, re.S)
    if match:
        return {"iface":match.group(1), "mac":match.group(2)}
    match = re.search("user.0:.*net=([^,]+).*\n.*macaddr=(\\S+)", answer)
    if match:
        return {"iface":"user", "ip":match.group(1),
                "mac":match.group(2)}




    print(answer, file=sys.stderr)
    return {"iface":"unknown", "ip":"?", "mac":"?", "card":"?"}
#
# command implementation
#

def cmd_spiceuri(options):







>
>
>
>







171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    match = re.search("bridge\\.0:.*,br=(\\S+).*macaddr=(\\S+)", answer, re.S)
    if match:
        return {"iface":match.group(1), "mac":match.group(2)}
    match = re.search("user.0:.*net=([^,]+).*\n.*macaddr=(\\S+)", answer)
    if match:
        return {"iface":"user", "ip":match.group(1),
                "mac":match.group(2)}
    match = re.search("hub0port1:.*.br=(\\S+).*hub0port0:.*macaddr=(\\S+)",
                      answer, flags=re.S)             
    if match:
        return {"iface":match.group(1), "mac":match.group(2)}
    print(answer, file=sys.stderr)
    return {"iface":"unknown", "ip":"?", "mac":"?", "card":"?"}
#
# command implementation
#

def cmd_spiceuri(options):
288
289
290
291
292
293
294

295
296
297
298
299
300
301
    if options.gui:
        os.system((config.get('tools', 'viewer') + "&") % uri)
    elif not options.stopped:
        print("VM already running use uri %s" % uri, file=sys.stderr)

def cmd_stop(options):
    """ vws stop """

    if options.hard or snapshot_mode(options.sock):
        try:
            send_command(options.sock, 'quit')
        except IOError as ex:
            # Expect IOError here
            if str(ex).find("EOF from monitor"):
                print("monitor socket closed")







>







293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    if options.gui:
        os.system((config.get('tools', 'viewer') + "&") % uri)
    elif not options.stopped:
        print("VM already running use uri %s" % uri, file=sys.stderr)

def cmd_stop(options):
    """ vws stop """
    print("entering cmd_stop", file=sys.stderr)
    if options.hard or snapshot_mode(options.sock):
        try:
            send_command(options.sock, 'quit')
        except IOError as ex:
            # Expect IOError here
            if str(ex).find("EOF from monitor"):
                print("monitor socket closed")