Skip to content

Commit

Permalink
Exclude loopback interface from nmcli listing
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmanzo committed Nov 27, 2023
1 parent 441a12a commit a029e92
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/mm_network.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sub configure_static_ip {

if ($is_nm) {
my $nm_id;
my $nm_list = script_output("nmcli -t -f DEVICE,NAME c | grep '$device' | head -n1");
my $nm_list = script_output("nmcli -t -f DEVICE,NAME c | grep -v ^lo: | grep '$device' | head -n1");
($device, $nm_id) = split(':', $nm_list);

record_info('set_ip', "Device: $device\n NM ID: $nm_id\nIP: $ip\nMTU: $mtu");
Expand Down Expand Up @@ -110,7 +110,7 @@ sub configure_default_gateway {
if ($is_nm) {
my $nm_id;
# When $device is not specified grep just does nothing and first connection is selected
my $nm_list = script_output("nmcli -t -f DEVICE,NAME c | grep '$device' | head -n1");
my $nm_list = script_output("nmcli -t -f DEVICE,NAME c | grep -v ^lo: | grep '$device' | head -n1");
($device, $nm_id) = split(':', $nm_list);

assert_script_run "nmcli connection modify '$nm_id' ipv4.gateway 10.0.2.2";
Expand All @@ -128,7 +128,7 @@ sub configure_static_dns {
my $servers = join(" ", @{$conf->{nameserver}});

if ($is_nm) {
$nm_id = script_output('nmcli -t -f NAME c | head -n 1') unless ($nm_id);
$nm_id = script_output('nmcli -t -f NAME c | grep -v ^lo: | head -n 1') unless ($nm_id);

assert_script_run "nmcli connection modify '$nm_id' ipv4.dns '$servers'";
} else {
Expand Down Expand Up @@ -246,4 +246,4 @@ sub restart_networking {
record_info('network cfg', script_output('ip address show; echo; ip route show; echo; grep -v "^#" /etc/resolv.conf', proceed_on_failure => 1));
}

1;
1;

0 comments on commit a029e92

Please sign in to comment.