[debian-lan-devel] [debian-lan] 01/01: More flexible mechanism for adding hosts

Andreas B. Mundt andi at moszumanska.debian.org
Thu Sep 15 13:06:02 UTC 2016


This is an automated email from the git hooks/post-receive script.

andi pushed a commit to branch experimental
in repository debian-lan.

commit 6c621782361bf2f27a93d7b9413b6d3b54e2bf85
Author: Afif Elghraoui <afif at debian.org>
Date:   Sat Aug 20 01:44:14 2016 -0700

    More flexible mechanism for adding hosts
    
    * Do not create dummy host entries in dhcpd.conf
    * Use separate files included from dhcpd.conf to only contain host definitions
    * Add hosts file (/usr/local/etc/hosts) to help with management of all clients
---
 fai/config/class/SERVER_A.var                      |  9 +--
 .../usr/local/sbin/debian-lan-chroots/FAISERVER    | 24 --------
 .../files/usr/local/sbin/debian-lan/SERVER_A       | 35 ++++++++---
 fai/config/scripts/FAISERVER/10-config             |  6 +-
 fai/config/scripts/FAISERVER/40-dhcp               | 69 +++++++++++++---------
 5 files changed, 72 insertions(+), 71 deletions(-)

diff --git a/fai/config/class/SERVER_A.var b/fai/config/class/SERVER_A.var
index 349e223..26a22ff 100644
--- a/fai/config/class/SERVER_A.var
+++ b/fai/config/class/SERVER_A.var
@@ -70,12 +70,9 @@ SUBNETMASK="10.0.0.0/16"
 FAINETMASK=${FAINETMASK:-'10.0.0.0/16'}
 
 ## DHCP range for unknown clients (cf. dhcpd.conf):
-RANGE="10.0.1.100 10.0.1.199"
-
-## IP address-endings for workstations and diskless machines (the list
-## is generated using 'seq $WS_RANGE' respectively 'seq $DL_RANGE'):
-WS_RANGE="50 149"
-DL_RANGE="150 249"
+GUEST_RANGE="10.0.1.50 10.0.1.99"
+## DHCP range for member clients (workstations and diskless)
+MEMBER_RANGE="10.0.1.100 10.0.1.249"
 
 ## Local APT repository for the site (accessible via http).
 ## Set empty to skip this feature.
diff --git a/fai/config/files/usr/local/sbin/debian-lan-chroots/FAISERVER b/fai/config/files/usr/local/sbin/debian-lan-chroots/FAISERVER
index 352661b..5f31401 100755
--- a/fai/config/files/usr/local/sbin/debian-lan-chroots/FAISERVER
+++ b/fai/config/files/usr/local/sbin/debian-lan-chroots/FAISERVER
@@ -56,18 +56,6 @@ kernel $KERNEL
 append initrd=$INITRD ip=dhcp root=nfs:/srv/nfs4/$(basename $NFSROOT) rootovl FAI_FLAGS=verbose,sshd,createvt FAI_CONFIG_SRC=nfs://faiserver/config FAI_ACTION=install
 EOF
 
-    ## Create pxelinux boot configuration for workstationXX.
-    ## The seq range is sed from the corresponding variable
-    ## when fcopy'd:
-    echo -n "Creating pxelinux boot configurations: "
-    NUM=0
-    for IPADDR in `seq WS_RANGE` ; do
-        fai-chboot -vc workstation.tmpl PREFIX.$IPADDR &>> /var/log/fai/fai-chboot.log
-        echo -n "."
-        NUM=$(($NUM+1))
-    done
-    echo -e " Done.\nCreated $NUM workstation configurations."
-
     if [ -e $DL_TEMPLATE ] ; then
         fai-chboot -vc diskless.tmpl default &>> /var/log/fai/fai-chboot.log
     else
@@ -106,18 +94,6 @@ kernel $KERNEL
 append initrd=$INITRD ip=dhcp root=/dev/nfs nfsroot=/srv/nfs4/live rootovl
 EOF
 
-    ## Create pxelinux boot configuration for disklessXX.
-    ## The seq range is sed from the corresponding variable
-    ## when fcopy'd:
-    echo -n "Creating pxelinux boot configurations: "
-    NUM=0
-    for IPADDR in `seq DL_RANGE` ; do
-        fai-chboot -vc diskless.tmpl PREFIX.$IPADDR &>> /var/log/fai/fai-chboot.log
-        echo -n "."
-        NUM=$(($NUM+1))
-    done
-    echo -e " Done.\nCreated $NUM diskless machine configurations."
-
     ## Boot unknown machines as diskless:
     fai-chboot -vc diskless.tmpl default &>> /var/log/fai/fai-chboot.log
 }
