diff options
Diffstat (limited to 'src/op_mode')
-rwxr-xr-x | src/op_mode/dns_forwarding_restart.sh | 2 | ||||
-rwxr-xr-x | src/op_mode/show_configuration_files.sh (renamed from src/op_mode/show-configuration-files.sh) | 0 | ||||
-rwxr-xr-x | src/op_mode/show_disk_format.sh (renamed from src/op_mode/show-disk-format.sh) | 0 | ||||
-rwxr-xr-x | src/op_mode/show_raid.sh (renamed from src/op_mode/show-raid.sh) | 0 | ||||
-rwxr-xr-x | src/op_mode/vrrp.py | 98 |
5 files changed, 99 insertions, 1 deletions
diff --git a/src/op_mode/dns_forwarding_restart.sh b/src/op_mode/dns_forwarding_restart.sh index 12106fcc1..8e556f2f0 100755 --- a/src/op_mode/dns_forwarding_restart.sh +++ b/src/op_mode/dns_forwarding_restart.sh @@ -1,6 +1,6 @@ #!/bin/sh -if cli-shell-api exists service dns forwarding; then +if cli-shell-api existsEffective service dns forwarding; then echo "Restarting the DNS forwarding service" systemctl restart pdns-recursor else diff --git a/src/op_mode/show-configuration-files.sh b/src/op_mode/show_configuration_files.sh index ad8e0747c..ad8e0747c 100755 --- a/src/op_mode/show-configuration-files.sh +++ b/src/op_mode/show_configuration_files.sh diff --git a/src/op_mode/show-disk-format.sh b/src/op_mode/show_disk_format.sh index 61b15a52b..61b15a52b 100755 --- a/src/op_mode/show-disk-format.sh +++ b/src/op_mode/show_disk_format.sh diff --git a/src/op_mode/show-raid.sh b/src/op_mode/show_raid.sh index ba4174692..ba4174692 100755 --- a/src/op_mode/show-raid.sh +++ b/src/op_mode/show_raid.sh diff --git a/src/op_mode/vrrp.py b/src/op_mode/vrrp.py new file mode 100755 index 000000000..ba8b56de3 --- /dev/null +++ b/src/op_mode/vrrp.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2018 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +import sys +import time +import argparse + +import tabulate + +import vyos.keepalived +import vyos.util + + +def print_summary(): + try: + vyos.keepalived.force_json_dump() + # Wait for keepalived to produce the data + # Replace with inotify or similar if it proves problematic + time.sleep(0.2) + json_data = vyos.keepalived.get_json_data() + except: + print("VRRP information is not available") + + groups = [] + for group in json_data: + data = group["data"] + + name = data["iname"] + + ltrans_timestamp = float(data["last_transition"]) + ltrans_time = vyos.util.seconds_to_human(int(time.time() - ltrans_timestamp)) + + interface = data["ifp_ifname"] + vrid = data["vrid"] + + state = vyos.keepalived.decode_state(data["state"]) + + row = [name, interface, vrid, state, ltrans_time] + groups.append(row) + + headers = ["Name", "Interface", "VRID", "State", "Last Transition"] + output = tabulate.tabulate(groups, headers) + print(output) + +def print_statistics(): + try: + vyos.keepalived.force_stats_dump() + time.sleep(0.2) + output = vyos.keepalived.get_statistics() + print(output) + except: + print("VRRP statistics are not available") + +def print_state_data(): + try: + vyos.keepalived.force_state_data_dump() + time.sleep(0.2) + output = vyos.keepalived.get_state_data() + print(output) + except: + print("VRRP information is not available") + +parser = argparse.ArgumentParser() +group = parser.add_mutually_exclusive_group() +group.add_argument("-s", "--summary", action="store_true", help="Print VRRP summary") +group.add_argument("-t", "--statistics", action="store_true", help="Print VRRP statistics") +group.add_argument("-d", "--data", action="store_true", help="Print detailed VRRP data") + +args = parser.parse_args() + +# Exit early if VRRP is dead or not configured +if not vyos.keepalived.vrrp_running(): + print("VRRP is not running") + sys.exit(0) + +if args.summary: + print_summary() +elif args.statistics: + print_statistics() +elif args.data: + print_state_data() +else: + parser.print_help() + sys.exit(1) |