]> git.proxmox.com Git - pve-cluster.git/blobdiff - data/PVE/CLI/pvecm.pm
fix #1723: add missing package for 'remote_node_ip'
[pve-cluster.git] / data / PVE / CLI / pvecm.pm
index 9b988151c770a5f6f26a8bc9fb85f2bac90bd18f..3f0ac128c22888801c947bf494edfd71eb33086c 100755 (executable)
@@ -107,75 +107,85 @@ __PACKAGE__->register_method ({
        my $nodename = PVE::INotify::nodename();
 
        my $host = $param->{hostname};
+       my $local_ip_address = PVE::Cluster::remote_node_ip($nodename);
 
        PVE::Cluster::assert_joinable($param->{ring0_addr}, $param->{ring1_addr}, $param->{force});
 
-       if (!$param->{use_ssh}) {
-           print "Please enter superuser (root) password for '$host':\n";
-           my $password = PVE::PTY::read_password("Password for root\@$host: ");
+       my $worker = sub {
+
+           if (!$param->{use_ssh}) {
+               print "Please enter superuser (root) password for '$host':\n";
+               my $password = PVE::PTY::read_password("Password for root\@$host: ");
 
-           delete $param->{use_ssh};
-           $param->{password} = $password;
+               delete $param->{use_ssh};
+               $param->{password} = $password;
 
-           my $local_cluster_lock = "/var/lock/pvecm.lock";
-           PVE::Tools::lock_file($local_cluster_lock, 10, \&PVE::Cluster::join, $param);
+               my $local_cluster_lock = "/var/lock/pvecm.lock";
+               PVE::Tools::lock_file($local_cluster_lock, 10, \&PVE::Cluster::join, $param);
 
-           if (my $err = $@) {
-               if (ref($err) eq 'PVE::APIClient::Exception' && $err->{code} == 501) {
-                   $err = "Remote side is not able to use API for Cluster join!\n" .
-                          "Pass the 'use_ssh' switch or update the remote side.\n";
+               if (my $err = $@) {
+                   if (ref($err) eq 'PVE::APIClient::Exception' && defined($err->{code}) && $err->{code} == 501) {
+                       $err = "Remote side is not able to use API for Cluster join!\n" .
+                              "Pass the 'use_ssh' switch or update the remote side.\n";
+                   }
+                   die $err;
                }
-               die $err;
+               return; # all OK, the API join endpoint successfully set us up
            }
-           return; # all OK, the API join endpoint successfully set us up
-       }
 
-       # allow fallback to old ssh only join if wished or needed
+           # allow fallback to old ssh only join if wished or needed
 
-       PVE::Cluster::setup_sshd_config();
-       PVE::Cluster::setup_rootsshconfig();
-       PVE::Cluster::setup_ssh_keys();
+           PVE::Cluster::setup_sshd_config();
+           PVE::Cluster::setup_rootsshconfig();
+           PVE::Cluster::setup_ssh_keys();
 
-       # make sure known_hosts is on local filesystem
-       PVE::Cluster::ssh_unmerge_known_hosts();
+           # make sure known_hosts is on local filesystem
+           PVE::Cluster::ssh_unmerge_known_hosts();
 
-       my $cmd = ['ssh-copy-id', '-i', '/root/.ssh/id_rsa', "root\@$host"];
-       run_command($cmd, 'outfunc' => sub {}, 'errfunc' => sub {},
-                               'errmsg' => "unable to copy ssh ID");
+           my $cmd = ['ssh-copy-id', '-i', '/root/.ssh/id_rsa', "root\@$host"];
+           run_command($cmd, 'outfunc' => sub {}, 'errfunc' => sub {},
+                                   'errmsg' => "unable to copy ssh ID");
 
-       $cmd = ['ssh', $host, '-o', 'BatchMode=yes',
-               'pvecm', 'addnode', $nodename, '--force', 1];
+           $cmd = ['ssh', $host, '-o', 'BatchMode=yes',
+                   'pvecm', 'addnode', $nodename, '--force', 1];
 
-       push @$cmd, '--nodeid', $param->{nodeid} if $param->{nodeid};
-       push @$cmd, '--votes', $param->{votes} if defined($param->{votes});
-       push @$cmd, '--ring0_addr', $param->{ring0_addr} if defined($param->{ring0_addr});
-       push @$cmd, '--ring1_addr', $param->{ring1_addr} if defined($param->{ring1_addr});
+           push @$cmd, '--nodeid', $param->{nodeid} if $param->{nodeid};
+           push @$cmd, '--votes', $param->{votes} if defined($param->{votes});
+           push @$cmd, '--ring0_addr', $param->{ring0_addr} // $local_ip_address;
+           push @$cmd, '--ring1_addr', $param->{ring1_addr} if defined($param->{ring1_addr});
 
-       if (system (@$cmd) != 0) {
-           my $cmdtxt = join (' ', @$cmd);
-           die "unable to add node: command failed ($cmdtxt)\n";
-       }
+           if (system (@$cmd) != 0) {
+               my $cmdtxt = join (' ', @$cmd);
+               die "unable to add node: command failed ($cmdtxt)\n";
+           }
 
-       my $tmpdir = "$libdir/.pvecm_add.tmp.$$";
-       mkdir $tmpdir;
+           my $tmpdir = "$libdir/.pvecm_add.tmp.$$";
+           mkdir $tmpdir;
 
-       eval {
-           print "copy corosync auth key\n";
-           $cmd = ['rsync', '--rsh=ssh -l root -o BatchMode=yes', '-lpgoq',
-                   "[$host]:$authfile $clusterconf", $tmpdir];
+           eval {
+               print "copy corosync auth key\n";
+               $cmd = ['rsync', '--rsh=ssh -l root -o BatchMode=yes', '-lpgoq',
+                       "[$host]:$authfile $clusterconf", $tmpdir];
 
-           system(@$cmd) == 0 || die "can't rsync data from host '$host'\n";
+               system(@$cmd) == 0 || die "can't rsync data from host '$host'\n";
 
-           my $corosync_conf = PVE::Tools::file_get_contents("$tmpdir/corosync.conf");
-           my $corosync_authkey = PVE::Tools::file_get_contents("$tmpdir/authkey");
+               my $corosync_conf = PVE::Tools::file_get_contents("$tmpdir/corosync.conf");
+               my $corosync_authkey = PVE::Tools::file_get_contents("$tmpdir/authkey");
 
-           PVE::Cluster::finish_join($host, $corosync_conf, $corosync_authkey);
+               PVE::Cluster::finish_join($host, $corosync_conf, $corosync_authkey);
+           };
+           my $err = $@;
+
+           rmtree $tmpdir;
+
+           die $err if $err;
        };
-       my $err = $@;
 
-       rmtree $tmpdir;
+       # use a synced worker so we get a nice task log when joining through CLI
+       my $rpcenv = PVE::RPCEnvironment::get();
+       my $authuser = $rpcenv->get_user();
 
-       die $err if $err;
+       $rpcenv->fork_worker('clusterjoin', '',  $authuser, $worker);
 
        return undef;
     }});
@@ -280,25 +290,7 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       PVE::Cluster::setup_rootsshconfig();
-
-       PVE::Cluster::gen_pve_vzdump_symlink();
-
-       if (!PVE::Cluster::check_cfs_quorum(1)) {
-           return undef if $param->{silent};
-           die "no quorum - unable to update files\n";
-       }
-
-       PVE::Cluster::setup_ssh_keys();
-
-       my $nodename = PVE::INotify::nodename();
-
-       my $local_ip_address = PVE::Cluster::remote_node_ip($nodename);
-
-       PVE::Cluster::gen_pve_node_files($nodename, $local_ip_address, $param->{force});
-       PVE::Cluster::ssh_merge_keys();
-       PVE::Cluster::ssh_merge_known_hosts($nodename, $local_ip_address);
-       PVE::Cluster::gen_pve_vzdump_files();
+       PVE::Cluster::updatecerts_and_ssh($param->@{qw(force silent)});
 
        return undef;
     }});