public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-network 0/2] add warning if sdn config in not include in /etc/network/interfaces
@ 2023-06-23 12:49 Alexandre Derumier
  2023-06-23 12:49 ` [pve-devel] [PATCH pve-network 1/2] sdn: config generation : check if interfaces.d/sdn is sourced Alexandre Derumier
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alexandre Derumier @ 2023-06-23 12:49 UTC (permalink / raw)
  To: pve-devel

- add a check at config generation
- display specific message on status if vnet is not generated


Alexandre Derumier (2):
  sdn: config generation : check if interfaces.d/sdn is sourced
  zones: status: display specific message if vnet is not generated.

 src/PVE/Network/SDN.pm                    | 11 ++++++++++-
 src/PVE/Network/SDN/Zones/Plugin.pm       | 18 +++++++++++++-----
 src/PVE/Network/SDN/Zones/QinQPlugin.pm   |  8 +-------
 src/PVE/Network/SDN/Zones/SimplePlugin.pm | 17 -----------------
 src/PVE/Network/SDN/Zones/VlanPlugin.pm   |  8 +-------
 5 files changed, 25 insertions(+), 37 deletions(-)

-- 
2.39.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH pve-network 1/2] sdn: config generation : check if interfaces.d/sdn is sourced
  2023-06-23 12:49 [pve-devel] [PATCH pve-network 0/2] add warning if sdn config in not include in /etc/network/interfaces Alexandre Derumier
@ 2023-06-23 12:49 ` Alexandre Derumier
  2023-06-23 12:49 ` [pve-devel] [PATCH pve-network 2/2] zones: status: display specific message if vnet is not generated Alexandre Derumier
  2023-07-19  9:52 ` [pve-devel] applied-series: [PATCH pve-network 0/2] add warning if sdn config in not include in /etc/network/interfaces Fabian Grünbichler
  2 siblings, 0 replies; 4+ messages in thread
From: Alexandre Derumier @ 2023-06-23 12:49 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN.pm | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/PVE/Network/SDN.pm b/src/PVE/Network/SDN.pm
index 1ad85e5..7ff550b 100644
--- a/src/PVE/Network/SDN.pm
+++ b/src/PVE/Network/SDN.pm
@@ -13,7 +13,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 +208,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};
+	    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);
 }
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH pve-network 2/2] zones: status: display specific message if vnet is not generated.
  2023-06-23 12:49 [pve-devel] [PATCH pve-network 0/2] add warning if sdn config in not include in /etc/network/interfaces Alexandre Derumier
  2023-06-23 12:49 ` [pve-devel] [PATCH pve-network 1/2] sdn: config generation : check if interfaces.d/sdn is sourced Alexandre Derumier
@ 2023-06-23 12:49 ` Alexandre Derumier
  2023-07-19  9:52 ` [pve-devel] applied-series: [PATCH pve-network 0/2] add warning if sdn config in not include in /etc/network/interfaces Fabian Grünbichler
  2 siblings, 0 replies; 4+ messages in thread
From: Alexandre Derumier @ 2023-06-23 12:49 UTC (permalink / raw)
  To: pve-devel

also cleanup duplicate code in plugins

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Zones/Plugin.pm       | 18 +++++++++++++-----
 src/PVE/Network/SDN/Zones/QinQPlugin.pm   |  8 +-------
 src/PVE/Network/SDN/Zones/SimplePlugin.pm | 17 -----------------
 src/PVE/Network/SDN/Zones/VlanPlugin.pm   |  8 +-------
 4 files changed, 15 insertions(+), 36 deletions(-)

diff --git a/src/PVE/Network/SDN/Zones/Plugin.pm b/src/PVE/Network/SDN/Zones/Plugin.pm
index 2c707b3..c2f496f 100644
--- a/src/PVE/Network/SDN/Zones/Plugin.pm
+++ b/src/PVE/Network/SDN/Zones/Plugin.pm
@@ -190,14 +190,13 @@ sub parse_tag_number_or_range {
     return (scalar(@elements) > 1);
 }
 
-sub status {
-    my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_;
+sub generate_status_message {
+    my ($class, $vnetid, $status, $ifaces) = @_;
 
     my $err_msg = [];
 
-    # ifaces to check
-    my $ifaces = [ $vnetid ];
-
+    return ["vnet is not generated. Please check you reload network task log."] if !$status->{$vnetid}->{status};
+    
     foreach my $iface (@{$ifaces}) {
         if (!$status->{$iface}->{status}) {
 	    push @$err_msg, "missing $iface";
@@ -205,7 +204,16 @@ sub status {
 	    push @$err_msg, "error $iface";
         }
     }
+
+    return $err_msg;
+}
+
+sub status {
+    my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_;
+
+    my $err_msg = $class->generate_status_message($vnetid, $status);
     return $err_msg;
+
 }
 
 
diff --git a/src/PVE/Network/SDN/Zones/QinQPlugin.pm b/src/PVE/Network/SDN/Zones/QinQPlugin.pm
index 8b9de43..7160434 100644
--- a/src/PVE/Network/SDN/Zones/QinQPlugin.pm
+++ b/src/PVE/Network/SDN/Zones/QinQPlugin.pm
@@ -198,13 +198,7 @@ sub status {
 	push @$ifaces, $svlan_iface;
     }
 
-    foreach my $iface (@{$ifaces}) {
-	if (!$status->{$iface}->{status}) {
-	    push @$err_msg, "missing $iface";
-        } elsif ($status->{$iface}->{status} ne 'pass') {
-	    push @$err_msg, "error $iface";
-	}
-    }
+    $err_msg = $class->generate_status_message($vnetid, $status, $ifaces);
     return $err_msg;
 }
 
diff --git a/src/PVE/Network/SDN/Zones/SimplePlugin.pm b/src/PVE/Network/SDN/Zones/SimplePlugin.pm
index 7757747..4922903 100644
--- a/src/PVE/Network/SDN/Zones/SimplePlugin.pm
+++ b/src/PVE/Network/SDN/Zones/SimplePlugin.pm
@@ -123,23 +123,6 @@ sub generate_sdn_config {
     return $config;
 }
 
-sub status {
-    my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_;
-
-    # ifaces to check
-    my $ifaces = [ $vnetid ];
-    my $err_msg = [];
-    foreach my $iface (@{$ifaces}) {
-	if (!$status->{$iface}->{status}) {
-	    push @$err_msg, "missing $iface";
-	} elsif ($status->{$iface}->{status} ne 'pass') {
-	    push @$err_msg, "error iface $iface";
-	}
-    }
-    return $err_msg;
-}
-
-
 sub vnet_update_hook {
     my ($class, $vnet_cfg, $vnetid, $zone_cfg) = @_;
 
diff --git a/src/PVE/Network/SDN/Zones/VlanPlugin.pm b/src/PVE/Network/SDN/Zones/VlanPlugin.pm
index 0bb6b8a..f39b71d 100644
--- a/src/PVE/Network/SDN/Zones/VlanPlugin.pm
+++ b/src/PVE/Network/SDN/Zones/VlanPlugin.pm
@@ -165,13 +165,7 @@ sub status {
 	push @$ifaces, $vnet_uplinkpeer;
     }
 
-    foreach my $iface (@{$ifaces}) {
-	if (!$status->{$iface}->{status}) {
-	    push @$err_msg, "missing $iface";
-        } elsif ($status->{$iface}->{status} ne 'pass') {
-	    push @$err_msg, "error iface $iface";
-	}
-    }
+    $err_msg = $class->generate_status_message($vnetid, $status, $ifaces);
     return $err_msg;
 }
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] applied-series: [PATCH pve-network 0/2] add warning if sdn config in not include in /etc/network/interfaces
  2023-06-23 12:49 [pve-devel] [PATCH pve-network 0/2] add warning if sdn config in not include in /etc/network/interfaces Alexandre Derumier
  2023-06-23 12:49 ` [pve-devel] [PATCH pve-network 1/2] sdn: config generation : check if interfaces.d/sdn is sourced Alexandre Derumier
  2023-06-23 12:49 ` [pve-devel] [PATCH pve-network 2/2] zones: status: display specific message if vnet is not generated Alexandre Derumier
@ 2023-07-19  9:52 ` Fabian Grünbichler
  2 siblings, 0 replies; 4+ messages in thread
