From 039e323d7e46f7d8244c42794f713a0bfecbe2d3 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 16 Apr 2022 12:14:56 +0200 Subject: dhcp(v6)-client: T4353: fix Jinja2 linting errors --- data/templates/dhcp-client/daemon-options.j2 | 4 ++ data/templates/dhcp-client/daemon-options.tmpl | 4 -- data/templates/dhcp-client/ipv4.j2 | 34 +++++++++++++++ data/templates/dhcp-client/ipv4.tmpl | 34 --------------- data/templates/dhcp-client/ipv6.j2 | 60 ++++++++++++++++++++++++++ data/templates/dhcp-client/ipv6.tmpl | 60 -------------------------- python/vyos/ifconfig/interface.py | 7 ++- 7 files changed, 101 insertions(+), 102 deletions(-) create mode 100644 data/templates/dhcp-client/daemon-options.j2 delete mode 100644 data/templates/dhcp-client/daemon-options.tmpl create mode 100644 data/templates/dhcp-client/ipv4.j2 delete mode 100644 data/templates/dhcp-client/ipv4.tmpl create mode 100644 data/templates/dhcp-client/ipv6.j2 delete mode 100644 data/templates/dhcp-client/ipv6.tmpl diff --git a/data/templates/dhcp-client/daemon-options.j2 b/data/templates/dhcp-client/daemon-options.j2 new file mode 100644 index 000000000..b21ad08ab --- /dev/null +++ b/data/templates/dhcp-client/daemon-options.j2 @@ -0,0 +1,4 @@ +### Autogenerated by interface.py ### +{% set if_metric = '-e IF_METRIC=' ~ dhcp_options.default_route_distance if dhcp_options.default_route_distance is vyos_defined else '' %} +DHCLIENT_OPTS="-nw -cf /var/lib/dhcp/dhclient_{{ ifname }}.conf -pf /var/lib/dhcp/dhclient_{{ ifname }}.pid -lf /var/lib/dhcp/dhclient_{{ ifname }}.leases {{ if_metric }} {{ ifname }}" + diff --git a/data/templates/dhcp-client/daemon-options.tmpl b/data/templates/dhcp-client/daemon-options.tmpl deleted file mode 100644 index 5b3bff73f..000000000 --- a/data/templates/dhcp-client/daemon-options.tmpl +++ /dev/null @@ -1,4 +0,0 @@ -### Autogenerated by interface.py ### - -DHCLIENT_OPTS="-nw -cf /var/lib/dhcp/dhclient_{{ ifname }}.conf -pf /var/lib/dhcp/dhclient_{{ ifname }}.pid -lf /var/lib/dhcp/dhclient_{{ ifname }}.leases{{" -e IF_METRIC=" ~ dhcp_options.default_route_distance if dhcp_options.default_route_distance is vyos_defined }} {{ ifname }}" - diff --git a/data/templates/dhcp-client/ipv4.j2 b/data/templates/dhcp-client/ipv4.j2 new file mode 100644 index 000000000..cc5ddf09c --- /dev/null +++ b/data/templates/dhcp-client/ipv4.j2 @@ -0,0 +1,34 @@ +### Autogenerated by interface.py ### + +option rfc3442-classless-static-routes code 121 = array of unsigned integer 8; +timeout 60; +retry 60; +initial-interval 2; + +interface "{{ ifname }}" { + send host-name "{{ dhcp_options.host_name }}"; +{% if dhcp_options.client_id is vyos_defined %} +{% set client_id = dhcp_options.client_id %} +{# Use HEX representation of client-id as it is send in MAC-address style using hex characters. If not HEX, use double quotes ASCII format #} +{% if not dhcp_options.client_id.split(':') | length >= 5 %} +{% set client_id = '"' + dhcp_options.client_id + '"' %} +{% endif %} + send dhcp-client-identifier {{ client_id }}; +{% endif %} +{% if dhcp_options.vendor_class_id is vyos_defined %} + send vendor-class-identifier "{{ dhcp_options.vendor_class_id }}"; +{% endif %} + # The request statement causes the client to request that any server responding to the + # client send the client its values for the specified options. + request subnet-mask, broadcast-address,{{ " routers," if dhcp_options.no_default_route is not vyos_defined }} domain-name-servers, + rfc3442-classless-static-routes, domain-name, interface-mtu; + + # The require statement lists options that must be sent in order for an offer to be + # accepted. Offers that do not contain all the listed options will be ignored! + require subnet-mask; +{% if dhcp_options.reject is vyos_defined %} + # Block addresses coming from theses dhcp servers if configured. + reject {{ dhcp_options.reject | join(', ') }}; +{% endif %} +} + diff --git a/data/templates/dhcp-client/ipv4.tmpl b/data/templates/dhcp-client/ipv4.tmpl deleted file mode 100644 index 83fb93dc1..000000000 --- a/data/templates/dhcp-client/ipv4.tmpl +++ /dev/null @@ -1,34 +0,0 @@ -### Autogenerated by interface.py ### - -option rfc3442-classless-static-routes code 121 = array of unsigned integer 8; -timeout 60; -retry 60; -initial-interval 2; - -interface "{{ ifname }}" { - send host-name "{{ dhcp_options.host_name }}"; -{% if dhcp_options.client_id is vyos_defined %} -{% set client_id = dhcp_options.client_id %} -{# Use HEX representation of client-id as it is send in MAC-address style using hex characters. If not HEX, use double quotes ASCII format #} -{% if not dhcp_options.client_id.split(':') | length >= 5 %} -{% set client_id = '"' + dhcp_options.client_id + '"' %} -{% endif %} - send dhcp-client-identifier {{ client_id }}; -{% endif %} -{% if dhcp_options.vendor_class_id is vyos_defined %} - send vendor-class-identifier "{{ dhcp_options.vendor_class_id }}"; -{% endif %} - # The request statement causes the client to request that any server responding to the - # client send the client its values for the specified options. - request subnet-mask, broadcast-address,{{ " routers," if dhcp_options.no_default_route is not vyos_defined }} domain-name-servers, - rfc3442-classless-static-routes, domain-name, interface-mtu; - - # The require statement lists options that must be sent in order for an offer to be - # accepted. Offers that do not contain all the listed options will be ignored! - require subnet-mask; -{% if dhcp_options.reject is vyos_defined %} - # Block addresses coming from theses dhcp servers if configured. - reject {{ dhcp_options.reject | join(', ') }}; -{% endif %} -} - diff --git a/data/templates/dhcp-client/ipv6.j2 b/data/templates/dhcp-client/ipv6.j2 new file mode 100644 index 000000000..e136b1789 --- /dev/null +++ b/data/templates/dhcp-client/ipv6.j2 @@ -0,0 +1,60 @@ +### Autogenerated by interface.py ### + +# man https://www.unix.com/man-page/debian/5/dhcp6c.conf/ +interface {{ ifname }} { +{% if dhcpv6_options.duid is vyos_defined %} + send client-id {{ dhcpv6_options.duid }}; +{% endif %} +{% if address is vyos_defined and 'dhcpv6' in address %} + request domain-name-servers; + request domain-name; +{% if dhcpv6_options.parameters_only is vyos_defined %} + information-only; +{% endif %} +{% if dhcpv6_options.temporary is not vyos_defined %} + send ia-na 0; # non-temporary address +{% endif %} +{% if dhcpv6_options.rapid_commit is vyos_defined %} + send rapid-commit; # wait for immediate reply instead of advertisements +{% endif %} +{% endif %} +{% if dhcpv6_options.pd is vyos_defined %} +{% for pd in dhcpv6_options.pd %} + send ia-pd {{ pd }}; # prefix delegation #{{ pd }} +{% endfor %} +{% endif %} +}; + +{% if address is vyos_defined and 'dhcpv6' in address %} +{% if dhcpv6_options.temporary is not vyos_defined %} +id-assoc na 0 { + # Identity association for non temporary address +}; +{% endif %} +{% endif %} + +{% if dhcpv6_options.pd is vyos_defined %} +{% for pd, pd_config in dhcpv6_options.pd.items() %} +id-assoc pd {{ pd }} { +{# length got a default value #} + prefix ::/{{ pd_config.length }} infinity; +{% set sla_len = 64 - pd_config.length | int %} +{% set count = namespace(value=0) %} +{% for interface, interface_config in pd_config.interface.items() if pd_config.interface is vyos_defined %} + prefix-interface {{ interface }} { + sla-len {{ sla_len }}; +{% if interface_config.sla_id is vyos_defined %} + sla-id {{ interface_config.sla_id }}; +{% else %} + sla-id {{ count.value }}; +{% endif %} +{% if interface_config.address is vyos_defined %} + ifid {{ interface_config.address }}; +{% endif %} + }; +{% set count.value = count.value + 1 %} +{% endfor %} +}; +{% endfor %} +{% endif %} + diff --git a/data/templates/dhcp-client/ipv6.tmpl b/data/templates/dhcp-client/ipv6.tmpl deleted file mode 100644 index 085cfe5a9..000000000 --- a/data/templates/dhcp-client/ipv6.tmpl +++ /dev/null @@ -1,60 +0,0 @@ -### Autogenerated by interface.py ### - -# man https://www.unix.com/man-page/debian/5/dhcp6c.conf/ -interface {{ ifname }} { -{% if dhcpv6_options.duid is vyos_defined %} - send client-id {{ dhcpv6_options.duid }}; -{% endif %} -{% if address is vyos_defined and 'dhcpv6' in address %} - request domain-name-servers; - request domain-name; -{% if dhcpv6_options.parameters_only is vyos_defined %} - information-only; -{% endif %} -{% if dhcpv6_options.temporary is not vyos_defined %} - send ia-na 0; # non-temporary address -{% endif %} -{% if dhcpv6_options.rapid_commit is vyos_defined %} - send rapid-commit; # wait for immediate reply instead of advertisements -{% endif %} -{% endif %} -{% if dhcpv6_options.pd is vyos_defined %} -{% for pd in dhcpv6_options.pd %} - send ia-pd {{ pd }}; # prefix delegation #{{ pd }} -{% endfor %} -{% endif %} -}; - -{% if address is vyos_defined and 'dhcpv6' in address %} -{% if dhcpv6_options.temporary is not vyos_defined %} -id-assoc na 0 { - # Identity association for non temporary address -}; -{% endif %} -{% endif %} - -{% if dhcpv6_options.pd is vyos_defined %} -{% for pd, pd_config in dhcpv6_options.pd.items() %} -id-assoc pd {{ pd }} { -{# length got a default value #} - prefix ::/{{ pd_config.length }} infinity; -{% set sla_len = 64 - pd_config.length|int %} -{% set count = namespace(value=0) %} -{% for interface, interface_config in pd_config.interface.items() if pd_config.interface is vyos_defined %} - prefix-interface {{ interface }} { - sla-len {{ sla_len }}; -{% if interface_config.sla_id is vyos_defined %} - sla-id {{ interface_config.sla_id }}; -{% else %} - sla-id {{ count.value }}; -{% endif %} -{% if interface_config.address is vyos_defined %} - ifid {{ interface_config.address }}; -{% endif %} - }; -{% set count.value = count.value + 1 %} -{% endfor %} -}; -{% endfor %} -{% endif %} - diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 6b0f08fd4..2345457dd 100755 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -1243,8 +1243,8 @@ class Interface(Control): tmp = {'dhcp_options' : { 'host_name' : hostname}} self._config = dict_merge(tmp, self._config) - render(options_file, 'dhcp-client/daemon-options.tmpl', self._config) - render(config_file, 'dhcp-client/ipv4.tmpl', self._config) + render(options_file, 'dhcp-client/daemon-options.j2', self._config) + render(config_file, 'dhcp-client/ipv4.j2', self._config) # When the DHCP client is restarted a brief outage will occur, as # the old lease is released a new one is acquired (T4203). We will @@ -1274,8 +1274,7 @@ class Interface(Control): systemd_service = f'dhcp6c@{ifname}.service' if enable and 'disable' not in self._config: - render(config_file, 'dhcp-client/ipv6.tmpl', - self._config) + render(config_file, 'dhcp-client/ipv6.j2', self._config) # We must ignore any return codes. This is required to enable # DHCPv6-PD for interfaces which are yet not up and running. -- cgit v1.2.3