]> git.puffer.fish Git - matthieu/pve-network.git/commitdiff
sdn: config generation : check if interfaces.d/sdn is sourced
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 19 Jul 2023 09:35:00 +0000 (11:35 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 19 Jul 2023 09:46:51 +0000 (11:46 +0200)
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
src/PVE/Network/SDN.pm

index 1ad85e5b763586344b1060a4dcaefc47c3168775..057034fbc1a811af7b2103d1faecf71b01444a7e 100644 (file)
@@ -6,6 +6,8 @@ use warnings;
 use Data::Dumper;
 use JSON;
 
+use PVE::INotify;
+
 use PVE::Network::SDN::Vnets;
 use PVE::Network::SDN::Zones;
 use PVE::Network::SDN::Controllers;
@@ -13,7 +15,7 @@ use PVE::Network::SDN::Subnets;
 
 use PVE::Tools qw(extract_param dir_glob_regex run_command);
 use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
-
+use PVE::RESTEnvironment qw(log_warn);
 
 my $running_cfg = "sdn/.running-config";
 
@@ -208,6 +210,15 @@ sub get_local_vnets {
 
 sub generate_zone_config {
     my $raw_config = PVE::Network::SDN::Zones::generate_etc_network_config();
+    if ($raw_config) {
+       eval {
+           my $net_cfg = PVE::INotify::read_file('interfaces', 1);
+           my $opts = $net_cfg->{data}->{options};
+           log_warn("missing 'source /etc/network/interfaces.d/sdn' directive for SDN support!\n")
+               if ! grep { $_->[1] =~ m!^source /etc/network/interfaces.d/(:?sdn|\*)! } @$opts;
+       };
+       log_warn("Failed to read network interfaces definition - $@") if $@;
+    }
     PVE::Network::SDN::Zones::write_etc_network_config($raw_config);
 }