[pve-devel] [PATCH cluster v3 6/7] WIP: add foreach_member
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Sep 18 10:32:57 CEST 2017
Add a method to execute a sub for each cluster member, passing its
name and cluster ip to the $code sub.
This is similar to our foreach_disk or foreach_storage
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
data/PVE/Cluster.pm | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 84e3cbf..ba107a8 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -1656,4 +1656,20 @@ sub ssh_info_to_command {
return $cmd;
}
+sub foreach_member {
+ my ($code, $noerr) = @_;
+
+ my $members = get_members();
+ foreach my $node (sort keys %$members) {
+ # FIXME: what about offline members?
+ if (my $ip = $members->{$node}->{ip}) {
+ &$code($node, $ip);
+ } else {
+ die "cannot get the cluster IP for node '$node'.\n" if !$noerr;
+ warn "cannot get the cluster IP for node '$node'.\n" if !$noerr;
+ return undef;
+ }
+ }
+}
+
1;
--
2.11.0
More information about the pve-devel
mailing list