diff options
author | Stig Thormodsrud <stig@vyatta.com> | 2010-12-10 17:22:29 -0800 |
---|---|---|
committer | Stig Thormodsrud <stig@vyatta.com> | 2010-12-10 17:22:29 -0800 |
commit | 4312358a0d527198010584ccdbe1a2e7c8a3a5c0 (patch) | |
tree | 007f937386d437e2e1eb209f6dec0a482701fcd6 | |
parent | 8a48d56ed76c17ce5276657ab6a3a0149cbd6819 (diff) | |
download | vyatta-cfg-4312358a0d527198010584ccdbe1a2e7c8a3a5c0.tar.gz vyatta-cfg-4312358a0d527198010584ccdbe1a2e7c8a3a5c0.zip |
Export vrrp_get_primary().
-rwxr-xr-x | lib/Vyatta/Keepalived.pm | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/lib/Vyatta/Keepalived.pm b/lib/Vyatta/Keepalived.pm index 15f2db2..7ded8a5 100755 --- a/lib/Vyatta/Keepalived.pm +++ b/lib/Vyatta/Keepalived.pm @@ -29,7 +29,8 @@ our @EXPORT = qw(get_conf_file get_state_script get_state_file vrrp_log vrrp_get_init_state get_changes_file start_daemon restart_daemon stop_daemon vrrp_get_config list_vrrp_intf list_vrrp_group - list_vrrp_sync_group list_all_vrrp_sync_grps); + list_vrrp_sync_group list_all_vrrp_sync_grps + vrrp_get_primary_addr); use base qw(Exporter); use Vyatta::Config; @@ -186,15 +187,11 @@ sub get_state_files { return @state_files; } -# -# this is meant to be called from op mode, so Orig functions are used. -# -sub vrrp_get_config { - my ($intf, $group) = @_; +sub vrrp_get_primary_addr { + my ($intf) = @_; my $path; my $config = new Vyatta::Config; - my $interface = new Vyatta::Interface($intf); die "Unknown interface type: $intf" unless $interface; @@ -202,15 +199,38 @@ sub vrrp_get_config { $config->setLevel($path); # don't use getIP() to get IP addresses because we only # want configured addresses, not vrrp VIP addresses. - my @addr = $config->returnOrigValues('address'); - my $primary_addr = shift @addr; - if (!defined $primary_addr or $primary_addr eq 'dhcp') { - $primary_addr = "0.0.0.0"; + my @addrs = (); + if ($config->inSession) { + @addrs = $config->returnValues('address'); + } else { + @addrs = $config->returnOrigValues('address'); } - if ($primary_addr =~ m/(\d+\.\d+\.\d+\.\d+)\/\d+/) { + my $primary_addr = shift @addrs; + + if (defined $primary_addr and + $primary_addr =~ m/(\d+\.\d+\.\d+\.\d+)\/\d+/) { $primary_addr = $1; # strip /mask } + return $primary_addr; +} +# +# this is meant to be called from op mode, so Orig functions are used. +# +sub vrrp_get_config { + my ($intf, $group) = @_; + + my $path; + my $config = new Vyatta::Config; + my $interface = new Vyatta::Interface($intf); + die "Unknown interface type: $intf" unless $interface; + + my $primary_addr = vrrp_get_primary_addr($intf); + if (!defined $primary_addr or $primary_addr eq 'dhcp') { + $primary_addr = "0.0.0.0"; + } + + $path = $interface->path(); $config->setLevel("$path vrrp vrrp-group $group"); my $source_addr = $config->returnOrigValue("hello-source-address"); $primary_addr = $source_addr if defined $source_addr; |