summaryrefslogtreecommitdiff
path: root/src/helpers/vyos_config_sync.py
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2024-03-18 18:55:47 +0100
committerGitHub <noreply@github.com>2024-03-18 18:55:47 +0100
commit20e08490e0a2c84c4925400c51fa9eb05f96f5b6 (patch)
tree28776671e04bc1c58a80ab8e4425c712665f0d44 /src/helpers/vyos_config_sync.py
parent42f3b83dd89893ca077bf41275d58a40294832f6 (diff)
parent84314fc310eb0b414c4060a6daeba1765af0cfa8 (diff)
downloadvyos-1x-20e08490e0a2c84c4925400c51fa9eb05f96f5b6.tar.gz
vyos-1x-20e08490e0a2c84c4925400c51fa9eb05f96f5b6.zip
Merge pull request #3144 from vyos/mergify/bp/sagitta/pr-3132
T6121: Extend service config-sync to new sections (backport #3132)
Diffstat (limited to 'src/helpers/vyos_config_sync.py')
-rwxr-xr-xsrc/helpers/vyos_config_sync.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/helpers/vyos_config_sync.py b/src/helpers/vyos_config_sync.py
index 7cfa8fe88..572fea61f 100755
--- a/src/helpers/vyos_config_sync.py
+++ b/src/helpers/vyos_config_sync.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2023 VyOS maintainers and contributors
+# Copyright (C) 2023-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -60,6 +60,7 @@ def post_request(url: str,
return response
+
def retrieve_config(section: str = None) -> Optional[Dict[str, Any]]:
"""Retrieves the configuration from the local server.
@@ -71,8 +72,6 @@ def retrieve_config(section: str = None) -> Optional[Dict[str, Any]]:
"""
if section is None:
section = []
- else:
- section = section.split()
conf = Config()
config = conf.get_config_dict(section, get_first_key=True)
@@ -101,8 +100,6 @@ def set_remote_config(
if path is None:
path = []
- else:
- path = path.split()
headers = {'Content-Type': 'application/json'}
# Disable the InsecureRequestWarning
@@ -127,17 +124,16 @@ def set_remote_config(
def is_section_revised(section: str) -> bool:
from vyos.config_mgmt import is_node_revised
- return is_node_revised([section])
+ return is_node_revised(section)
def config_sync(secondary_address: str,
secondary_key: str,
- sections: List[str],
+ sections: List[list],
mode: str):
"""Retrieve a config section from primary router in JSON format and send it to
secondary router
"""
- # Config sync only if sections changed
if not any(map(is_section_revised, sections)):
return
@@ -188,5 +184,17 @@ if __name__ == '__main__':
"Missing required configuration data for config synchronization.")
exit(0)
+ # Generate list_sections of sections/subsections
+ # [
+ # ['interfaces', 'pseudo-ethernet'], ['interfaces', 'virtual-ethernet'], ['nat'], ['nat66']
+ # ]
+ list_sections = []
+ for section, subsections in sections.items():
+ if subsections:
+ for subsection in subsections:
+ list_sections.append([section, subsection])
+ else:
+ list_sections.append([section])
+
config_sync(secondary_address, secondary_key,
- sections, mode)
+ list_sections, mode)