public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Alexandre Derumier <aderumier@odiso.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH V2 pve-network 4/4] sdn: fix : pending parser
Date: Wed, 25 Nov 2020 10:01:39 +0100	[thread overview]
Message-ID: <20201125090139.3553272-5-aderumier@odiso.com> (raw)
In-Reply-To: <20201125090139.3553272-1-aderumier@odiso.com>

---
 PVE/API2/Network/SDN/Zones.pm   | 12 +++++++--
 PVE/Network/SDN.pm              | 45 ++++++++++++++++++++++++++++++---
 PVE/Network/SDN/Zones/Plugin.pm | 28 --------------------
 3 files changed, 52 insertions(+), 33 deletions(-)

diff --git a/PVE/API2/Network/SDN/Zones.pm b/PVE/API2/Network/SDN/Zones.pm
index 5ae577b..5bbdd36 100644
--- a/PVE/API2/Network/SDN/Zones.pm
+++ b/PVE/API2/Network/SDN/Zones.pm
@@ -38,12 +38,20 @@ my $api_sdn_zones_config = sub {
     $scfg->{digest} = $cfg->{digest};
 
     if ($scfg->{nodes}) {
-        $scfg->{nodes} = PVE::Network::SDN::Zones::Plugin->encode_value($scfg->{type}, 'nodes', $scfg->{nodes});
+        $scfg->{nodes} = PVE::Network::SDN::encode_value($scfg->{type}, 'nodes', $scfg->{nodes});
+    }
+
+    if ($scfg->{exitnodes}) {
+        $scfg->{exitnodes} = PVE::Network::SDN::encode_value($scfg->{type}, 'exitnodes', $scfg->{exitnodes});
     }
 
     my $pending = $scfg->{pending};
     if ($pending->{nodes}) {
-        $pending->{nodes} = PVE::Network::SDN::Zones::Plugin->encode_value($scfg->{type}, 'nodes', $pending->{nodes});
+        $pending->{nodes} = PVE::Network::SDN::encode_value($scfg->{type}, 'nodes', $pending->{nodes});
+    }
+
+    if ($pending->{exitnodes}) {
+        $pending->{exitnodes} = PVE::Network::SDN::encode_value($scfg->{type}, 'exitnodes', $pending->{exitnodes});
     }
 
     return $scfg;
diff --git a/PVE/Network/SDN.pm b/PVE/Network/SDN.pm
index 3cd73ff..c0c5672 100644
--- a/PVE/Network/SDN.pm
+++ b/PVE/Network/SDN.pm
@@ -6,6 +6,8 @@ use warnings;
 use Data::Dumper;
 use JSON;
 
+use PVE::JSONSchema;
+
 use PVE::Network::SDN::Vnets;
 use PVE::Network::SDN::Zones;
 use PVE::Network::SDN::Controllers;
@@ -96,7 +98,11 @@ sub pending_config {
 	    $pending->{$id}->{$key} = $running_object->{$key};
 	    if(!keys %{$config_object}) {
 		$pending->{$id}->{state} = "deleted";
-	    } elsif ($running_object->{$key} ne $config_object->{$key}) {
+	    } elsif (!defined($config_object->{$key})) {
+		$pending->{$id}->{"pending"}->{$key} = 'deleted';
+		$pending->{$id}->{state} = "changed";
+	    } elsif (PVE::Network::SDN::encode_value(undef, $key, $running_object->{$key})
+			 ne PVE::Network::SDN::encode_value(undef, $key, $config_object->{$key})) {
 		$pending->{$id}->{state} = "changed";
 	    }
 	}
@@ -107,8 +113,8 @@ sub pending_config {
 	my $config_object = $config_objects->{$id};
 
 	foreach my $key (sort keys %{$config_object}) {
-	    my $config_value = $config_object->{$key} if $config_object->{$key};
-	    my $running_value = $running_object->{$key} if $running_object->{$key};
+	    my $config_value = PVE::Network::SDN::encode_value(undef, $key, $config_object->{$key}) if $config_object->{$key};
+	    my $running_value = PVE::Network::SDN::encode_value(undef, $key, $running_object->{$key}) if $running_object->{$key};
 	    if($key eq 'type' || $key eq 'vnet') {
 		$pending->{$id}->{$key} = $config_value;
 	    } else {
@@ -210,5 +216,38 @@ sub generate_controller_config {
     PVE::Network::SDN::Controllers::reload_controller() if $reload;
 }
 
+
+sub decode_value {
+    my ($type, $key, $value) = @_;
+
+    if ($key eq 'nodes') {
+        my $res = {};
+
+        foreach my $node (PVE::Tools::split_list($value)) {
+            if (PVE::JSONSchema::pve_verify_node_name($node)) {
+                $res->{$node} = 1;
+            }
+        }
+
+        return $res;
+    }
+
+   return $value;
+}
+
+sub encode_value {
+    my ($type, $key, $value) = @_;
+
+    if ($key eq 'nodes' || $key eq 'exitnodes') {
+        if(ref($value) eq 'HASH') {
+            return join(',', sort keys(%$value));
+        } else {
+            return $value;
+        }
+    }
+
+    return $value;
+}
+
 1;
 
diff --git a/PVE/Network/SDN/Zones/Plugin.pm b/PVE/Network/SDN/Zones/Plugin.pm
index 8592e3c..ebb5c7e 100644
--- a/PVE/Network/SDN/Zones/Plugin.pm
+++ b/PVE/Network/SDN/Zones/Plugin.pm
@@ -55,34 +55,6 @@ sub private {
     return $defaultData;
 }
 
-sub decode_value {
-    my ($class, $type, $key, $value) = @_;
-
-    if ($key eq 'nodes') {
-        my $res = {};
-
-        foreach my $node (PVE::Tools::split_list($value)) {
-            if (PVE::JSONSchema::pve_verify_node_name($node)) {
-                $res->{$node} = 1;
-            }
-        }
-
-        return $res;
-    }
-
-   return $value;
-}
-
-sub encode_value {
-    my ($class, $type, $key, $value) = @_;
-
-    if ($key eq 'nodes') {
-        return join(',', keys(%$value));
-    }
-
-    return $value;
-}
-
 sub parse_section_header {
     my ($class, $line) = @_;
 
-- 
2.20.1




  parent reply	other threads:[~2020-11-25  9:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-25  9:01 [pve-devel] [PATCH V2 pve-network 0/4] add ebgp-evpn support Alexandre Derumier
2020-11-25  9:01 ` [pve-devel] [PATCH V2 pve-network 1/4] controllers: improve bgp-evpn Alexandre Derumier
2020-11-25  9:01 ` [pve-devel] [PATCH V2 pve-network 2/4] zones: evpn : add support for loopback Alexandre Derumier
2020-11-25  9:01 ` [pve-devel] [PATCH V2 pve-network 3/4] update test documentation Alexandre Derumier
2020-11-25  9:01 ` Alexandre Derumier [this message]
2020-11-25 14:00 ` [pve-devel] applied-series: [PATCH V2 pve-network 0/4] add ebgp-evpn support Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201125090139.3553272-5-aderumier@odiso.com \
    --to=aderumier@odiso.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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