summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rwxr-xr-xlib/Vyatta/Keepalived.pm (renamed from scripts/keepalived/VyattaKeepalived.pm)14
-rwxr-xr-xscripts/keepalived/vyatta-keepalived.pl42
3 files changed, 32 insertions, 28 deletions
diff --git a/Makefile.am b/Makefile.am
index 0d574833..e487007f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
cfgdir = $(datadir)/vyatta-cfg/templates
-share_perl5dir = $(datarootdir)/perl5
+share_perl5dir = $(datarootdir)/perl5/Vyatta
libudevdir = /lib/udev
etcudevdir = /etc/udev
bin_sudo_usersdir = $(bindir)/sudo-users
@@ -43,7 +43,7 @@ sbin_SCRIPTS += scripts/vyatta-raid-event
noinst_DATA = test_bootfile
-share_perl5_DATA = scripts/keepalived/VyattaKeepalived.pm
+share_perl5_DATA = lib/Vyatta/Keepalived.pm
bin_sudo_users_SCRIPTS = scripts/keepalived/vyatta-clear-vrrp.pl
bin_sudo_users_SCRIPTS += scripts/keepalived/vyatta-show-vrrp.pl
diff --git a/scripts/keepalived/VyattaKeepalived.pm b/lib/Vyatta/Keepalived.pm
index 6507d8f7..1dbf2a93 100755
--- a/scripts/keepalived/VyattaKeepalived.pm
+++ b/lib/Vyatta/Keepalived.pm
@@ -21,7 +21,11 @@
#
# **** End License ****
#
-package VyattaKeepalived;
+package Vyatta::Keepalived;
+our @EXPORT = qw(get_conf_file get_state_script get_state_file
+ vrrp_log vrrp_get_init_state
+ start_daemon restart_daemon stop_daemon);
+use base qw(Exporter);
use VyattaConfig;
use POSIX;
@@ -81,7 +85,7 @@ sub stop_daemon {
sub restart_daemon {
my ($conf) = @_;
- if (VyattaKeepalived::is_running()) {
+ if (is_running()) {
my $pid = `cat $keepalived_pid`;
$pid =~ s/\s+$//; # chomp doesn't remove nl
system("kill -1 $pid");
@@ -232,12 +236,12 @@ sub vrrp_get_init_state {
my ($intf, $group, $vips, $preempt) = @_;
my $init_state;
- if (VyattaKeepalived::is_running()) {
- my @state_files = VyattaKeepalived::get_state_files($intf, $group);
+ if (is_running()) {
+ my @state_files = get_state_files($intf, $group);
chomp @state_files;
if (scalar(@state_files) > 0) {
my ($start_time, $f_intf, $f_group, $state, $ltime) =
- VyattaKeepalived::vrrp_state_parse($state_files[0]);
+ vrrp_state_parse($state_files[0]);
if ($state eq "master") {
$init_state = 'MASTER';
} else {
diff --git a/scripts/keepalived/vyatta-keepalived.pl b/scripts/keepalived/vyatta-keepalived.pl
index c41fa7e2..a59f6832 100755
--- a/scripts/keepalived/vyatta-keepalived.pl
+++ b/scripts/keepalived/vyatta-keepalived.pl
@@ -25,14 +25,14 @@
use lib "/opt/vyatta/share/perl5/";
use VyattaConfig;
-use VyattaKeepalived;
+use Vyatta::Keepalived;
use Getopt::Long;
use strict;
use warnings;
my $changes_file = '/var/log/vrrpd/changes';
-my $conf_file = VyattaKeepalived::get_conf_file();
+my $conf_file = get_conf_file();
my %HoA_sync_groups;
@@ -43,7 +43,7 @@ sub keepalived_get_values {
my $output = '';
my $config = new VyattaConfig;
- my $state_transition_script = VyattaKeepalived::get_state_script();
+ my $state_transition_script = get_state_script();
$config->setLevel("$path vrrp vrrp-group");
my @groups = $config->listNodes();
@@ -51,8 +51,8 @@ sub keepalived_get_values {
my $vrrp_instance = "vyatta-$intf-$group";
$config->setLevel("$path vrrp vrrp-group $group");
if ($config->exists("disable")) {
- VyattaKeepalived::vrrp_log("$vrrp_instance disabled - skipping");
- my $state_file = VyattaKeepalived::get_state_file($intf, $group);
+ vrrp_log("$vrrp_instance disabled - skipping");
+ my $state_file = get_state_file($intf, $group);
system("rm -f $state_file");
next;
}
@@ -116,7 +116,7 @@ sub keepalived_get_values {
$output .= "vrrp_instance $vrrp_instance \{\n";
my $init_state;
- $init_state = VyattaKeepalived::vrrp_get_init_state($intf, $group,
+ $init_state = vrrp_get_init_state($intf, $group,
$vips[0], $preempt);
$output .= "\tstate $init_state\n";
$output .= "\tinterface $intf\n";
@@ -179,7 +179,7 @@ sub vrrp_save_changes {
my @list = @_;
my $num_changes = scalar(@list);
- VyattaKeepalived::vrrp_log("saving changes file $num_changes");
+ vrrp_log("saving changes file $num_changes");
open(my $FILE, ">", $changes_file) or die "Error: write $!";
print $FILE join("\n", @list), "\n";
close($FILE);
@@ -201,7 +201,7 @@ sub vrrp_find_changes {
my ($vrrp, $vrrp_status) = each(%vrrp_status_hash);
if ($vrrp_status ne "static") {
push @list, $eth;
- VyattaKeepalived::vrrp_log("$vrrp_status found $eth");
+ vrrp_log("$vrrp_status found $eth");
}
}
if ($config->exists("vif")) {
@@ -217,7 +217,7 @@ sub vrrp_find_changes {
my ($vrrp, $vrrp_status) = each(%vrrp_status_hash);
if ($vrrp_status ne "static") {
push @list, "$eth.$vif";
- VyattaKeepalived::vrrp_log("$vrrp_status found $eth.$vif");
+ vrrp_log("$vrrp_status found $eth.$vif");
}
}
}
@@ -234,7 +234,7 @@ sub vrrp_find_changes {
$config->setLevel($path);
if ($config->isDeleted("vrrp")) {
push @list, $eth;
- VyattaKeepalived::vrrp_log("Delete found $eth");
+ vrrp_log("Delete found $eth");
}
$config->setLevel("$path vif");
my @vifs = $config->listOrigNodes();
@@ -244,13 +244,13 @@ sub vrrp_find_changes {
$config->setLevel($vif_path);
if ($config->isDeleted("vrrp")) {
push @list, "$eth.$vif";
- VyattaKeepalived::vrrp_log("Delete found $eth.$vif");
+ vrrp_log("Delete found $eth.$vif");
}
}
}
my $num = scalar(@list);
- VyattaKeepalived::vrrp_log("Start transation: $num changes");
+ vrrp_log("Start transation: $num changes");
if ($num) {
vrrp_save_changes(@list);
}
@@ -271,7 +271,7 @@ sub remove_from_changes {
my @new_lines = ();
foreach my $line (@lines) {
if ($line =~ /$intf$/) {
- VyattaKeepalived::vrrp_log("remove_from_changes [$line]");
+ vrrp_log("remove_from_changes [$line]");
} else {
push @new_lines, $line;
}
@@ -316,7 +316,7 @@ sub vrrp_update_config {
#
my $vif_intf = $eth . "." . $vif;
if (!(-d "/sys/class/net/$vif_intf")) {
- VyattaKeepalived::vrrp_log("skipping $vif_intf");
+ vrrp_log("skipping $vif_intf");
next;
}
my $vif_path = "$path $vif";
@@ -363,24 +363,24 @@ if (! defined $action) {
}
if ($action eq "update") {
- VyattaKeepalived::vrrp_log("vrrp update $vrrp_intf");
+ vrrp_log("vrrp update $vrrp_intf");
if ( ! -e $changes_file) {
my $num_changes = vrrp_find_changes();
if ($num_changes == 0) {
#
# Shouldn't happen, but ...
#
- VyattaKeepalived::vrrp_log("unexpected 0 changes");
+ vrrp_log("unexpected 0 changes");
}
}
my $vrrp_instances = vrrp_update_config($vrrp_intf);
my $more_changes = remove_from_changes($vrrp_intf);
- VyattaKeepalived::vrrp_log(" instances $vrrp_instances, $more_changes");
+ vrrp_log(" instances $vrrp_instances, $more_changes");
if ($vrrp_instances > 0 and $more_changes == 0) {
- VyattaKeepalived::restart_daemon($conf_file);
+ restart_daemon($conf_file);
}
if ($vrrp_instances == 0) {
- VyattaKeepalived::stop_daemon();
+ stop_daemon();
system("rm -f $conf_file");
}
}
@@ -390,8 +390,8 @@ if ($action eq "delete") {
print "must include interface & group";
exit 1;
}
- VyattaKeepalived::vrrp_log("vrrp delete $vrrp_intf $vrrp_group");
- my $state_file = VyattaKeepalived::get_state_file($vrrp_intf, $vrrp_group);
+ vrrp_log("vrrp delete $vrrp_intf $vrrp_group");
+ my $state_file = get_state_file($vrrp_intf, $vrrp_group);
system("rm -f $state_file");
exit 0;
}