Skip to content

Commit

Permalink
network: nmstate use new ordering logic for nmstate interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
stdweird committed Sep 20, 2024
1 parent 68ac9cc commit 8dbea98
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,11 @@ sub generate_nmstate_config
$ifaceconfig->{state} = "up";
$ifaceconfig->{bridge}->{options} = {
stp => $YTRUE,
port => delete $ifaceconfig->{ports},
};
$ifaceconfig->{bridge}->{port} => delete $ifaceconfig->{ports};
} elsif (lc($iface->{type} || '') eq 'ovsintport') {
$ifaceconfig->{type} = "ovs-interface";
$ifaceconfig->{state} = "up";
} elsif ($is_eth) {
$ifaceconfig->{type} = "ethernet";
if ($is_partof_bond) {
Expand Down Expand Up @@ -671,18 +672,35 @@ sub clear_inactive_nm_connections
}
}

# return ordered list of interface keys
sub nmstate_order($self, $ifaces)
{
my ($self, $ifaces) = @_;

# do no use the value 0 in the score; it will break the || $default logic when the value is 0
my $default = 10; # lowest / first
my $score = {
bond => 20, # slaves need to be alive
"ovs-interface" => 30, # can only be ports of a bridge, this could probably be 0 as well
"ovs-bridge" => 40, # needs ports alive; these can be anything with lower score
};

# compare on (score or default)
my @sorted_ifnames = sort {
($score->{$ifaces->{$a}->{$type}} || $default) <=> ($score->{$ifaces->{$b}->{$type}} || $default)
} keys %$ifaces;

return @sorted_ifaces;
}


sub nmstate_apply
{
my ($self, $exifiles, $ifup, $ifdown, $nwsrv) = @_;


my @ifaces = sort keys %$ifup;
my @ifaces_down = sort keys %$ifdown;

# primitive re-ordering to make sure eg bond are apply'ed last, and removed first
my $order_pattern = '^bond';
@ifaces = ((grep {$_ !~ m/$order_pattern/} @ifaces), (grep {$_ =~ m/$order_pattern/} @ifaces));
@ifaces_down = ((grep {$_ =~ m/$order_pattern/} @ifaces_down), (grep {$_ !~ m/$order_pattern/} @ifaces_down));
my @ifaces = $self->nmstate_order($ifup);
my @ifaces_down = reverse $self->nmstate_order($ifdown);

my $action;

Expand Down

0 comments on commit 8dbea98

Please sign in to comment.