<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2914" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=757032617-19012007><FONT face=Arial 
color=#0000ff size=2>Ouch, that's a lot of coding for something that could have 
been found in the list archives.  Here is what I use:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=757032617-19012007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=757032617-19012007><FONT face=Arial 
color=#0000ff size=2># Determine how many drives we have<BR>set 
$(list-harddrives)<BR>let numd=$#/2<BR>d1=$1<BR>d2=$3</FONT></SPAN></DIV>
<DIV><SPAN class=757032617-19012007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=757032617-19012007><FONT face=Arial color=#0000ff size=2># 
<SPAN class=757032617-19012007><FONT face=Arial color=#0000ff size=2>This will 
give you all the drives in your system, and their 
sizes.</FONT></SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=757032617-19012007><FONT face=Arial color=#0000ff size=2><SPAN 
class=757032617-19012007></SPAN></FONT></SPAN> </DIV>
<DIV><SPAN class=757032617-19012007><FONT face=Arial color=#0000ff size=2>if [ 
$numd -ge 2 ] ; then<BR>cat << EOF >> /tmp/partinfo<BR>part pv.01 
--size=1 --grow --fstype=ext3 --ondisk=$d1<BR>volgroup volgrp01 pv.01<BR>part 
pv.02 --size=1 --grow --fstype=ext3 --ondisk=$d2<BR>volgroup volgrp02 
pv.02<BR>WHATEVER YOU WANT FOR PARTITIONING HERE</FONT></SPAN></DIV>
<DIV><SPAN class=757032617-19012007><FONT face=Arial color=#0000ff size=2>part 
swap --recommended --ondisk=$d1<BR>EOF</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=757032617-19012007><FONT face=Arial color=#0000ff 
size=2>Chip</DIV>
<DIV dir=ltr align=left><BR></DIV></FONT></SPAN>
<DIV dir=ltr align=left><SPAN class=757032617-19012007><FONT face=Arial 
color=#0000ff size=2> </DIV></FONT></SPAN><FONT face=Arial color=#0000ff 
size=2></FONT><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> kickstart-list-bounces@redhat.com 
[mailto:kickstart-list-bounces@redhat.com] <B>On Behalf Of </B>KENNEDY VAN DAM 
Eric<BR><B>Sent:</B> Friday, January 19, 2007 4:23 AM<BR><B>To:</B> Discussion 
list about Kickstart<BR><B>Subject:</B> python in %pre<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial 
size=2>Hello</FONT></SPAN></DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial size=2>I'm trying to solve 
my disks detection problem. I've found a way to do which is using 
python</FONT></SPAN></DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial size=2>The problem is that 
I encounter a import error. It seems that python is not able to find the 
modules.</FONT></SPAN></DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial size=2>Below is my 
%pre section. Note that it does not work with %pre --interpreter or with a 
#!/usr/bin/python</FONT></SPAN></DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial size=2>Can somebody help me 
?</FONT></SPAN></DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial 
size=2>Thanks</FONT></SPAN></DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial size=2>-------- % pre 
Section ------</FONT></SPAN></DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial size=2>%pre 
--interpreter=/usr/bin/python</FONT></SPAN></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial size=2>import 
commands<BR>import os<BR>import string<BR>import sys<BR>import 
re</FONT></SPAN></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial size=2># Configuration: 
size are in Mb</FONT></SPAN></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial size=2>root_size = 
512<BR>boot_size = 100<BR>tmp_size = 750<BR>home_size = 256<BR>var_size = 
512<BR>opt_size = 128<BR>usr_size = 1024 * 3<BR>srv_size = 128<BR>local_size = 
128<BR>ram_swap_ratio = 1.5<BR># Don't change anything below this 
line#</FONT></SPAN></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><SPAN class=858151512-19012007><FONT face=Arial size=2>script_name = 
sys.argv[0]</FONT></SPAN></DIV><SPAN class=858151512-19012007><FONT face=Arial 
size=2>
<DIV><BR>output = commands.getoutput('fdisk -l')<BR>pattern = "sda"<BR>matchobj 
= re.search(pattern, output)<BR>if matchobj:<BR>   scsi = 
"yes"<BR>else:<BR>   scsi = "no"</DIV>
<DIV> </DIV>
<DIV>pattern = "sdb"<BR>matchobj = re.search(pattern, output)<BR>if 
matchobj:<BR>   scsi2 = "yes"<BR>else:<BR>   scsi2 = 
"no"</DIV>
<DIV> </DIV>
<DIV>pattern = "hda"<BR>matchobj = re.search(pattern, output)<BR>if 
matchobj:<BR>   ide = "yes"<BR>else:<BR>   ide = "no"</DIV>
<DIV> </DIV>
<DIV>pattern = "hdb"</DIV>
<DIV>matchobj = re.search(pattern, output)<BR>if matchobj:<BR>   ide2 
= "yes"<BR>else:<BR>   ide2 = "no"</DIV>
<DIV> </DIV>
<DIV>if scsi == "yes":<BR>   drive1 = "sda"<BR>   
drive1_size = commands.getoutput('fdisk -l').strip()<BR>   pattern = 
"sda: (\d+)"<BR>   matchobj = re.search(pattern, 
drive1_size)<BR>   if matchobj:<BR>      
drive1_size = matchobj.group(1)<BR>   if scsi2 == 
"yes":<BR>      drive2 = "sdb"<BR>   elif ide 
== "yes":<BR>      drive2 = "hda"</DIV>
<DIV> </DIV>
<DIV>if scsi == "no":<BR>   if ide == 
"yes":<BR>      drive1 = 
"hda"<BR>      drive1_size = commands.getoutput('fdisk 
-l').strip()<BR>      pattern = "hda: 
(\d+)"<BR>      matchobj = re.search(pattern, 
drive1_size)</DIV>
<DIV>      if 
matchobj:<BR>         drive1_size = 
matchobj.group(1)</DIV>
<DIV> </DIV>
<DIV>if ide2 == "yes":<BR>   drive2 = "hdb"</DIV>
<DIV> </DIV>
<DIV>drive1_size = float(drive1_size)</DIV>
<DIV> </DIV>
<DIV>drive_size_m = int(drive1_size) * 1024</DIV>
<DIV> </DIV>
<DIV>output = commands.getoutput('cat /proc/meminfo').strip()<BR>pattern = 
"MemTotal:(\s+)(\d+)"</DIV>
<DIV> </DIV>
<DIV>matchobj = re.search(pattern, output)<BR>if matchobj:<BR>   
mem_size = matchobj.group(2)<BR>mem_size = float(mem_size)/1024<BR>swap_size = 
int(mem_size * ram_swap_ratio)</DIV>
<DIV> </DIV>
<DIV>f = open('/tmp/part-include', 'w')</DIV>
<DIV> </DIV>
<DIV>f.write("""# Drive partitioning information determined from %s<BR>clearpart 
--drives=%s --initlabel<BR>part /boot --fstype ext3 --size=%s --ondisk=%s 
--asprimary</DIV>
<DIV>part pv.01 --size 100 --grow --ondisk=%s<BR>volgroup vgfs pv.01<BR>logvol / 
--vgname=vgfs --size=%s --name=lvroot --fstype ext3<BR>logvol swap --vgname=vgfs 
--size=%s --name=lvswap --fstype=swap<BR>logvol /tmp --vgname=vgfs --size=%s 
--name=lvtmp --fstype=ext3<BR>logvol /home --vgname=vgfs --size=%s --name=lvhome 
--fstype=ext3<BR>logvol /var --vgname=vgfs --size=%s --name=lvvar 
--fstype=ext3<BR>logvol /opt --vgname=vgfs --size=%s --name=lvopt 
--fstype=ext3<BR>logvol /srv --vgname=vgfs --size=%s --name=lvsrv 
--fstype=ext3<BR>logvol /usr --vgname=vgfs --size=%s --name=lvusr 
--fstype=ext3<BR>logvol /usr/local --vgname=vgfs --size=%s --name=lvlocal 
--fstype=ext3<BR>""" %(script_name, drive1, boot_size, drive1, drive1, 
root_size, swap_size, tmp_<BR>size, home_size, var_size, opt_size, srv_size, 
usr_size, local_size) )</DIV>
<DIV> </DIV>
<DIV>f.close()<BR></FONT></SPAN></DIV>
<DIV> </DIV>
<DIV align=left><FONT face=Arial size=2>-- </FONT></DIV>
<DIV align=left><FONT face=Arial size=2>Kennedy van Dam Eric</FONT><FONT 
face=Arial size=2></DIV>
<DIV align=left>Unix/Storage Team</DIV>
<DIV align=left>Phone: +32 (0)2 529 3375</DIV>
<DIV align=left>Mail: <A 
href="mailto:eric.kennedyvandam@rvponp.fgov.be">eric.kennedyvandam@rvponp.fgov.be</A></FONT></DIV>
<DIV align=left><FONT face=Arial size=2></FONT> </DIV>
<DIV> </DIV></BODY></HTML>