Skip to content

Commit

Permalink
net: allow to specify the bridge iface
Browse files Browse the repository at this point in the history
Before this modification, '-n bridge' required an interface called
'virbr0'. That's probably OK when only one interface is required, but
not when multiple interfaces are.

Instead of incrementing the index at the end of 'virbr', the option can
now receive a specified bridge interface for more flexibility, e.g.

  -n bridge=br0 -n bridge=br1

Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
  • Loading branch information
matttbe committed Nov 27, 2024
1 parent 7603efb commit 4a8d556
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 8 additions & 5 deletions virtme/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def make_parser() -> argparse.ArgumentParser:
action="append",
const="user",
nargs="?",
choices=["user", "bridge", "loop"],
help="Enable basic network access.",
help="Enable basic network access: user, bridge(=<br>), loop.",
)
g.add_argument(
"--balloon",
Expand Down Expand Up @@ -1338,8 +1337,12 @@ def do_script(shellcmd: str, ret_path=None, show_boot_console=False) -> None:
if net == "user":
qemuargs.extend(["-netdev", "user,id=n%d" % index])
extend_dhcp = True
elif net == "bridge":
qemuargs.extend(["-netdev", "bridge,id=n%d,br=virbr0" % index])
elif net == "bridge" or net.startswith("bridge="):
if len(net) > 7 and net[6] == '=':
bridge = net[7:]
else:
bridge = "virbr0"
qemuargs.extend(["-netdev", "bridge,id=n%d,br=%s" % (index, bridge)])
extend_dhcp = True
elif net == "loop":
hubid = index
Expand All @@ -1348,7 +1351,7 @@ def do_script(shellcmd: str, ret_path=None, show_boot_console=False) -> None:
qemuargs.extend(["-device", "%s,netdev=n%d" % (arch.virtio_dev_type("net"), index)])
qemuargs.extend(["-netdev", "hubport,id=n%d,hubid=%d" % (index, hubid)])
else:
assert False
arg_fail("--net: invalid choice: '%s' (choose from user, bridge(=<br>), loop)" % net)
index += 1
if extend_dhcp:
kernelargs.extend(["virtme.dhcp"])
Expand Down
3 changes: 1 addition & 2 deletions virtme_ng/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ def make_parser():
"--network",
"-n",
action="append",
choices=['user', 'bridge', 'loop'],
help="Enable network access",
help="Enable network access: user, bridge(=<br>), loop",
)

parser.add_argument(
Expand Down

0 comments on commit 4a8d556

Please sign in to comment.