[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

some help needed with python script to detect number of drives in kickstart file



Hi all

I would like to put together a kickstart script which will allow me to install CentOS on many different platforms, regardless of the number & types of drive installed. If the system has 3 drives, I'd like to setup RAID 1 + 1 hot spare, for example. If it has 4 HDD's, then I'd like to setup RAID10, and for 10 HDD's, RAID 50.

So, after trying many different options, I still can't get it to work, but recently found the following website, http://evuraan.blogspot.com/2005/02/auto-finding-your-hard-drives-for.html which basically outlines a way to determine how many drives are in the machine, but it's very basic.


%pre --interpreter /usr/bin/python
import os, sys
sys.path.append('/usr/lib/anaconda')
import isys

# get a sorted list of drives
drives = isys.hardDriveDict().keys()
drives.sort()

# write the include file to /tmp/kspart, drives[0] is the first drive,
# drives[1] is the second, etc.  To get the filet to be used, put
# '%include /tmp/partitions' in your kickstart configuration.
print "Writing partition details"
f = open("/tmp/partitions", "w")
f.write("part /boot --size 400 --ondisk %s\n" % drives[0])
f.write("part / --size 6144 --ondisk %s\n" % drives[0])
f.write("part swap --size 2048 --ondisk %s\n" % drives[0])
f.write("part /var --size 3072 --ondisk %s\n" % drives[0])
f.write("part /home --size 2048 --ondisk %s\n" % drives[0])
f.write("part /tmp --size 4096 --ondisk %s\n" % drives[0])
f.write("part /data --size 6144 --ondisk %s\n" % drives[0])

f.close()





So, with this, I'd like to do different things, according to the number of drives, with an if/elseif loop (is there a better way?)

This is what I've tried:

if [ drives[]  == "5" ] ; then
f = open("/tmp/num_drives","w")
f.write("5")
f.close()

elif [ drives[]  == "4" ] ; then
f = open("/tmp/num_drives","w")
f.write("4")
f.close()

elif [ drives[] == "3" ] ; then
f = open("/tmp/num_drives","w")
f.write("3")
f.close()

<--snip-->

but it fails. Can someone please help with this?


--

Kind Regards
Rudi Ahlers
CEO, SoftDux

Web:   http://www.SoftDux.com
Check out my technical blog, http://blog.softdux.com for Linux or other technical stuff, or visit http://www.WebHostingTalk.co.za for Web Hosting stuff


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]