summaryrefslogtreecommitdiff
path: root/src/op_mode/vrrp.py
diff options
context:
space:
mode:
authorzsdc <taras@vyos.io>2020-04-02 13:30:29 +0300
committerzsdc <taras@vyos.io>2020-04-02 13:30:29 +0300
commit9c605ffae490b6fa6f0c0e310ea88c83eee8be9d (patch)
tree3bbac3f9cf7c35b056bb1a69809bf2e0a33cd7f2 /src/op_mode/vrrp.py
parent2e8150e060568be4ec465b9135ddd52fd7423e94 (diff)
downloadvyos-1x-9c605ffae490b6fa6f0c0e310ea88c83eee8be9d.tar.gz
vyos-1x-9c605ffae490b6fa6f0c0e310ea88c83eee8be9d.zip
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
Diffstat (limited to 'src/op_mode/vrrp.py')
-rwxr-xr-xsrc/op_mode/vrrp.py23
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")