diff --git a/daemon/core/configservice/base.py b/daemon/core/configservice/base.py index 386ab26d..6e1dc859 100644 --- a/daemon/core/configservice/base.py +++ b/daemon/core/configservice/base.py @@ -19,6 +19,20 @@ logger = logging.getLogger(__name__) TEMPLATES_DIR: str = "templates" +def get_template_path(file_path: Path) -> str: + """ + Utility to convert a given file path to a valid template path format. + + :param file_path: file path to convert + :return: template path + """ + if file_path.is_absolute(): + template_path = str(file_path.relative_to("/")) + else: + template_path = str(file_path) + return template_path + + class ConfigServiceMode(enum.Enum): BLOCKING = 0 NON_BLOCKING = 1 @@ -295,10 +309,7 @@ class ConfigService(abc.ABC): templates = {} for file in self.files: file_path = Path(file) - if file_path.is_absolute(): - template_path = str(file_path.relative_to("/")) - else: - template_path = str(file_path) + template_path = get_template_path(file_path) if file in self.custom_templates: template = self.custom_templates[file] template = self.clean_text(template) @@ -322,11 +333,12 @@ class ConfigService(abc.ABC): "node(%s) service(%s) template(%s)", self.node.name, self.name, file ) file_path = Path(file) + template_path = get_template_path(file_path) if file in self.custom_templates: text = self.custom_templates[file] rendered = self.render_text(text, data) - elif self.templates.has_template(file_path.name): - rendered = self.render_template(file_path.name, data) + elif self.templates.has_template(template_path): + rendered = self.render_template(template_path, data) else: text = self.get_text_template(file) rendered = self.render_text(text, data) diff --git a/daemon/core/configservices/frrservices/templates/daemons b/daemon/core/configservices/frrservices/templates/usr/local/etc/frr/daemons similarity index 100% rename from daemon/core/configservices/frrservices/templates/daemons rename to daemon/core/configservices/frrservices/templates/usr/local/etc/frr/daemons diff --git a/daemon/core/configservices/frrservices/templates/frr.conf b/daemon/core/configservices/frrservices/templates/usr/local/etc/frr/frr.conf similarity index 100% rename from daemon/core/configservices/frrservices/templates/frr.conf rename to daemon/core/configservices/frrservices/templates/usr/local/etc/frr/frr.conf diff --git a/daemon/core/configservices/frrservices/templates/vtysh.conf b/daemon/core/configservices/frrservices/templates/usr/local/etc/frr/vtysh.conf similarity index 100% rename from daemon/core/configservices/frrservices/templates/vtysh.conf rename to daemon/core/configservices/frrservices/templates/usr/local/etc/frr/vtysh.conf diff --git a/daemon/core/configservices/nrlservices/templates/olsrd.conf b/daemon/core/configservices/nrlservices/templates/etc/olsrd/olsrd.conf similarity index 100% rename from daemon/core/configservices/nrlservices/templates/olsrd.conf rename to daemon/core/configservices/nrlservices/templates/etc/olsrd/olsrd.conf diff --git a/daemon/core/configservices/quaggaservices/templates/Quagga.conf b/daemon/core/configservices/quaggaservices/templates/usr/local/etc/quagga/Quagga.conf similarity index 100% rename from daemon/core/configservices/quaggaservices/templates/Quagga.conf rename to daemon/core/configservices/quaggaservices/templates/usr/local/etc/quagga/Quagga.conf diff --git a/daemon/core/configservices/quaggaservices/templates/vtysh.conf b/daemon/core/configservices/quaggaservices/templates/usr/local/etc/quagga/vtysh.conf similarity index 100% rename from daemon/core/configservices/quaggaservices/templates/vtysh.conf rename to daemon/core/configservices/quaggaservices/templates/usr/local/etc/quagga/vtysh.conf diff --git a/daemon/core/configservices/utilservices/templates/apache2.conf b/daemon/core/configservices/utilservices/templates/etc/apache2/apache2.conf similarity index 100% rename from daemon/core/configservices/utilservices/templates/apache2.conf rename to daemon/core/configservices/utilservices/templates/etc/apache2/apache2.conf diff --git a/daemon/core/configservices/utilservices/templates/envvars b/daemon/core/configservices/utilservices/templates/etc/apache2/envvars similarity index 100% rename from daemon/core/configservices/utilservices/templates/envvars rename to daemon/core/configservices/utilservices/templates/etc/apache2/envvars diff --git a/daemon/core/configservices/utilservices/templates/dhcpd.conf b/daemon/core/configservices/utilservices/templates/etc/dhcp/dhcpd.conf similarity index 100% rename from daemon/core/configservices/utilservices/templates/dhcpd.conf rename to daemon/core/configservices/utilservices/templates/etc/dhcp/dhcpd.conf diff --git a/daemon/core/configservices/utilservices/templates/radvd.conf b/daemon/core/configservices/utilservices/templates/etc/radvd/radvd.conf similarity index 100% rename from daemon/core/configservices/utilservices/templates/radvd.conf rename to daemon/core/configservices/utilservices/templates/etc/radvd/radvd.conf diff --git a/daemon/core/configservices/utilservices/templates/sshd_config b/daemon/core/configservices/utilservices/templates/etc/ssh/sshd_config similarity index 100% rename from daemon/core/configservices/utilservices/templates/sshd_config rename to daemon/core/configservices/utilservices/templates/etc/ssh/sshd_config diff --git a/daemon/core/configservices/utilservices/templates/index.html b/daemon/core/configservices/utilservices/templates/var/www/index.html similarity index 100% rename from daemon/core/configservices/utilservices/templates/index.html rename to daemon/core/configservices/utilservices/templates/var/www/index.html