mirror of
https://git.proxmox.com/git/pve-network
synced 2025-08-16 15:11:20 +00:00
add new status sub and move code from test
old status sub was renamed ifquery_check also check if local config exist or if local config is too old. (fixme : compare mtime, maybe could we use some kind of version for this?) we can have 4 status code: - pending : local config is absent but sdn.cfg exist - unknown : local config is too old, we can't be sure of the running state - error : local config is present, but don't match the running state - available : all is ok, local config is present and match running state. Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
parent
80348b2d6f
commit
e424c7ac28
@ -65,7 +65,7 @@ sub complete_sdn {
|
|||||||
return $cmdname eq 'add' ? [] : [ PVE::Network::SDN::sdn_ids($cfg) ];
|
return $cmdname eq 'add' ? [] : [ PVE::Network::SDN::sdn_ids($cfg) ];
|
||||||
}
|
}
|
||||||
|
|
||||||
sub status {
|
sub ifquery_check {
|
||||||
|
|
||||||
my $cmd = ['ifquery', '-a', '-c', '-o','json'];
|
my $cmd = ['ifquery', '-a', '-c', '-o','json'];
|
||||||
|
|
||||||
@ -161,7 +161,63 @@ sub write_etc_network_config {
|
|||||||
$writefh->close();
|
$writefh->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub status {
|
||||||
|
|
||||||
|
my $cluster_sdn_file = "/etc/pve/sdn.cfg";
|
||||||
|
my $local_sdn_file = "/etc/network/interfaces.d/sdn";
|
||||||
|
my $err_config = undef;
|
||||||
|
|
||||||
|
return if !-e $cluster_sdn_file;
|
||||||
|
|
||||||
|
if (!-e $local_sdn_file) {
|
||||||
|
warn "local sdn network configuration is not yet generated, please reload";
|
||||||
|
$err_config = 'pending';
|
||||||
|
} else {
|
||||||
|
# fixme : use some kind of versioning info?
|
||||||
|
my $cluster_sdn_timestamp = (stat($cluster_sdn_file))[9];
|
||||||
|
my $local_sdn_timestamp = (stat($local_sdn_file))[9];
|
||||||
|
|
||||||
|
if ($local_sdn_timestamp < $cluster_sdn_timestamp) {
|
||||||
|
warn "local sdn network configuration is too old, please reload";
|
||||||
|
$err_config = 'unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
my $status = ifquery_check();
|
||||||
|
|
||||||
|
my $network_cfg = PVE::Cluster::cfs_read_file('sdn.cfg');
|
||||||
|
my $vnet_cfg = undef;
|
||||||
|
my $transport_cfg = undef;
|
||||||
|
|
||||||
|
my $vnet_status = {};
|
||||||
|
my $transport_status = {};
|
||||||
|
|
||||||
|
foreach my $id (keys %{$network_cfg->{ids}}) {
|
||||||
|
if ($network_cfg->{ids}->{$id}->{type} eq 'vnet') {
|
||||||
|
my $transportzone = $network_cfg->{ids}->{$id}->{transportzone};
|
||||||
|
$vnet_status->{$id}->{transportzone} = $transportzone;
|
||||||
|
$transport_status->{$transportzone}->{status} = 'available' if !defined($transport_status->{$transportzone}->{status});
|
||||||
|
|
||||||
|
if($err_config) {
|
||||||
|
$vnet_status->{$id}->{status} = $err_config;
|
||||||
|
$transport_status->{$transportzone}->{status} = $err_config;
|
||||||
|
} elsif ($status->{$id}->{status} && $status->{$id}->{status} eq 'pass') {
|
||||||
|
$vnet_status->{$id}->{status} = 'available';
|
||||||
|
my $bridgeport = $status->{$id}->{config}->{'bridge-ports'};
|
||||||
|
|
||||||
|
if ($status->{$bridgeport}->{status} && $status->{$bridgeport}->{status} ne 'pass') {
|
||||||
|
$vnet_status->{$id}->{status} = 'error';
|
||||||
|
$transport_status->{$transportzone}->{status} = 'error';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$vnet_status->{$id}->{status} = 'error';
|
||||||
|
$transport_status->{$transportzone}->{status} = 'error';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return($transport_status, $vnet_status);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,44 +1,9 @@
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use File::Copy;
|
|
||||||
use PVE::Cluster qw(cfs_read_file);
|
|
||||||
|
|
||||||
use PVE::Network::SDN;
|
use PVE::Network::SDN;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use PVE::Network::SDN::Plugin;
|
|
||||||
use PVE::Network::SDN::VnetPlugin;
|
|
||||||
use PVE::Network::SDN::VlanPlugin;
|
|
||||||
use PVE::Network::SDN::VxlanMulticastPlugin;
|
|
||||||
|
|
||||||
|
my ($transport_status, $vnet_status) = PVE::Network::SDN::status();
|
||||||
my $status = PVE::Network::SDN::status();
|
|
||||||
|
|
||||||
my $network_cfg = PVE::Cluster::cfs_read_file('networks.cfg');
|
|
||||||
my $vnet_cfg = undef;
|
|
||||||
my $transport_cfg = undef;
|
|
||||||
|
|
||||||
my $vnet_status = {};
|
|
||||||
my $transport_status = {};
|
|
||||||
|
|
||||||
foreach my $id (keys %{$network_cfg->{ids}}) {
|
|
||||||
if ($network_cfg->{ids}->{$id}->{type} eq 'vnet') {
|
|
||||||
my $transportzone = $network_cfg->{ids}->{$id}->{transportzone};
|
|
||||||
$transport_status->{$transportzone}->{status} = 1 if !defined($transport_status->{$transportzone}->{status});
|
|
||||||
|
|
||||||
if ($status->{$id}->{status} && $status->{$id}->{status} eq 'pass') {
|
|
||||||
$vnet_status->{$id}->{status} = 1;
|
|
||||||
my $bridgeport = $status->{$id}->{config}->{'bridge-ports'};
|
|
||||||
|
|
||||||
if ($status->{$bridgeport}->{status} && $status->{$bridgeport}->{status} ne 'pass') {
|
|
||||||
$vnet_status->{$id}->{status} = 0;
|
|
||||||
$transport_status->{$transportzone}->{status} = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$vnet_status->{$id}->{status} = 0;
|
|
||||||
$transport_status->{$transportzone}->{status} = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print Dumper($vnet_status);
|
print Dumper($vnet_status);
|
||||||
print Dumper($transport_status);
|
print Dumper($transport_status);
|
||||||
|
Loading…
Reference in New Issue
Block a user