[pve-devel] [PATCH cluster v2 6/7] WIP: add foreach_member
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Sep 14 10:00:40 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>
---
NOTE: WIP, and only for the next patchs qdevice prototype
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