From 94c9aa940aeb0ee17b14fc0d826ea01a38712a92 Mon Sep 17 00:00:00 2001
From: Weidong Shao <weidong.shao@huawei.com>
Date: Thu, 9 Jan 2014 03:21:14 +0000
Subject: [PATCH] Update cobbler snippets

---
 cobbler/snippets/chef               |  4 +-
 cobbler/snippets/chef-validator.pem |  1 -
 cobbler/snippets/client.rb          |  3 ++
 cobbler/snippets/ntp.conf           |  1 +
 cobbler/snippets/partition_disks    | 61 +++++++++++++++++++++--------
 cobbler/snippets/rsyslogconf        |  3 +-
 6 files changed, 53 insertions(+), 20 deletions(-)
 delete mode 120000 cobbler/snippets/chef-validator.pem

diff --git a/cobbler/snippets/chef b/cobbler/snippets/chef
index 4f194f9..7348f16 100644
--- a/cobbler/snippets/chef
+++ b/cobbler/snippets/chef
@@ -50,7 +50,7 @@ cat << EOF > /etc/init.d/chef
 # processname: chef-agent
 #if $getVar('ntp_server', '') != ""
 echo "old date is: \`date\`" 2>&1 > /tmp/ntp.log
-echo "path: \$PATH" 2>71 >> /tmp/ntp.log
+echo "path: \$PATH" 2>&1 >> /tmp/ntp.log
 /sbin/service ntpd stop 2>&1 >> /tmp/ntp.log
 /usr/sbin/ntpdate $server 2>&1 >> /tmp/ntp.log
 /sbin/service ntpd start 2>&1 >> /tmp/ntp.log
@@ -65,7 +65,7 @@ echo "*/1 * * * *  /etc/chef/rerun.sh" >> mycron
 crontab mycron
 rm mycron
 chkconfig chef off
-rm -rf /etc/init.d/chef
+mv /etc/init.d/chef /tmp/chef
 EOF
 
 
diff --git a/cobbler/snippets/chef-validator.pem b/cobbler/snippets/chef-validator.pem
deleted file mode 120000
index 340240d..0000000
--- a/cobbler/snippets/chef-validator.pem
+++ /dev/null
@@ -1 +0,0 @@
-/etc/chef-server/chef-validator.pem
\ No newline at end of file
diff --git a/cobbler/snippets/client.rb b/cobbler/snippets/client.rb
index 506db72..efb02c3 100644
--- a/cobbler/snippets/client.rb
+++ b/cobbler/snippets/client.rb
@@ -10,6 +10,9 @@ https_proxy      '$proxy'
 #if $getVar('ignore_proxy', '') != ""
 no_proxy         '$ignore_proxy'
 #end if
+#if $getVar('chef_node_name', '') != ""
+node_name        '$chef_node_name'
+#end if
 validation_client_name 'chef-validator'
 # Using default node name (fqdn) 
 
diff --git a/cobbler/snippets/ntp.conf b/cobbler/snippets/ntp.conf
index d27eb6e..1c12eda 100644
--- a/cobbler/snippets/ntp.conf
+++ b/cobbler/snippets/ntp.conf
@@ -24,6 +24,7 @@ restrict -6 ::1
 # server 2.centos.pool.ntp.org
 #if $getVar('ntp_server', '') != ""
 server $ntp_server
+fudge $ntp_server stratum 8
 #end if
 
 # broadcast 192.168.1.255 autokey	# broadcast server
diff --git a/cobbler/snippets/partition_disks b/cobbler/snippets/partition_disks
index e2ea9aa..d5dcfb4 100644
--- a/cobbler/snippets/partition_disks
+++ b/cobbler/snippets/partition_disks
@@ -1,5 +1,5 @@
-#set hostname=$getVar('$hostname',None)
-#set partition = $getVar('$partition', None)
+#set hostname=$getVar('hostname',None)
+#set partition = $getVar('partition', None)
 
 #if $hostname == None
 #set $vgname = "VolGroup00"
@@ -8,22 +8,51 @@
 #end if
 
 set \$(list-harddrives)
-let numd=\$#/2
-d1=\$1
-d2=\$3
+let disk_nums=\$#/2
+let disk_offset=0
+while [ \$disk_offset -lt \$disk_nums ];
+do
+disks[disk_offset]=\$1
+let disk_offset=\$disk_offset+1
+shift 2
+done
 
-echo "clearpart --all --initlabel" > /tmp/part-include
-echo "part /boot --fstype ext3 --size=100 --ondisk=\$d1  --asprimary" >> /tmp/part-include
-echo "part swap --recommended --ondisk=\$d1" >> /tmp/part-include
-echo "part pv.01 --size=1 --grow --ondisk=\$d1" >> /tmp/part-include
-# if [ "$numd" == "2" ]
-#     echo "part pv.02 --size=1 --glow --ondisk=\$d2" >> /tmp/part-include
-#     echo "volgroup $vgname pv.01 pv.02" >> /tmp/part-include
-# else
-    echo "volgroup $vgname pv.01" >> /tmp/part-include
-# fi
+echo "" > /tmp/part-include
+#if $getVar('partitions_only','') != ""
+echo "ignoredisk --only-use=$partitions_only" >> /tmp/part-include
+#end if
+echo "clearpart --all --initlabel" >> /tmp/part-include
 
-echo "logvol / --fstype ext3 --vgname=$vgname --size=1 --grow --percent=30 --name=rootvol" >> /tmp/part-include
+echo "part /boot --fstype ext3 --size=100 --ondisk=\${disks[0]}  --asprimary" >> /tmp/part-include
+echo "part swap --recommended --ondisk=\${disks[0]}" >> /tmp/part-include
+
+vggroup=''
+let disk_offset=0
+while [ \$disk_offset -lt \$disk_nums ];
+do
+let found_partition=0
+#if $getVar('partitions_only','') != ""
+    #for $partition_only in $partitions_only.split(',')
+if [[ "\${disks[\$disk_offset]}" =~ "$partition_only" ]]; then
+    let found_partition=1
+fi
+    #end for
+#else
+let found_partition=1
+#end if
+
+if [ \$found_partition -gt 0 ]; then
+    let pv_id=\$disk_offset+1
+    partname="pv.0\$pv_id"
+    echo "part \$partname --size=1 --grow --ondisk=\${disks[\$disk_offset]}" >> /tmp/part-include
+    vggroup="\$vggroup \$partname"
+fi
+let disk_offset=\$disk_offset+1;
+done
+
+echo "volgroup $vgname \$vggroup" >> /tmp/part-include
+
+echo "logvol / --fstype ext3 --vgname=$vgname --size=1 --grow --name=rootvol" >> /tmp/part-include
 
 #if $partition != None
     #set vol_sizes = [part.strip() for part in $partition.split(';') if part.strip()]
diff --git a/cobbler/snippets/rsyslogconf b/cobbler/snippets/rsyslogconf
index 6de661d..fcbe2e5 100644
--- a/cobbler/snippets/rsyslogconf
+++ b/cobbler/snippets/rsyslogconf
@@ -23,7 +23,8 @@
 # Provides TCP syslog reception
 \\$ModLoad imtcp
 \\$InputTCPServerRun 514
-
+#set system_name = $getVar('system_name','')
+\\$LocalHostName $system_name
 
 #### GLOBAL DIRECTIVES ####