Adapt some functions to prefer 'name' subkey over 'ring0_addr'.
Add a function to get a hash representatiion of the totem corosync
config item.

Signed-off-by: Thomas Lamprecht <t.lampre...@proxmox.com>
---
 data/PVE/CLI/pvecm.pm | 51 +++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 45 insertions(+), 6 deletions(-)

diff --git a/data/PVE/CLI/pvecm.pm b/data/PVE/CLI/pvecm.pm
index c9ebffc..ae39af5 100755
--- a/data/PVE/CLI/pvecm.pm
+++ b/data/PVE/CLI/pvecm.pm
@@ -554,7 +554,7 @@ sub corosync_update_nodelist {
 
     my $children = [];
     foreach my $v (values %$nodelist) {
-       next if !$v->{ring0_addr};
+       next if !($v->{ring0_addr} || $v->{name});
        my $kv = [];
        foreach my $k (keys %$v) {
            push @$kv, { key => $k, value => $v->{$k} };
@@ -580,22 +580,27 @@ sub corosync_update_nodelist {
 
 sub corosync_nodelist {
     my ($conf) = @_;
-    
-    my $res = {};
 
     my $nodelist = {};
-    
+
     foreach my $main (@{$conf->{children}}) {
        next if !defined($main->{section});
        if ($main->{section} eq 'nodelist') {
            foreach my $ne (@{$main->{children}}) {
                next if !defined($ne->{section}) || ($ne->{section} ne 'node');
                my $node = { quorum_votes => 1 };
+               my $name;
                foreach my $child (@{$ne->{children}}) {
                    next if !defined($child->{key});
                    $node->{$child->{key}} = $child->{value};
-                   if ($child->{key} eq 'ring0_addr') {
-                       $nodelist->{$child->{value}} = $node;
+                   # use 'name' over 'ring0_addr' if set
+                   if ($child->{key} eq 'name') {
+                       delete $nodelist->{$name} if $name;
+                       $name = $child->{value};
+                       $nodelist->{$name} = $node;
+                   } elsif(!$name && $child->{key} eq 'ring0_addr') {
+                       $name = $child->{value};
+                       $nodelist->{$name} = $node;
                    }
                }
            }
@@ -605,6 +610,40 @@ sub corosync_nodelist {
     return $nodelist;
 }
 
+# get a hash representation of the corosync config totem section
+sub corosync_totem_config {
+    my ($conf) = @_;
+
+    my $res = {};
+
+    foreach my $main (@{$conf->{children}}) {
+       next if !defined($main->{section}) ||
+           $main->{section} ne 'totem';
+
+       foreach my $e (@{$main->{children}}) {
+
+           if ($e->{section} && $e->{section} eq 'interface') {
+               my $entry = {};
+
+               $res->{interface} = {};
+
+               foreach my $child (@{$e->{children}}) {
+                   next if !defined($child->{key});
+                   $entry->{$child->{key}} = $child->{value};
+                   if($child->{key} eq 'ringnumber') {
+                       $res->{interface}->{$child->{value}} = $entry;
+                   }
+               }
+
+           } elsif  ($e->{key}) {
+               $res->{$e->{key}} = $e->{value};
+           }
+       }
+    }
+
+    return $res;
+}
+
 __PACKAGE__->register_method ({
     name => 'updatecerts', 
     path => 'updatecerts',
-- 
2.1.4


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

Reply via email to