[pve-devel] [RFC cluster 5/6] api/join: check if peer supports addnode over API

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Nov 27 14:13:02 CET 2017


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

I tend to not check for the version, but simply do the POST request on
"/cluster/config/join" and handle the "not implemented" error instead,
seems to be straight forward and does not needs an timed version bump.

 data/PVE/API2/ClusterConfig.pm | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/data/PVE/API2/ClusterConfig.pm b/data/PVE/API2/ClusterConfig.pm
index 9a4d9f5..97706d9 100644
--- a/data/PVE/API2/ClusterConfig.pm
+++ b/data/PVE/API2/ClusterConfig.pm
@@ -96,6 +96,23 @@ my $config_change_lock = sub {
     });
 };
 
+my $peer_can_use_api = sub {
+    my ($conn) = @_;
+
+    print "Probe peer cluster package version...\n";
+    my $res = $conn->get("/nodes/localhost/apt/versions");
+
+    my $api_ok = undef;
+    foreach my $pkg (@$res) {
+	next if $pkg->{Package} ne 'pve-cluster';
+	if ($pkg->{OldVersion} =~ m/^(\d\.\d)-(\d+)/) {
+	    my ($version, $release) = ($1, $2);
+	    $api_ok = 1 if $version >= 5.1 && $release >= 16;
+	}
+    }
+
+    return $api_ok;
+};
 
 __PACKAGE__->register_method ({
     name => 'join',
@@ -197,6 +214,10 @@ __PACKAGE__->register_method ({
 
 	print "Login succeeded.\n";
 
+	if (!$peer_can_use_api->($conn)) {
+	    die "Cannot use API to join, peer is not up to date!\n";
+	}
+
 	my $args = {
 	    node => $nodename,
 	};
-- 
2.11.0





More information about the pve-devel mailing list