diff --git a/ncm-network/src/main/perl/nmstate.pm b/ncm-network/src/main/perl/nmstate.pm index ca5cfcc7a1..8753040143 100644 --- a/ncm-network/src/main/perl/nmstate.pm +++ b/ncm-network/src/main/perl/nmstate.pm @@ -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) { @@ -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;