Attempt to preserve unknown config entries

This commit is contained in:
Jamie Cameron
2018-09-08 23:32:18 -07:00
parent 1ab259a7ee
commit bbdb92debd

View File

@ -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
{