diff --git a/fai/config/files/usr/local/sbin/debian-lan/SERVER_A b/fai/config/files/usr/local/sbin/debian-lan/SERVER_A
index 0ff388f..782ee98 100755
--- a/fai/config/files/usr/local/sbin/debian-lan/SERVER_A
+++ b/fai/config/files/usr/local/sbin/debian-lan/SERVER_A
@@ -9,7 +9,8 @@ DATADIR="/root/installation/"
 #KADMINOPTION="-force"
 HOSTNAME=`hostname -s`
 HOME="/lan/$HOSTNAME/home0"
-DHCPCONF="/etc/dhcp/dhcpd.conf"
+DHCPCLIENTSDIR="/etc/dhcp/clients.d/"
+HOSTSFILE="/usr/local/etc/hosts"
 DATE=`date +%Y%m%d`
 
 ## Password restrictions (compliant with kerberos policy):
@@ -17,7 +18,7 @@ MINLEN=4  # minimal password length (max 8 with slappasswd as password generator
 MINCLS=2  # minimal number of character classes
 
 usage(){
-    echo "Usage: debian-lan  adduser|deluser|purgehomes|key2machine  argument"
+    echo "Usage: debian-lan  adduser|deluser|purgehomes|key2machine|chboot  argument"
     echo "       debian-lan  add2dhcp"
     echo
     echo "The corresponding argument can be one of the following:"
@@ -42,6 +43,9 @@ usage(){
     echo "   All non-local hardware MAC addresses found in the syslog may be added"
     echo "   to '$DHCPCONF', either as workstation or diskless machine."
     echo
+    echo "  chboot hostname"
+    echo "   Set PXE boot configuration for hostname to its class template"
+    echo
     exit 1
 }
 
@@ -259,10 +263,10 @@ case $COMMAND in
                 echo "Skipping local MAC address: ${HWaddr}"
                 echo
                 continue
-            elif grep $HWaddr $DHCPCONF; then
-                echo "--->  MAC address already present in ${DHCPCONF}."
+            elif grep $HWaddr $DHCPCLIENTSDIR/*.list; then
+                echo "--->  MAC address already present in ${DHCPCLIENTSDIR}."
             else
-                echo "Add ${HWaddr} to ${DHCPCONF}?"
+                echo "Add ${HWaddr} to managed DHCP clients?"
                 read -e -n 1 -p "Choose d (diskless), w (workstation) or press RETURN to ignore [d|w|N]: " inp
                 inp=${inp:-N}
                 case $inp in
@@ -278,8 +282,15 @@ case $COMMAND in
                         continue
                         ;;
                 esac
-                sed -i "0,/\(host ${NAME}.*\) A1:B2:C3:D4:E5:\w\{2\};/s//\1 ${HWaddr};/" ${DHCPCONF}
-                MACHINE=$(grep $HWaddr ${DHCPCONF} | awk -F " " '{print $2}')
+		NUMBER=$(printf "%02d" \
+				$(expr \
+				      $(grep -Po "(?<=${NAME})[0-9]*" \
+					     ${HOSTSFILE} \
+					       | sort | tail -n1) \
+				      + 1))
+		MACHINE=${NAME}${NUMBER}
+		echo "host ${MACHINE} {hardware ethernet ${HWaddr}; ddns-hostname ${MACHINE};}" >> ${DHCPCLIENTSDIR}/${NAME}.list
+		echo "${MACHINE}" >> ${HOSTSFILE}
                 echo "MAC address $HWaddr added as: ${MACHINE}"
                 add2log ${MACHINE}
             fi
@@ -288,6 +299,16 @@ case $COMMAND in
         /etc/init.d/isc-dhcp-server restart
         /etc/init.d/icinga reload
         ;;
+    chboot)
+	MACHINE=$1
+	IP=$2
+	NAME=${MACHINE//[0-9]/}
+	LOG=/var/log/chboot.log
+	. /etc/fai/nfsroot.conf
+	test -e $TFTPROOT/pxelinux.cfg/$NAME.tmpl \
+	    && fai-chboot -vc ${NAME}.tmpl ${IP} 2>&1 >> $LOG \
+		|| echo "No boot configuration was found for host type '${NAME}'; using default." >> $LOG
+	;;
     *)
         usage
         ;;
diff --git a/fai/config/scripts/FAISERVER/10-config b/fai/config/scripts/FAISERVER/10-config
index ca3bbe0..1d9420a 100755
--- a/fai/config/scripts/FAISERVER/10-config
+++ b/fai/config/scripts/FAISERVER/10-config
@@ -5,13 +5,9 @@ set -e
 fcopy -r /etc/fai
 
 if [ "$FAI_ACTION" == "install" ] || [ "$CONVERT" == "true" ] ; then
-    ## fetch template and insert 'number' of workstations:
+    ## fetch template:
     FILE="/usr/local/sbin/debian-lan-chroots"
     fcopy $FILE
-    sed -i "s/WS_RANGE/${WS_RANGE}/g" ${target}$FILE
-    sed -i "s/DL_RANGE/${DL_RANGE}/g" ${target}$FILE
-    PREFIX=`echo $SUBNET | cut -d "." --fields=1,2,3`
-    sed -i "s/PREFIX/${PREFIX}/g" ${target}$FILE
 
     if ifclass DISKLESS_SERVER ; then
 	sed -i "s%\(^.*\#\#DISKLESS_SERVER\#\#\)%\#\1%"  ${target}$FILE
diff --git a/fai/config/scripts/FAISERVER/40-dhcp b/fai/config/scripts/FAISERVER/40-dhcp
index 15c31be..3de3f1e 100755
--- a/fai/config/scripts/FAISERVER/40-dhcp
+++ b/fai/config/scripts/FAISERVER/40-dhcp
@@ -67,8 +67,11 @@ option dhcp-max-message-size  2048;
 
 ddns-updates          on;
 ddns-update-style     interim;
-update-static-leases  on;
 use-host-decl-names   on;
+# Check on ISC #31179 ; fixed in 2016; still affects Jessie
+# https://lists.isc.org/pipermail/dhcp-users/2016-March/019589.html
+# https://kb.isc.org/article/AA-01357/0/DHCP-4.3.4b1-Release-Notes.html
+infinite-is-reserved on;
 
 include "/etc/dhcp/ddns.key";
 
@@ -85,7 +88,6 @@ zone ${PREFIX2}.${PREFIX1}.in-addr.arpa. {
 class "PXE-clients" {
    match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";
    ddns-updates    off;
-   max-lease-time  120;
    server-name faiserver;
    next-server faiserver;
 }
@@ -99,44 +101,53 @@ subnet ${SUBNET} netmask ${NETMASK} {
    pool {
       allow unknown-clients;
       max-lease-time 7200;
-      range ${RANGE};
+      range ${GUEST_RANGE};
       filename "debian-installer/pxelinux.0";
       if not exists host-name {
          option host-name = concat("guest",suffix(binary-to-ascii(10,8,".",suffix(leased-address,1)),2));
          ddns-hostname = config-option host-name;
       }
    }
-}
 
-group {
-   filename "fai/pxelinux.0";
-   on commit {
-        execute("/usr/local/sbin/dhcpd-keytab", host-decl-name);
+   pool {
+      deny unknown-clients;
+      default-lease-time -1;
+      max-lease-time -1;
+      range ${MEMBER_RANGE};
+      filename "fai/pxelinux.0";
+
+      group {
+         on commit {
+            execute("/usr/local/sbin/dhcpd-keytab", host-decl-name);
+            execute("/usr/local/sbin/debian-lan", "chboot", host-decl-name, binary-to-ascii(10,8,".",leased-address));
+         }
+
+         include "/etc/dhcp/clients.d/workstation.list";
+      }
+
+      group {
+         on commit {
+            execute("/usr/local/sbin/debian-lan", "chboot", host-decl-name, binary-to-ascii(10,8,".",leased-address));
+         }
+
+         include "/etc/dhcp/clients.d/diskless.list";
+      }
    }
+}
 
 EOF
 
-PREFIX=`echo $SUBNET | cut -d "." --fields=1,2,3`
+mkdir -p $target/etc/dhcp/clients.d
 
-NUM=0
-for IPADDR in `seq $WS_RANGE` ; do
-    NUMSTR=`printf "%02d" $NUM`
-    echo "   host workstation${NUMSTR} {hardware ethernet A1:B2:C3:D4:E5:${NUMSTR}; fixed-address $PREFIX.$IPADDR; ddns-hostname workstation${NUMSTR};}" \
-	>> $target/etc/dhcp/dhcpd.conf
-    NUM=$(($NUM+1))
+for client_type in workstation diskless
+do
+    if [ ! -f $target/etc/dhcp/clients.d/$client_type.list ]
+    then
+	touch $target/etc/dhcp/clients.d/$client_type.list
+    fi
 done
-echo "}" >> $target/etc/dhcp/dhcpd.conf
-cat >> $target/etc/dhcp/dhcpd.conf <<EOF
-
-group {
-   filename "fai/pxelinux.0";
 
-EOF
-NUM=0
-for IPADDR in `seq $DL_RANGE` ; do
-    NUMSTR=`printf "%02d" $NUM`
-    echo "   host diskless${NUMSTR} {hardware ethernet A1:B2:C3:D4:E5:${NUMSTR}; fixed-address $PREFIX.$IPADDR; ddns-hostname diskless${NUMSTR};}" \
-	>> $target/etc/dhcp/dhcpd.conf
-    NUM=$(($NUM+1))
-done
-echo "}" >> $target/etc/dhcp/dhcpd.conf
+if [ ! -f $target/usr/local/etc/hosts ]
+then
+   touch $target/usr/local/etc/hosts
+fi

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/debian-lan.git



More information about the debian-lan-devel mailing list