From ed88a51ed13255d8dfe1143afe665fc261e992f7 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sun, 24 Jun 2018 22:02:15 -0700 Subject: [PATCH] Code for saving interfaces --- net/netplan-lib.pl | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/net/netplan-lib.pl b/net/netplan-lib.pl index 0eb829007..6d5e24cf2 100644 --- a/net/netplan-lib.pl +++ b/net/netplan-lib.pl @@ -91,13 +91,22 @@ foreach my $f (glob("$netplan_dir/*.yaml")) { return @rv; } -# save_interface(&details) +# save_interface(&details, [&all-interfaces]) # Create or update a boot-time interface sub save_interface { -my ($iface) = @_; -if ($iface->{'alias'}) { - # XXX alias interface +my ($iface, $boot) = @_; +$boot ||= [ &boot_interfaces() ]; +if ($iface->{'virtual'} ne '') { + # Find the parent config entry + my ($parent) = grep { $_->{'fullname'} eq $iface->{'name'} } + &boot_interfaces(); + $parent || &error("No interface named $iface->{'name'} exists"); + if (!$iface->{'file'}) { + # Add to complete interface list + push(@$boot, $iface); + } + &save_interface($parent, $boot); } else { # Build interface config lines @@ -116,6 +125,12 @@ else { push(@addrs, $iface->{'address6'}->[$i]."/". $iface->{'netmask6'}->[$i]); } + foreach my $a (@$boot) { + if ($a->{'virtual'} ne '' && $a->{'name'} eq $iface->{'name'}) { + push(@addrs, $a->{'address'}."/". + &mask_to_prefix($a->{'netmask'})); + } + } if (@addrs) { push(@lines, $id." "."addresses: [".join(",", @addrs)."]"); }