[pve-devel] [RFC cluster v2 09/10] move cluster create to API
Fabian Grünbichler
f.gruenbichler at proxmox.com
Wed Dec 6 16:13:59 CET 2017
same high-level questions:
- worker?
- file paths?
On Mon, Dec 04, 2017 at 12:11:16PM +0100, Thomas Lamprecht wrote:
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
> data/PVE/API2/ClusterConfig.pm | 94 ++++++++++++++++++++++++++++++++++++++++--
> data/PVE/CLI/pvecm.pm | 89 +--------------------------------------
> 2 files changed, 92 insertions(+), 91 deletions(-)
>
> diff --git a/data/PVE/API2/ClusterConfig.pm b/data/PVE/API2/ClusterConfig.pm
> index 97706d9..9bbefaf 100644
> --- a/data/PVE/API2/ClusterConfig.pm
> +++ b/data/PVE/API2/ClusterConfig.pm
> @@ -14,6 +14,9 @@ use PVE::Corosync;
>
> use base qw(PVE::RESTHandler);
>
> +my $clusterconf = "/etc/pve/corosync.conf";
> +my $authfile = "/etc/corosync/authkey";
> +
> __PACKAGE__->register_method({
> name => 'index',
> path => '',
> @@ -46,6 +49,94 @@ __PACKAGE__->register_method({
> return $result;
> }});
>
> +__PACKAGE__->register_method ({
> + name => 'create',
> + path => 'create',
> + method => 'POST',
> + description => "Generate new cluster configuration.",
> + parameters => {
> + additionalProperties => 0,
> + properties => {
> + clustername => {
> + description => "The name of the cluster.",
> + type => 'string', format => 'pve-node',
> + maxLength => 15,
> + },
> + nodeid => {
> + type => 'integer',
> + description => "Node id for this node.",
> + minimum => 1,
> + optional => 1,
> + },
> + votes => {
> + type => 'integer',
> + description => "Number of votes for this node.",
> + minimum => 1,
> + optional => 1,
> + },
> + bindnet0_addr => {
> + type => 'string', format => 'ip',
> + description => "This specifies the network address the corosync ring 0".
> + " executive should bind to and defaults to the local IP address of the node.",
> + optional => 1,
> + },
> + ring0_addr => {
> + type => 'string', format => 'address',
> + description => "Hostname (or IP) of the corosync ring0 address of this node.".
> + " Defaults to the hostname of the node.",
> + optional => 1,
> + },
> + bindnet1_addr => {
> + type => 'string', format => 'ip',
> + description => "This specifies the network address the corosync ring 1".
> + " executive should bind to and is optional.",
> + optional => 1,
> + },
> + ring1_addr => {
> + type => 'string', format => 'address',
> + description => "Hostname (or IP) of the corosync ring1 address, this".
> + " needs an valid bindnet1_addr.",
> + optional => 1,
> + },
> + },
> + },
> + returns => { type => 'null' },
> +
> + code => sub {
> + my ($param) = @_;
> +
> + -f $clusterconf && die "cluster config '$clusterconf' already exists\n";
> +
> + PVE::Cluster::setup_sshd_config(1);
> + PVE::Cluster::setup_rootsshconfig();
> + PVE::Cluster::setup_ssh_keys();
> +
> + PVE::Tools::run_command(['/usr/sbin/corosync-keygen', '-lk', $authfile])
> + if !-f $authfile;
> + die "no authentication key available\n" if -f !$authfile;
> +
> + my $nodename = PVE::INotify::nodename();
> +
> + # get the corosync basis config for the new cluster
> + my $config = PVE::Corosync::create_conf($nodename, %$param);
> +
> + print "Writing corosync config to /etc/corosync/corosync.conf\n";
> + PVE::Corosync::atomic_write_conf($config);
> +
> + my $local_ip_address = PVE::Cluster::remote_node_ip($nodename);
> +
> + PVE::Cluster::ssh_merge_keys();
> +
> + PVE::Cluster::gen_pve_node_files($nodename, $local_ip_address);
> +
> + PVE::Cluster::ssh_merge_known_hosts($nodename, $local_ip_address, 1);
> +
> + print "Restart corosync and cluster filesystem\n";
> + PVE::Tools::run_command('systemctl restart corosync pve-cluster');
> +
> + return undef;
> +}});
> +
> __PACKAGE__->register_method({
> name => 'nodes',
> path => 'nodes',
> @@ -376,9 +467,6 @@ __PACKAGE__->register_method ({
> $config_change_lock->($code);
> die $@ if $@;
>
> - my $clusterconf = "/etc/pve/corosync.conf";
> - my $authfile = "/etc/corosync/authkey";
> -
> my $res = {
> corosync_authkey => PVE::Tools::file_get_contents($authfile),
> corosync_conf => PVE::Tools::file_get_contents($clusterconf),
> diff --git a/data/PVE/CLI/pvecm.pm b/data/PVE/CLI/pvecm.pm
> index 4b4eaa5..14c47df 100755
> --- a/data/PVE/CLI/pvecm.pm
> +++ b/data/PVE/CLI/pvecm.pm
> @@ -66,93 +66,6 @@ __PACKAGE__->register_method ({
> }});
>
> __PACKAGE__->register_method ({
> - name => 'create',
> - path => 'create',
> - method => 'PUT',
> - description => "Generate new cluster configuration.",
> - parameters => {
> - additionalProperties => 0,
> - properties => {
> - clustername => {
> - description => "The name of the cluster.",
> - type => 'string', format => 'pve-node',
> - maxLength => 15,
> - },
> - nodeid => {
> - type => 'integer',
> - description => "Node id for this node.",
> - minimum => 1,
> - optional => 1,
> - },
> - votes => {
> - type => 'integer',
> - description => "Number of votes for this node.",
> - minimum => 1,
> - optional => 1,
> - },
> - bindnet0_addr => {
> - type => 'string', format => 'ip',
> - description => "This specifies the network address the corosync ring 0".
> - " executive should bind to and defaults to the local IP address of the node.",
> - optional => 1,
> - },
> - ring0_addr => {
> - type => 'string', format => 'address',
> - description => "Hostname (or IP) of the corosync ring0 address of this node.".
> - " Defaults to the hostname of the node.",
> - optional => 1,
> - },
> - bindnet1_addr => {
> - type => 'string', format => 'ip',
> - description => "This specifies the network address the corosync ring 1".
> - " executive should bind to and is optional.",
> - optional => 1,
> - },
> - ring1_addr => {
> - type => 'string', format => 'address',
> - description => "Hostname (or IP) of the corosync ring1 address, this".
> - " needs an valid bindnet1_addr.",
> - optional => 1,
> - },
> - },
> - },
> - returns => { type => 'null' },
> -
> - code => sub {
> - my ($param) = @_;
> -
> - -f $clusterconf && die "cluster config '$clusterconf' already exists\n";
> -
> - PVE::Cluster::setup_sshd_config(1);
> - PVE::Cluster::setup_rootsshconfig();
> - PVE::Cluster::setup_ssh_keys();
> -
> - -f $authfile || __PACKAGE__->keygen({filename => $authfile});
> - -f $authfile || die "no authentication key available\n";
> -
> - my $nodename = PVE::INotify::nodename();
> -
> - # get the corosync basis config for the new cluster
> - my $config = PVE::Corosync::create_conf($nodename, %$param);
> -
> - print "Writing corosync config to /etc/corosync/corosync.conf\n";
> - PVE::Corosync::atomic_write_conf($config);
> -
> - my $local_ip_address = PVE::Cluster::remote_node_ip($nodename);
> -
> - PVE::Cluster::ssh_merge_keys();
> -
> - PVE::Cluster::gen_pve_node_files($nodename, $local_ip_address);
> -
> - PVE::Cluster::ssh_merge_known_hosts($nodename, $local_ip_address, 1);
> -
> - print "Restart corosync and cluster filesystem\n";
> - run_command('systemctl restart corosync pve-cluster'); # restart
> -
> - return undef;
> -}});
> -
> -__PACKAGE__->register_method ({
> name => 'add',
> path => 'add',
> method => 'PUT',
> @@ -499,7 +412,7 @@ __PACKAGE__->register_method ({
>
> our $cmddef = {
> keygen => [ __PACKAGE__, 'keygen', ['filename']],
> - create => [ __PACKAGE__, 'create', ['clustername']],
> + create => [ 'PVE::API2::ClusterConfig', 'create', ['clustername']],
> add => [ __PACKAGE__, 'add', ['hostname']],
> addnode => [ 'PVE::API2::ClusterConfig', 'addnode', ['node']],
> delnode => [ 'PVE::API2::ClusterConfig', 'delnode', ['node']],
> --
> 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