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.lampre...@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


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to