From bbdb92debd3d239b9c76b5c2fb6a1f7200085845 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sat, 8 Sep 2018 23:32:18 -0700 Subject: [PATCH] Attempt to preserve unknown config entries --- net/netplan-lib.pl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/net/netplan-lib.pl b/net/netplan-lib.pl index 73b8dcd3f..ec174dc98 100644 --- a/net/netplan-lib.pl +++ b/net/netplan-lib.pl @@ -25,6 +25,7 @@ foreach my $f (glob("$netplan_dir/*.yaml")) { my $cfg = { 'name' => $e->{'name'}, 'fullname' => $e->{'name'}, 'file' => $f, + 'yaml' => $e, 'line' => $e->{'line'}, 'eline' => $e->{'eline'}, 'edit' => 1, @@ -211,6 +212,16 @@ else { push(@lines, $id." "."macaddress: ".$iface->{'ether'}); } + # Add all extra YAML directives from the original config + my @poss = ( "optional", "dhcp4", "dhcp6", "addresses", "gateway4", + "gateway6", "nameservers", "macaddress" ); + if ($iface->{'yaml'}) { + foreach my $y (@{$yaml->{'members'}}) { + next if (&indexof($y->{'name'}, @poss) >= 0); + push(@lines, &yaml_lines($y, $id." ")); + } + } + if ($iface->{'file'}) { # Replacing an existing interface my ($old) = grep { $_->{'fullname'} eq $iface->{'fullname'} } @$boot; @@ -582,6 +593,23 @@ foreach my $origl (@$lref) { return $rv; } +# yaml_lines(&directive, indent-string) +sub yaml_lines +{ +my ($yaml, $id) = @_; +my @rv; +push(@rv, $id.$yaml->{'name'}.":". + (ref($yaml->{'value'}) eq 'ARRAY' ? + " [".&join_addr_list(@{$yaml->{'value'}})."]" : + defined($yaml->{'value'}) ? " ".$yaml->{'value'} : "")); +if ($yaml->{'members'}) { + foreach my $m (@{$yaml->{'members'}}) { + push(@rv, &yaml_lines($m, $id." ")); + } + } +return @rv; +} + # set_parent_elines(&conf, eline) sub set_parent_elines {