Added a start for configured interfaces found to be down after boot.

* Added the 'up' parameter to Network->collect_data() that will bring up
  an interface we configured that is down.
* Updated scan-network to call Network->collect_data() with 'up' if the
  uptime is less than ten minutes.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 5 months ago
parent 6d121dc0c0
commit 6826b12188
  1. 33
      Anvil/Tools/Network.pm
  2. 13
      scancore-agents/scan-network/scan-network

@ -564,6 +564,10 @@ Parameters;
If this is set to C<< 1 >>, any connetions found to be down and not referencing any devices will be assigned the unroutable IP C<< 169.0.0.x >>, where C<< x >> is a sequential number. This should bring up unconfigured devices.
=head3 up (optional, default '0')
If this is set to C<< 1 >>, any configured interfaces (determined by checking for C<< match.interface-name >>) that are down will be started, if possible.
=cut
sub collect_data
{
@ -574,8 +578,10 @@ sub collect_data
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Network->check_internet()" }});
my $start = defined $parameter->{start} ? $parameter->{start} : "";
my $up = defined $parameter->{up} ? $parameter->{up} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
start => $start,
up => $up,
}});
if (exists $anvil->data->{nmcli})
@ -1121,6 +1127,29 @@ sub collect_data
}
}
# Should we bring up interfaces?
if ($up)
{
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{nmcli}{uuid}})
{
$anvil->data->{nmcli}{uuid}{$uuid}{'match.interface-name'} = "" if not defined $anvil->data->{nmcli}{uuid}{$uuid}{'match.interface-name'};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::uuid::${uuid}::active" => $anvil->data->{nmcli}{uuid}{$uuid}{active},
"nmcli::uuid::${uuid}::match.interface-name" => $anvil->data->{nmcli}{uuid}{$uuid}{'match.interface-name'},
}});
if ((not $anvil->data->{nmcli}{uuid}{$uuid}{active}) && ($anvil->data->{nmcli}{uuid}{$uuid}{'match.interface-name'}))
{
my $shell_call = $anvil->data->{path}{exe}{nmcli}." connection up ".$uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
}
}
}
# Should we start interfaces?
if ($start)
{
@ -1132,8 +1161,8 @@ sub collect_data
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{nmcli}{uuid}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::uuid::${uuid}::active" => $anvil->data->{nmcli}{uuid}{$uuid}{active},
"nmcli::uuid::${uuid}::active" => $anvil->data->{nmcli}{uuid}{$uuid}{'connection.interface-name'},
"nmcli::uuid::${uuid}::active" => $anvil->data->{nmcli}{uuid}{$uuid}{active},
"nmcli::uuid::${uuid}::connection.interface-name" => $anvil->data->{nmcli}{uuid}{$uuid}{'connection.interface-name'},
}});
if ((not $anvil->data->{nmcli}{uuid}{$uuid}{active}) && (not $anvil->data->{nmcli}{uuid}{$uuid}{'connection.interface-name'}))
{

@ -536,7 +536,18 @@ sub collect_data
my ($anvil) = @_;
# Read in data from Network Manager
$anvil->Network->collect_data({debug => 2});
my $uptime = $anvil->Get->uptime;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uptime => $uptime }});
if ($uptime < 600)
{
# Check for / start down but configured interfaces.
$anvil->Network->collect_data({up => 1, debug => 2});
}
else
{
# Just collect data.
$anvil->Network->collect_data({debug => 2});
}
### TODO: We can get the IPs from collect_data, we should phase this out.
# The 'local_host' is needed to pull data recorded by Network->get_ips();

Loading…
Cancel
Save