[pve-devel] [PATCH cluster v5] api/cluster: add endpoint to GET cluster join information

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Jan 18 13:41:18 CET 2018


On Thu, Jan 18, 2018 at 01:29:33PM +0100, Thomas Lamprecht wrote:
> Returns all relevant information for joining this cluster over the
> current connected node securely over the API: wrapped in the corosync
> nodelist are address and fingerprint of the node, further totem
> config section and (not directly needed but possibly useful) cluster
> configuration digest are passed.
> 
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
> 
> changes v4 -> v5:
> * return the information of all known cluster nodes
> * thus use array as return type, this allows to still verify the
>   returned data
> * pass the preferred node, if explicitly pass
> * add checks, i.e., is a cluster configured and is the passed node a
>   known member
> 
>  data/PVE/API2/ClusterConfig.pm | 69 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 69 insertions(+)
> 
> diff --git a/data/PVE/API2/ClusterConfig.pm b/data/PVE/API2/ClusterConfig.pm
> index 8c88a17..9c1a038 100644
> --- a/data/PVE/API2/ClusterConfig.pm
> +++ b/data/PVE/API2/ClusterConfig.pm
> @@ -396,6 +396,74 @@ __PACKAGE__->register_method ({
>      }});
>  
>  __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 => {
> +			pve_addr => { type => 'string', format => 'ip' },
> +			pve_fp => get_standard_option('fingerprint-sha256'),
> +		    },

are there other properties we could add here with a schema as well?
seems like all/most of them are already defined in some way for
create/... anyway?

> +		},
> +	    },
> +	    prefered_node => get_standard_option('pve-node'),

s/prefered/preferred/

> +	    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',
>      method => 'POST',
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel




More information about the pve-devel mailing list