diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-04-17 08:11:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-17 08:11:31 +0200 |
commit | 75c7e2a5cea6713623208a4023455de64d13d7e1 (patch) | |
tree | 8be3e77575d316d428dfd1d570a7502257dea4b5 /src/conf_mode/vrrp.py | |
parent | 3964ee10a3a85e3655135d7e0235b4d1b2f08214 (diff) | |
parent | 7d04bfbcc74e062b80b337753e7018a6af81e70c (diff) | |
download | vyos-1x-75c7e2a5cea6713623208a4023455de64d13d7e1.tar.gz vyos-1x-75c7e2a5cea6713623208a4023455de64d13d7e1.zip |
Merge pull request #341 from thomas-mangin/T2223
op_mode: T2223: convert vyatta-show-interfaces.pl to show_interfaces.py
Diffstat (limited to 'src/conf_mode/vrrp.py')
-rwxr-xr-x | src/conf_mode/vrrp.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/conf_mode/vrrp.py b/src/conf_mode/vrrp.py index b9b0405e2..f358891a5 100755 --- a/src/conf_mode/vrrp.py +++ b/src/conf_mode/vrrp.py @@ -22,16 +22,13 @@ from json import dumps from pathlib import Path import vyos.config -import vyos.keepalived from vyos import ConfigError from vyos.util import call from vyos.template import render +from vyos.ifconfig.vrrp import VRRP -daemon_file = "/etc/default/keepalived" -config_file = "/etc/keepalived/keepalived.conf" -config_dict_path = "/run/keepalived_config.dict" def get_config(): vrrp_groups = [] @@ -127,7 +124,7 @@ def get_config(): sync_groups.append(sync_group) # create a file with dict with proposed configuration - with open("{}.temp".format(config_dict_path), 'w') as dict_file: + with open("{}.temp".format(VRRP.location['vyos']), 'w') as dict_file: dict_file.write(dumps({'vrrp_groups': vrrp_groups, 'sync_groups': sync_groups})) return (vrrp_groups, sync_groups) @@ -212,9 +209,9 @@ def generate(data): # Filter out disabled groups vrrp_groups = list(filter(lambda x: x["disable"] is not True, vrrp_groups)) - render(config_file, 'vrrp/keepalived.conf.tmpl', - {"groups": vrrp_groups, "sync_groups": sync_groups}) - render(daemon_file, 'vrrp/daemon.tmpl', {}) + render(VRRP.location['config'], 'vrrp/keepalived.conf.tmpl', + {"groups": vrrp_groups, "sync_groups": sync_groups}) + render(VRRP.location['daemon'], 'vrrp/daemon.tmpl', {}) return None @@ -223,12 +220,12 @@ def apply(data): if vrrp_groups: # safely rename a temporary file with configuration dict try: - dict_file = Path("{}.temp".format(config_dict_path)) - dict_file.rename(Path(config_dict_path)) + dict_file = Path("{}.temp".format(VRRP.location['vyos'])) + dict_file.rename(Path(VRRP.location['vyos'])) except Exception as err: print("Unable to rename the file with keepalived config for FIFO pipe: {}".format(err)) - if not vyos.keepalived.vrrp_running(): + if not VRRP.is_running(): print("Starting the VRRP process") ret = call("sudo systemctl restart keepalived.service") else: @@ -241,7 +238,7 @@ def apply(data): # VRRP is removed in the commit print("Stopping the VRRP process") call("sudo systemctl stop keepalived.service") - os.unlink(config_file) + os.unlink(VRRP.location['daemon']) return None |