]> git.proxmox.com Git - pve-cluster.git/commitdiff
pvecm add: report all errors found at once
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 22 Feb 2017 15:59:10 +0000 (16:59 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 28 Feb 2017 10:51:21 +0000 (11:51 +0100)
Else only the first error got reported and we had no idea what else
was possible wrong.

I'll also use the $err method more in next commits

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

index e4de650b6d8591a945797e062bcc58ea4e4687eb..df94c2e883d398759cd05bc0ac1ed28e8c9c69f5 100755 (executable)
@@ -504,26 +504,41 @@ __PACKAGE__->register_method ({
 
        my $host = $param->{hostname};
 
+       my ($errors, $warnings) = ('', '');
+
+       my $error = sub {
+           my ($msg, $suppress) = @_;
+
+           if ($suppress) {
+               $warnings .= "* $msg\n";
+           } else {
+               $errors .= "* $msg\n";
+           }
+       };
+
        if (!$param->{force}) {
 
            if (-f $authfile) {
-               die "authentication key already exists\n";
+               &$error("authentication key '$authfile' already exists", $param->{force});
            }
 
            if (-f $clusterconf)  {
-               die "cluster config '$clusterconf' already exists\n";
+               &$error("cluster config '$clusterconf' already exists", $param->{force});
            }
 
            my $vmlist = PVE::Cluster::get_vmlist();
            if ($vmlist && $vmlist->{ids} && scalar(keys %{$vmlist->{ids}})) {
-               die "this host already contains virtual machines - please remove them first\n";
+               &$error("this host already contains virtual guests", $param->{force});
            }
 
            if (system("corosync-quorumtool -l >/dev/null 2>&1") == 0) {
-               die "corosync is already running\n";
+               &$error("corosync is already running, is this node already in a cluster?!", $param->{force});
            }
        }
 
+       warn "warning, ignore the following errors:\n$warnings" if $warnings;
+       die "detected the following error(s):\n$errors" if $errors;
+
        # make sure known_hosts is on local filesystem
        PVE::Cluster::ssh_unmerge_known_hosts();