diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-04-03 16:02:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 16:02:09 +0200 |
commit | 5f850ee4f60e08b7e1f62100f406ce1dcbfedd0e (patch) | |
tree | 2f641a742f659d8011013975d17b7cbeef1a0b94 /src/op_mode/vrrp.py | |
parent | e8d26b914a273911bc283c1ac14d934a4b29a0ba (diff) | |
parent | 9c605ffae490b6fa6f0c0e310ea88c83eee8be9d (diff) | |
download | vyos-1x-5f850ee4f60e08b7e1f62100f406ce1dcbfedd0e.tar.gz vyos-1x-5f850ee4f60e08b7e1f62100f406ce1dcbfedd0e.zip |
Merge pull request #293 from zdc/T2193
VRRP: T2193: Added disabled VRRP instances to `show vrrp`
Diffstat (limited to 'src/op_mode/vrrp.py')
-rwxr-xr-x | src/op_mode/vrrp.py | 23 |
1 files changed, 22 insertions, 1 deletions
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") |