From: Fabian Grünbichler @ 2023-07-19  9:52 UTC (permalink / raw)
  To: Proxmox VE development discussion

with first patch correctly attributed to me, since I wrote the change ;)
and fixed up the first warn to also be a log_warn.

also added two followups, one for the error message, the other for style
of the second patch - please shout if you notice something off with
either of those!

On June 23, 2023 2:49 pm, Alexandre Derumier wrote:
> - add a check at config generation
> - display specific message on status if vnet is not generated
> 
> 
> Alexandre Derumier (2):
>   sdn: config generation : check if interfaces.d/sdn is sourced
>   zones: status: display specific message if vnet is not generated.
> 
>  src/PVE/Network/SDN.pm                    | 11 ++++++++++-
>  src/PVE/Network/SDN/Zones/Plugin.pm       | 18 +++++++++++++-----
>  src/PVE/Network/SDN/Zones/QinQPlugin.pm   |  8 +-------
>  src/PVE/Network/SDN/Zones/SimplePlugin.pm | 17 -----------------
>  src/PVE/Network/SDN/Zones/VlanPlugin.pm   |  8 +-------
>  5 files changed, 25 insertions(+), 37 deletions(-)
> 
> -- 
> 2.39.2
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-19  9:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-23 12:49 [pve-devel] [PATCH pve-network 0/2] add warning if sdn config in not include in /etc/network/interfaces Alexandre Derumier
2023-06-23 12:49 ` [pve-devel] [PATCH pve-network 1/2] sdn: config generation : check if interfaces.d/sdn is sourced Alexandre Derumier
2023-06-23 12:49 ` [pve-devel] [PATCH pve-network 2/2] zones: status: display specific message if vnet is not generated Alexandre Derumier
2023-07-19  9:52 ` [pve-devel] applied-series: [PATCH pve-network 0/2] add warning if sdn config in not include in /etc/network/interfaces Fabian Grünbichler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal