1919from vyos import ConfigError
2020from vyos .base import Warning
2121from vyos .config import Config
22+ from vyos .frrender import FRRender
23+ from vyos .frrender import get_frrender_dict
2224from vyos .logger import syslog
2325from vyos .template import render_to_string
2426from vyos .utils .boot import boot_configuration_complete
2527from vyos .utils .file import read_file
2628from vyos .utils .file import write_file
2729from vyos .utils .process import call
30+ from vyos .utils .process import is_systemd_service_running
2831
2932from vyos import airbag
3033airbag .enable ()
3134
3235# path to daemons config and config status files
33- config_file = '/etc/frr/daemons'
36+ daemon_config_file = '/etc/frr/daemons'
3437
3538def get_config (config = None ):
3639 if config :
@@ -42,6 +45,8 @@ def get_config(config=None):
4245 frr_config = conf .get_config_dict (base , key_mangling = ('-' , '_' ),
4346 get_first_key = True ,
4447 with_recursive_defaults = True )
48+ # get FRR configuration
49+ frr_config ['frrender' ] = get_frrender_dict (conf )
4550
4651 return frr_config
4752
@@ -51,15 +56,27 @@ def verify(frr_config):
5156
5257def generate (frr_config ):
5358 # read daemons config file
54- daemons_config_current = read_file (config_file )
59+ daemons_config_current = read_file (daemon_config_file )
5560 # generate new config file
5661 daemons_config_new = render_to_string ('frr/daemons.frr.tmpl' , frr_config )
5762 # update configuration file if this is necessary
5863 if daemons_config_new != daemons_config_current :
5964 syslog .warning ('FRR daemons configuration file need to be changed' )
60- write_file (config_file , daemons_config_new )
65+ write_file (daemon_config_file , daemons_config_new )
6166 frr_config ['config_file_changed' ] = True
6267
68+ # profile could be automatically generated by frr in frr.conf
69+ # and needs to be updated as it is taking precedence
70+ if 'frrender' in frr_config and 'profile' in frr_config ['frrender' ]:
71+ frr_config ['frrender' ]['profile' ] = frr_config ['profile' ]
72+ if frr_config ['frrender' ] and not is_systemd_service_running (
73+ 'vyos-configd.service'
74+ ):
75+ FRRender ().generate (frr_config ['frrender' ])
76+ # apply here to keep consistency with the generated daemons
77+ # config file
78+ FRRender ().apply ()
79+
6380def apply (frr_config ):
6481 # display warning to user
6582 if boot_configuration_complete () and frr_config .get ('config_file_changed' ):
0 commit comments