Package: fai-server Severity: wishlist
Forwarding patch from the devel list: -------- Original Message -------- Subject: Recursive fai-class Date: Fri, 15 Feb 2008 10:01:52 +0100 From: Raphaël Pinson <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Hello FAI devs, As I was looking at the list of FAI classes and dependencies we use for our production, I found that the system was a bit flat and that adding a recursive class declaration would make it more powerful. I'm attaching a patch to make fai-class work recursively (patch based on FAI 3.2.4). This patch modifies the addclass() function to make it recursive, i.e. whenever a new class is added, it checks for the presence of a $classdir/$class file and includes the classes listed there, that way it is done with $classdir/$HOSTNAME. Additionaly, a file named /tmp/fai/parsed_classes is used to store the parsed files in order to prevent loops. Attached is a graphviz graph (test_class.png) showing the kind of dependencies it allows - the $classdir/10-base-classes script dynamiquely declares the DEBIAN_4 class. The $classdir/DEBIAN_4 file is found and contains GRUB, so the GRUB class is defined ; - "test" is $HOSTNAME given in the kernel arguments. The $classdir/test file contains three classes: HEBEX, KERNEL and PART_CCISS_C0D0_defosof ; - when the HEBEX class is added, a file $classdir/HEBEX is found and parsed, declaring the 4 new classes: BOOT, MBR, NETWORK and CFD ; Eventually, FAI_CLASS contains (# are added commentaries) : ---- # DEFAULT DEFAULT # Begin 10-base-classes SOPHIA LINUX SOPHIA AMD64 DEBIAN DEBIAN_4 # File /var/lib/fai/config/class/DEBIAN_4 found GRUB # Back to 10-base-classes DEBIAN_4_0 DEBIAN_AMD64 DEBIAN_4_AMD64 DEBIAN_4_0_AMD64 SOPHIA_AMD64 SOPHIA_DEBIAN SOPHIA_DEBIAN_4 SOPHIA_DEBIAN_4_0 SOPHIA_DEBIAN_AMD64 SOPHIA_DEBIAN_4_AMD64 SOPHIA_DEBIAN_4_0_AMD64 SOPHIA_test # Begin 25-disk-classes PART_CCISS_C0D0_test # Reading $classdir/test HEBEX # File /var/lib/fai/config/class/HEBEX found BOOT MBR NETWORK CFD # Back to $classdir/test KERNEL PART_CCISS_C0D0_defosof # $HOSTNAME test # LAST LAST ---- I'd be happy if some of you can test the patch and give some feedback. Cheers, Raphaël -- Henning Sprang http://www.sprang.de | http://lazyb0y.blogspot.com/
--- fai-3.2.4/bin/fai-class 2007-11-10 14:55:28.000000000 +0100
+++ fai-class.new 2008-02-15 09:43:50.000000000 +0100
@@ -49,13 +49,25 @@
# append classes to a file
while read line ; do
- case $line in
- \#*) ;; # strip comments
- *) debugmsg "Adding class $line"
- for class in $line ; do
- echo $class >> $filename
- done
- esac
+ case $line in
+ \#*) ;; # strip comments
+ *)
+ for class in $line ; do
+ verbosemsg "I: Adding class $class"
+ echo $class >> $filename
+
+ if [[ -f $classdir/$class ]] ; then
+ verbosemsg "I: File $classdir/$class found."
+ if grep -q "^${class}$" $PARSEDCLASSES; then
+ verbosemsg "W: $class already done. Not doing again."
+ else
+ verbosemsg "I: Recursively analyzing $class."
+ echo "$class" >> $PARSEDCLASSES
+ grep -v "^#" "$classdir/$class" | addclass
+ fi
+ fi
+ done
+ esac
done
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -141,6 +158,9 @@
setup "$@"
verbosemsg "$0: Defining classes."
+# initialize $PARSEDCLASSES
+PARSEDCLASSES="/tmp/fai/parsed_classes"
+
echo DEFAULT | addclass
# define classes by executing scripts
@@ -192,6 +212,7 @@
# add all classes which are listed in a file with the hostname
if [ -f "$HOSTNAME" ]; then
verbosemsg "Using classes from file $classdir/$HOSTNAME"
+ echo "$HOSTNAME" >> $PARSEDCLASSES
grep -v "^#" $HOSTNAME | addclass
fi
<<inline: test_class.png>>

