[pve-devel] [PATCH cluster 6/7] WIP: add foreach_member
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Aug 3 10:03:10 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>
---
Not sure if I go with this, this is just sended along for people who want to
try qdevice helpers in the next patch.
data/PVE/Cluster.pm | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 38c5fdb..c87ced4 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -1646,4 +1646,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