46
47
48
49
50
51
52
53
54
55
56
57
58
59
  | 
    readfd, dummy_w, dummy_x = select.select([sock], [], [], 0.1)
    if sock in readfd:
        dummy_greeting = sock.recv(1024)
    return sock
def send_command(sock, command):
    """ Sends monitor command to given socket and returns answer """
    fcntl.flock(sock, fcntl.LOCK_EX)
    try:
        # There can be stray (qemu) prompt in the socket. Try to drain
        # it
        try:
            sock.recv(64, socket.MSG_DONTWAIT)
        except socket.error as ex:
 | 
>
>
  | 
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  | 
    readfd, dummy_w, dummy_x = select.select([sock], [], [], 0.1)
    if sock in readfd:
        dummy_greeting = sock.recv(1024)
    return sock
def send_command(sock, command):
    """ Sends monitor command to given socket and returns answer """
    if sock is None:
        raise RuntimeError("None socket is passed to send_command")
    fcntl.flock(sock, fcntl.LOCK_EX)
    try:
        # There can be stray (qemu) prompt in the socket. Try to drain
        # it
        try:
            sock.recv(64, socket.MSG_DONTWAIT)
        except socket.error as ex:
 | 
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
  | 
    Checks if bridge listed in network configuration
    exists on this machine, and replaces it with default one
    from config, if not so
    """
    f = open(filename, "r+")
    data = f.read()
    idx0 = data.find("-net bridge,br=")
    if idx != -1:
        idx = data.find("=", idx0)
        idx += 1
        idx2 = data.find(" ", idx)
        bridgename = data[idx:idx2]
        if not bridgename in list_bridges():
            net = config.get("create options", "net")
            if net == "user":
 | 
|
  | 
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
  | 
    Checks if bridge listed in network configuration
    exists on this machine, and replaces it with default one
    from config, if not so
    """
    f = open(filename, "r+")
    data = f.read()
    idx0 = data.find("-net bridge,br=")
    if idx0 != -1:
        idx = data.find("=", idx0)
        idx += 1
        idx2 = data.find(" ", idx)
        bridgename = data[idx:idx2]
        if not bridgename in list_bridges():
            net = config.get("create options", "net")
            if net == "user":
 | 
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
  | 
        # Check for snapshot
        snapshot_id = check_for_snapshot(options.dir)
        if snapshot_id is not None:
            arg = arg + " -loadvm " + snapshot_id
        # Check for correct brige name
        try:
            os.stat("monitor")
        except OSError:
            # We cannot find monitor socket. So this machine might be
            # never run on this host
            fix_bridge_name("start")
        os.system("./start%s" % arg)
        os.chdir(cwd)
        time.sleep(2)
        options.sock = connect_vm(options.dir)
        if snapshot_id:
            send_command(options.sock, "delvm " + snapshot_id)
    else:
        if options.snapshot or options.args or options.password:
            print("Cannot change qemu options. " +
                  "VM is already running", file=sys.stderr)
        if options.cdrom:
 | 
|
>
>
>
  | 
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
  | 
        # Check for snapshot
        snapshot_id = check_for_snapshot(options.dir)
        if snapshot_id is not None:
            arg = arg + " -loadvm " + snapshot_id
        # Check for correct brige name
        try:
            os.stat("monitor")
        except FileNotFoundError:
            # We cannot find monitor socket. So this machine might be
            # never run on this host
            fix_bridge_name("start")
        os.system("./start%s" % arg)
        os.chdir(cwd)
        time.sleep(2)
        options.sock = connect_vm(options.dir)
        if options.sock is None:
            print("VM start failed", file=sys.stderr)
            sys.exit(1)
        if snapshot_id:
            send_command(options.sock, "delvm " + snapshot_id)
    else:
        if options.snapshot or options.args or options.password:
            print("Cannot change qemu options. " +
                  "VM is already running", file=sys.stderr)
        if options.cdrom:
 |