From 9c605ffae490b6fa6f0c0e310ea88c83eee8be9d Mon Sep 17 00:00:00 2001 From: zsdc Date: Thu, 2 Apr 2020 13:30:29 +0300 Subject: VRRP: T2193: Added disabled VRRP instances to `show vrrp` Disabled VRRP instances will be listed in a `show vrrp` command at the end of the list with the DISABLED status --- src/op_mode/vrrp.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/op_mode/vrrp.py b/src/op_mode/vrrp.py index 8d1369823..8a993f92c 100755 --- a/src/op_mode/vrrp.py +++ b/src/op_mode/vrrp.py @@ -18,12 +18,28 @@ import sys import time import argparse - +import json import tabulate import vyos.keepalived import vyos.util +config_dict_path = '/run/keepalived_config.dict' + + +# get disabled instances from a config +def vrrp_get_disabled(): + # read the dictionary file with configuration + with open(config_dict_path, 'r') as dict_file: + vrrp_config_dict = json.load(dict_file) + vrrp_disabled = [] + # add disabled groups to the list + for vrrp_group in vrrp_config_dict['vrrp_groups']: + if vrrp_group['disable']: + vrrp_disabled.append([vrrp_group['name'], vrrp_group['interface'], vrrp_group['vrid'], 'DISABLED', '']) + # return list with disabled instances + return vrrp_disabled + def print_summary(): try: @@ -54,10 +70,13 @@ def print_summary(): row = [name, interface, vrid, state, ltrans_time] groups.append(row) + # add to the active list disabled instances + groups.extend(vrrp_get_disabled()) headers = ["Name", "Interface", "VRID", "State", "Last Transition"] output = tabulate.tabulate(groups, headers) print(output) + def print_statistics(): try: vyos.keepalived.force_stats_dump() @@ -69,6 +88,7 @@ def print_statistics(): print("VRRP statistics are not available") sys.exit(1) + def print_state_data(): try: vyos.keepalived.force_state_data_dump() @@ -80,6 +100,7 @@ def print_state_data(): print("VRRP information is not available") sys.exit(1) + parser = argparse.ArgumentParser() group = parser.add_mutually_exclusive_group() group.add_argument("-s", "--summary", action="store_true", help="Print VRRP summary") -- cgit v1.2.3