[pve-devel] [PATCH cluster v4 00/15] Allow adding/deleting nodes and cluster creation over API

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Jan 9 16:15:38 CET 2018


On 1/9/18 3:52 PM, Thomas Lamprecht wrote:
> Tested with CLI tool pvecm and through API client.
> 

For convenience here two small helper to simplify testing:


Small bash script to remove the current node from the cluster automatically
(just for *testing* and simple setups)

#!/bin/bash

PEER="192.168.YY.XX" # ADAPT

if [[ -z "$1" && ! -f /etc/pve/corosync.conf ]]; then
    echo "No /etc/pve/corosync abort!"
    exit -1
fi

systemctl stop corosync pve-cluster
echo "Connect to remote node and delete us"
ssh "root@$PEER" -- 'pvecm e 1; sleep 1 && pvecm delnode lois'

echo "Remove local cluster traces and restart cfs"
pmxcfs -l
rm -rf /etc/pve/corosync.conf /etc/corosync/*
killall pmxcfs
systemctl restart pve-cluster.service corosync



Also a small perl script using the pve api client library to do a join:

#!/usr/bin/perl

use strict;
use warnings;

use PVE::APIClient::LWP;
use JSON;

sub p { print to_json($_[0], { pretty => 1, canonical => 1}); }

# TODO: ADAPT BELOW
my $ip_cluster_node = '192.168.30.31';
my $fp_cluster_node = "EB:6C:21:D8:69:C6:96:DF:FD:CB:C4:73:51:8F:0A:4D:81:FC:F3:1A:30:0C:62:34:EA:51:66:0E:96:51:91:99";
my $pass_cluster_node = "12345";

my $ip_joinee = '192.168.30.32';
my $fp_joinee = '3B:64:4E:C9:3B:95:A1:D2:B9:B6:09:90:02:D2:3D:BF:F6:DD:4B:3C:56:BB:79:63:66:39:8D:87:5E:CD:94:63';
my $pass_joinee = '12345';

my $joinee = PVE::APIClient::LWP->new(
    username => 'root at pam',
    password =>$pass_joinee,
    host => $ip_joinee,
    cached_fingerprints => {
	"$fp_joinee" => 1,
    },
);
my $cluster_node = PVE::APIClient::LWP->new(
    username => 'root at pam',
    password =>$pass_cluster_node,
    host => $ip_cluster_node,
    cached_fingerprints => {
	"$fp_cluster_node" => 1,
    },
);

my $joininfo = $cluster_node->get("/cluster/config/join", {});

p($joininfo);

my $upid = $joinee->post("/cluster/config/join", {
    hostname => $joininfo->{nodeinfo}->{addr},
    fingerprint => $joininfo->{nodeinfo}->{fp},
    password => $pass_cluster_node,
});

print "join task upid: $upid\n";

my $task_state;
my $errors = 0;
while (1) {
    eval { $task_state = $joinee->get("/nodes/localhost/tasks/$upid/status", {}) };
    if (my $err = $@) {
	warn $@;
	$errors++;
	die "to much errors from querying task state!\n" if $errors > 5;
    }

    last if $task_state->{status} eq 'stopped';
    sleep 1;
}

print "join task finished, res:\n";

p($task_state)




More information about the pve-devel mailing list