[pve-devel] [PATCH v2 cluster] Add warning for pvecm commands if not part of cluster

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Mar 11 13:31:15 CET 2016


If the cluster config file is missing, pvecm status, nodes
and expected will probably not work. Add a helpful warning
because the corosync-quorumtool error message is not very
descriptive here.

Add a helper sub in Cluster.pm to actually do the check.
---
Changes compared to v1:
- move into helper sub in Cluster.pm
 data/PVE/CLI/pvecm.pm |  6 ++++++
 data/PVE/Cluster.pm   | 11 +++++++++++
 2 files changed, 17 insertions(+)

diff --git a/data/PVE/CLI/pvecm.pm b/data/PVE/CLI/pvecm.pm
index 7fadb7d..ad127e9 100755
--- a/data/PVE/CLI/pvecm.pm
+++ b/data/PVE/CLI/pvecm.pm
@@ -601,6 +601,8 @@ __PACKAGE__->register_method ({
     code => sub {
 	my ($param) = @_;
 
+	PVE::Cluster::check_corosync_conf_exists("is this node part of a cluster?");
+
 	my $cmd = ['corosync-quorumtool', '-siH'];
 
 	exec (@$cmd);
@@ -622,6 +624,8 @@ __PACKAGE__->register_method ({
     code => sub {
 	my ($param) = @_;
 
+	PVE::Cluster::check_corosync_conf_exists("is this node part of a cluster?");
+
 	my $cmd = ['corosync-quorumtool', '-l'];
 
 	exec (@$cmd);
@@ -649,6 +653,8 @@ __PACKAGE__->register_method ({
     code => sub {
 	my ($param) = @_;
 
+	PVE::Cluster::check_corosync_conf_exists("is this node part of a cluster?");
+
 	my $cmd = ['corosync-quorumtool', '-e', $param->{expected}];
 
 	exec (@$cmd);
diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index b241662..8fc8a97 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -1499,6 +1499,17 @@ PVE::Cluster::cfs_register_file('corosync.conf', \&parse_corosync_conf);
 PVE::Cluster::cfs_register_file('corosync.conf.new', \&parse_corosync_conf, 
 				\&write_corosync_conf);
 
+sub check_corosync_conf_exists {
+    my ($msg) = @_;
+
+    my $exists = -f "$basedir/corosync.conf";
+
+    warn "Corosync config '$basedir/corosync.conf' does not exist - $msg\n"
+	if defined($msg);
+
+    return $exists;
+}
+
 # bash completion helpers
 
 sub complete_next_vmid {
-- 
2.1.4





More information about the pve-devel mailing list