]> git.proxmox.com Git - pve-cluster.git/commitdiff
api/cluster: add endpoint to GET cluster join information
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 1 Dec 2017 12:57:42 +0000 (13:57 +0100)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 16 Feb 2018 12:50:46 +0000 (13:50 +0100)
Returns all relevant information for joining this cluster over the
current connected node securely over the API, address, fingerprint,
totem config section and (not directly needed but possibly useful)
cluster configuration digest.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
data/PVE/API2/ClusterConfig.pm

index eeb4ff1e1e25e4601c4aced2d6271086c82a94de..8eb1c95c1c7a3d3662dcc4b21c93026fdad95c20 100644 (file)
@@ -390,6 +390,78 @@ __PACKAGE__->register_method ({
        return undef;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'join_info',
+    path => 'join',
+    method => 'GET',
+    description => "Get information needed to join this cluster over the connected node.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node', {
+               description => "The node for which the joinee gets the nodeinfo. ",
+               default => "current connected node",
+               optional => 1,
+           }),
+       },
+    },
+    returns => {
+       type => 'object',
+       additionalProperties => 0,
+       properties => {
+           nodelist => {
+               type => 'array',
+               items => {
+                   type => "object",
+                   additionalProperties => 1,
+                   properties => {
+                       name => get_standard_option('pve-node'),
+                       nodeid => get_standard_option('corosync-nodeid'),
+                       ring0_addr => get_standard_option('corosync-ring0-addr'),
+                       quorum_votes => { type => 'integer', minimum => 0 },
+                       pve_addr => { type => 'string', format => 'ip' },
+                       pve_fp => get_standard_option('fingerprint-sha256'),
+                   },
+               },
+           },
+           preferred_node => get_standard_option('pve-node'),
+           totem => { type => 'object' },
+           config_digest => { type => 'string' },
+       },
+    },
+    code => sub {
+       my ($param) = @_;
+
+       my $nodename = $param->{node} // PVE::INotify::nodename();
+
+       PVE::Cluster::cfs_update(1);
+       my $conf = PVE::Cluster::cfs_read_file('corosync.conf');
+
+       die "node is not in a cluster, no join info available!\n"
+           if !($conf && $conf->{main});
+
+       my $totem_cfg = $conf->{main}->{totem} // {};
+       my $nodelist = $conf->{main}->{nodelist}->{node} // {};
+       my $corosync_config_digest = $conf->{digest};
+
+       die "unknown node '$nodename'\n" if ! $nodelist->{$nodename};
+
+       foreach my $name (keys %$nodelist) {
+           my $node = $nodelist->{$name};
+           $node->{pve_fp} = PVE::Cluster::get_node_fingerprint($name);
+           $node->{pve_addr} = scalar(PVE::Cluster::remote_node_ip($name));
+       }
+
+       my $res = {
+           nodelist => [ values %$nodelist ],
+           preferred_node => $nodename,
+           totem => $totem_cfg,
+           config_digest => $corosync_config_digest,
+       };
+
+       return $res;
+    }});
+
 __PACKAGE__->register_method ({
     name => 'join',
     path => 'join',