improvements in networking
- macvtaps working - only 1 dnsmasq service per namespace - vms binds to networking services - lans with domains - vms no longer assigned same ip (machine id issues) -
This commit is contained in:
parent
3d27f32c03
commit
4254ebabaa
5 changed files with 93 additions and 37 deletions
|
|
@ -41,6 +41,7 @@ let
|
|||
create = ''
|
||||
ip link add link ${macvtapNetworkCfg.uplink.iface} name ${macvtapInterfaceName} type macvtap mode bridge
|
||||
ip link set ${macvtapInterfaceName} netns ${netName}.vmix
|
||||
ip netns exec ${netName}.vmix ip link set dev ${macvtapInterfaceName} up
|
||||
'';
|
||||
delete = ''
|
||||
ip netns exec ${netName}.vmix ip link del ${macvtapInterfaceName}
|
||||
|
|
@ -66,7 +67,13 @@ let
|
|||
concatStringsSep "\n" (builtins.map (macvtap: macvtap.delete) allMacvtaps)
|
||||
);
|
||||
|
||||
osImage = vmixLib.customizeImage vmCfg.disks.os.file { name = vmCfg.name; };
|
||||
osImage = vmixLib.customizeImage vmCfg.disks.os.file {
|
||||
name = vmCfg.name;
|
||||
commands = ''
|
||||
truncate /etc/machine-id
|
||||
run-command systemd-machine-id-setup
|
||||
'';
|
||||
};
|
||||
|
||||
qemuStartVMScript = pkgs.writeShellScript "${vmCfg.name}-qemu-vmix" ''
|
||||
exec qemu-system-${vmCfg.arch} \
|
||||
|
|
@ -96,20 +103,19 @@ let
|
|||
-device virtio-net-pci,netdev=user \
|
||||
"} \
|
||||
${optionalString (vmCfg.boot.menu == true) "-boot menu=on"} \
|
||||
#${optionalString (length vmCfg.boot.order > 0) "-boot order=${concatStringsSep "," vmCfg.boot.order}"}
|
||||
|
||||
# ${concatMapStrings (macvtap: ''
|
||||
# -device virtio-net-pci,netdev=macvtap-${macvtap.name} \
|
||||
# -netdev tap,id=macvtap-${macvtap.name},ifname=${macvtap.iface},script=no,downscript=no \
|
||||
# '') allMacvtaps} \
|
||||
${concatStrings (imap1 (i: macvtap: ''
|
||||
-device virtio-net-pci,netdev=macvtap-${macvtap.name},mac=$(ip l show ${macvtap.iface} | awk '/link\/ether/{print $2}') \
|
||||
-netdev tap,id=macvtap-${macvtap.name},fd=${toString (i+2)} ${toString (i+2)}<>/dev/tap$(ip l show ${macvtap.iface} | awk -F':' '/${macvtap.iface}/{print $1}') \
|
||||
'') allMacvtaps)} \
|
||||
#${optionalString (length vmCfg.boot.order > 0) "-boot order=${concatStringsSep "," vmCfg.boot.order}"} \
|
||||
'';
|
||||
in
|
||||
{
|
||||
"vm.vmix@${vmCfg.name}" = rec {
|
||||
requires = [ "net.vmix@${netCfg.name}.target" "macvtaps.vm.vmix@${vmCfg.name}.service" ];
|
||||
bindsTo = [ "net.vmix@${netCfg.name}.target" "macvtaps.vm.vmix@${vmCfg.name}.service" ];
|
||||
unitConfig.JoinsNamespaceOf = "ns.net.vmix@${netCfg.name}.service";
|
||||
after = requires;
|
||||
path = with pkgs; [ iproute2 qemu ];
|
||||
after = bindsTo;
|
||||
path = with pkgs; [ iproute2 qemu gawk ];
|
||||
serviceConfig = {
|
||||
ExecStartPre = createTapsforLansScript;
|
||||
ExecStart = qemuStartVMScript;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue