diff --git a/virtme/commands/run.py b/virtme/commands/run.py index 193ffe0..74e1742 100644 --- a/virtme/commands/run.py +++ b/virtme/commands/run.py @@ -123,6 +123,12 @@ def make_parser() -> argparse.ArgumentParser: nargs="?", help="Enable basic network access: user, bridge(=
), loop.", ) + g.add_argument( + "--mac-address-prefix", + action="store", + default=None, + help="The MAC address, excluding the last octet, to assign to the NIC interface, e.g. 52:54:00:12:34", + ) g.add_argument( "--balloon", action="store_true", @@ -1329,11 +1335,17 @@ def do_script(shellcmd: str, ret_path=None, show_boot_console=False) -> None: if video_args: qemuargs.extend(video_args) + def get_mac(index): + if args.mac_address_prefix is None: + return "" + return ",mac=%s:%02d" % (args.mac_address_prefix, index) + if args.net: extend_dhcp = False index = 0 for net in args.net: - qemuargs.extend(["-device", "%s,netdev=n%d" % (arch.virtio_dev_type("net"), index)]) + qemuargs.extend(["-device", "%s,netdev=n%d%s" % + (arch.virtio_dev_type("net"), index, get_mac(index))]) if net == "user": qemuargs.extend(["-netdev", "user,id=n%d" % index]) extend_dhcp = True @@ -1348,7 +1360,8 @@ def do_script(shellcmd: str, ret_path=None, show_boot_console=False) -> None: hubid = index qemuargs.extend(["-netdev", "hubport,id=n%d,hubid=%d" % (index, hubid)]) index += 1 - qemuargs.extend(["-device", "%s,netdev=n%d" % (arch.virtio_dev_type("net"), index)]) + qemuargs.extend(["-device", "%s,netdev=n%d%s" % + (arch.virtio_dev_type("net"), index, get_mac(index))]) qemuargs.extend(["-netdev", "hubport,id=n%d,hubid=%d" % (index, hubid)]) else: arg_fail("--net: invalid choice: '%s' (choose from user, bridge(=
), loop)" % net) diff --git a/virtme_ng/run.py b/virtme_ng/run.py index 08954cd..9aa5e0c 100644 --- a/virtme_ng/run.py +++ b/virtme_ng/run.py @@ -352,6 +352,13 @@ def make_parser(): help="Enable network access: user, bridge(=
), loop", ) + parser.add_argument( + "--mac-address-prefix", + "-M", + action="store", + help="The MAC address, excluding the last octet, to assign to the NIC interface, e.g. 52:54:00:12:34", + ) + parser.add_argument( "--disk", "-D", @@ -934,6 +941,12 @@ def _get_virtme_network(self, args): else: self.virtme_param["network"] = "" + def _get_virtme_mac_address_prefix(self, args): + if args.mac_address_prefix is not None: + self.virtme_param["mac_address_prefix"] = "--mac-address-prefix " + args.mac_address_prefix + else: + self.virtme_param["mac_address_prefix"] = "" + def _get_virtme_disk(self, args): if args.disk is not None: disk_str = "" @@ -1088,6 +1101,7 @@ def run(self, args): self._get_virtme_no_virtme_ng_init(args) self._get_virtme_mods(args) self._get_virtme_network(args) + self._get_virtme_mac_address_prefix(args) self._get_virtme_disk(args) self._get_virtme_sound(args) self._get_virtme_disable_microvm(args) @@ -1126,6 +1140,7 @@ def run(self, args): + f'{self.virtme_param["no_virtme_ng_init"]} ' + f'{self.virtme_param["mods"]} ' + f'{self.virtme_param["network"]} ' + + f'{self.virtme_param["mac_address_prefix"]} ' + f'{self.virtme_param["disk"]} ' + f'{self.virtme_param["sound"]} ' + f'{self.virtme_param["disable_microvm"]} '