summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMichael Larson <slioch@eng-140.vyatta.com>2008-01-30 11:47:28 -0800
committerMichael Larson <slioch@eng-140.vyatta.com>2008-01-30 11:47:28 -0800
commit62b85bda5f9eb966c12f2a5351d18ab9d2a6baa6 (patch)
treee853fb5d0c0416600bd102599ba0dff83653e401 /scripts
parent2e39e64f3806fc8abb44a39843e1a2df4aec6f15 (diff)
downloadvyatta-wanloadbalance-62b85bda5f9eb966c12f2a5351d18ab9d2a6baa6.tar.gz
vyatta-wanloadbalance-62b85bda5f9eb966c12f2a5351d18ab9d2a6baa6.zip
checkin of cli commands for wan loadbalancing. some cleanup of the project--more cli work to follow...
Diffstat (limited to 'scripts')
-rw-r--r--scripts/vyatta-wanloadbalance.pl180
1 files changed, 180 insertions, 0 deletions
diff --git a/scripts/vyatta-wanloadbalance.pl b/scripts/vyatta-wanloadbalance.pl
new file mode 100644
index 0000000..c65c1f0
--- /dev/null
+++ b/scripts/vyatta-wanloadbalance.pl
@@ -0,0 +1,180 @@
+#!/usr/bin/perl -w
+#
+# Module: vyatta-wanloadbalance.pl
+#
+# **** License ****
+# Version: VPL 1.0
+#
+# The contents of this file are subject to the Vyatta Public License
+# Version 1.0 ("License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.vyatta.com/vpl
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+# the License for the specific language governing rights and limitations
+# under the License.
+#
+# This code was originally developed by Vyatta, Inc.
+# Portions created by Vyatta are Copyright (C) 2008 Vyatta, Inc.
+# All Rights Reserved.
+#
+# Author: Michael Larson
+# Date: January 2008
+# Description: Writes exclusion list for linkstatus
+#
+# **** End License ****
+#
+use lib "/opt/vyatta/share/perl5/";
+use VyattaConfig;
+use VyattaMisc;
+
+use warnings;
+use strict;
+use POSIX;
+use File::Copy;
+
+sub write_health {
+#open conf
+ my $config = new VyattaConfig;
+
+ $config->setLevel("load-balancing wan interface-health");
+ my @eths = $config->listNodes();
+
+ print FILE_LCK "health {\n";
+
+ foreach my $ethNode (@eths) {
+
+ print FILE_LCK "\tinterface " . $ethNode . " {\n";
+
+ my $option = $config->returnValue("$ethNode failure-count");
+ if (defined $option) {
+ print FILE_LCK "\t\tfailure-ct " . $option . "\n";
+ }
+
+ $option = $config->returnValue("$ethNode ping");
+ if (defined $option) {
+ print FILE_LCK "\t\ttarget " . $option . "\n";
+ }
+
+ $option = $config->returnValue("$ethNode resp-time");
+ if (defined $option) {
+ print FILE_LCK "\t\tping-resp " . $option . "\n";
+ }
+
+ $option = $config->returnValue("$ethNode success-count");
+ if (defined $option) {
+ print FILE_LCK "\t\tsuccess-ct " . $option . "\n";
+ }
+ print FILE_LCK "\t}\n";
+ }
+ print FILE_LCK "}\n\n";
+}
+
+sub write_rules {
+ my $config = new VyattaConfig;
+
+ $config->setLevel("load-balancing wan rule");
+ my @rules = $config->listNodes();
+
+ #destination
+ foreach my $rule (@rules) {
+ print FILE_LCK "rule " . $rule . " {\n";
+
+ my $option = $config->returnValue("$rule protocol");
+ if (defined $option) {
+ print FILE_LCK "\tprotocol " . $option . "\n"
+ }
+
+ #destination
+ print FILE_LCK "\tdestination {\n";
+ $option = $config->returnValue("$rule destination address");
+ if (defined $option) {
+ print FILE_LCK "\t\taddress " . $option . "\n";
+ }
+
+ $option = $config->returnValue("$rule destination network");
+ if (defined $option) {
+ print FILE_LCK "\t\tnetwork " . $option . "\n";
+ }
+
+ $config->setLevel("load-balancing wan rule $rule destination port-number");
+ my @dport_nums = $config->listNodes();
+ foreach my $dport_num (@dport_nums) {
+ print FILE_LCK "\t\tport-number " . $dport_num . "\n";
+ }
+
+ $config->setLevel("load-balancing wan rule $rule destination port-name");
+ my @dport_names = $config->listNodes();
+ foreach my $dport_name (@dport_names) {
+ print FILE_LCK "\t\tport-number " . $dport_name . "\n";
+ }
+ print FILE_LCK "\t}\n";
+
+ #source
+ print FILE_LCK "\tsource {\n";
+ $option = $config->returnValue("$rule source address");
+ if (defined $option) {
+ print FILE_LCK "\t\taddress " . $option . "\n";
+ }
+
+ $option = $config->returnValue("$rule source network");
+ if (defined $option) {
+ print FILE_LCK "\t\tnetwork " . $option . "\n";
+ }
+
+ $config->setLevel("load-balancing wan rule $rule source port-number");
+ my @sport_nums = $config->listNodes();
+ foreach my $sport_num (@sport_nums) {
+ print FILE_LCK "\t\tport-number " . $sport_num . "\n";
+ }
+
+ $config->setLevel("load-balancing wan rule $rule source port-name");
+ my @sport_names = $config->listNodes();
+ foreach my $sport_name (@sport_names) {
+ print FILE_LCK "\t\tport-number " . $sport_name . "\n";
+ }
+ print FILE_LCK "\t}\n";
+
+ #interface
+ $config->setLevel("load-balancing wan rule $rule interface");
+ my @eths = $config->listNodes();
+
+ foreach my $ethNode (@eths) {
+ print FILE_LCK "\tinterface " . $ethNode . " {\n";
+
+ $option = $config->returnValue("$ethNode weight");
+ if (defined $option) {
+ print FILE_LCK "\t\tweight " . $option . "\n";
+ }
+ print FILE_LCK "\t}\n";
+ }
+ print FILE_LCK "}\n";
+ }
+}
+
+
+
+####main
+my $conf_file = '/var/load-balance/wlb.conf';
+my $conf_lck_file = '/var/load-balance/wlb.conf.lck';
+
+#open file
+open FILE, "<$conf_file";
+open FILE_LCK, "+>$conf_lck_file";
+
+write_health();
+
+write_rules();
+
+close FILE;
+close FILE_LCK;
+
+copy ($conf_lck_file,$conf_file);
+unlink($conf_lck_file);
+
+
+#finally kick the process
+#system "/etc/init.d/vyatta-wanloadbalance restart";
+
+exit 0;