From 9f5abb65f04d1ce40532e266e942ad35b8ebae92 Mon Sep 17 00:00:00 2001
From: Bob <bob@clough.me>
Date: Thu, 8 Nov 2018 17:03:38 +0000
Subject: dhcp - move commit hook into shared-network

Move the on commit in a generated dhcpd.conf into the shared-network
to fix hostfile-update not working.
---
 src/conf_mode/dhcp_server.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

(limited to 'src/conf_mode')

diff --git a/src/conf_mode/dhcp_server.py b/src/conf_mode/dhcp_server.py
index 2a2b1fe6c..560c80e7f 100755
--- a/src/conf_mode/dhcp_server.py
+++ b/src/conf_mode/dhcp_server.py
@@ -42,14 +42,6 @@ config_tmpl = """
 # log-facility local7;
 
 {% if hostfile_update %}
-on commit {
-    set ClientName = pick-first-value(host-decl-name, option fqdn.hostname, option host-name);
-    set ClientIp = binary-to-ascii(10, 8, ".", leased-address);
-    set ClientMac = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
-    set ClientDomain = pick-first-value(config-option domain-name, "..YYZ!");
-    execute("/usr/libexec/vyos/system/on-dhcp-event.sh", "commit", ClientName, ClientIp, ClientMac, ClientDomain);
-}
-
 on release {
     set ClientName = pick-first-value(host-decl-name, option fqdn.hostname, option host-name);
     set ClientIp = binary-to-ascii(10, 8, ".",leased-address);
@@ -210,7 +202,16 @@ shared-network {{ network.name }} {
         {%- endif %}
     }
     {%- endfor %}
-    on commit { set shared-networkname = "{{ network.name }}"; }
+    on commit {
+        set shared-networkname = "{{ network.name }}";
+        {% if hostfile_update -%}
+        set ClientName = pick-first-value(host-decl-name, option fqdn.hostname, option host-name);
+        set ClientIp = binary-to-ascii(10, 8, ".", leased-address);
+        set ClientMac = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
+        set ClientDomain = pick-first-value(config-option domain-name, "..YYZ!");
+        execute("/usr/libexec/vyos/system/on-dhcp-event.sh", "commit", ClientName, ClientIp, ClientMac, ClientDomain);
+        {% endif -%}
+    }
 }
 {%- endif %}
 {% endfor %}
-- 
cgit v1.2.3