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

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

Rudi Ahlers wrote:
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.

This script is a bit overkill. From cobbler's snippets directory, I have this for default drive selection code. You will have do a bit more get RAID auto-configured, but that is left as an exercise for the reader.

%include /tmp/partinfo

# Determine how many drives we have
set \$(list-harddrives)
let numd=\$#/2

cat << EOF > /tmp/partinfo
part / --fstype ext3 --size=1024 --grow --ondisk=\$d1 --asprimary
part swap --size=1024 --ondisk=\$d1 --asprimary

%pre --interpreter /usr/bin/python
import os, sys
import isys

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

# 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])


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")

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

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


but it fails. Can someone please help with this?

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