Hello
I'm trying to solve
my disks detection problem. I've found a way to do which is using
python
The problem is that
I encounter a import error. It seems that python is not able to find the
modules.
Below is my
%pre section. Note that it does not work with %pre --interpreter or with a
#!/usr/bin/python
Can somebody help me
?
Thanks
-------- % pre
Section ------
%pre
--interpreter=/usr/bin/python
import
commands
import os
import string
import sys
import re
import os
import string
import sys
import re
# Configuration:
size are in Mb
root_size =
512
boot_size = 100
tmp_size = 750
home_size = 256
var_size = 512
opt_size = 128
usr_size = 1024 * 3
srv_size = 128
local_size = 128
ram_swap_ratio = 1.5
# Don't change anything below this line#
boot_size = 100
tmp_size = 750
home_size = 256
var_size = 512
opt_size = 128
usr_size = 1024 * 3
srv_size = 128
local_size = 128
ram_swap_ratio = 1.5
# Don't change anything below this line#
script_name =
sys.argv[0]
output = commands.getoutput('fdisk -l')
pattern = "sda"
matchobj = re.search(pattern, output)
if matchobj:
scsi = "yes"
else:
scsi = "no"
pattern = "sdb"
matchobj = re.search(pattern, output)
if matchobj:
scsi2 = "yes"
else:
scsi2 = "no"
matchobj = re.search(pattern, output)
if matchobj:
scsi2 = "yes"
else:
scsi2 = "no"
pattern = "hda"
matchobj = re.search(pattern, output)
if matchobj:
ide = "yes"
else:
ide = "no"
matchobj = re.search(pattern, output)
if matchobj:
ide = "yes"
else:
ide = "no"
pattern = "hdb"
matchobj = re.search(pattern, output)
if matchobj:
ide2 = "yes"
else:
ide2 = "no"
if matchobj:
ide2 = "yes"
else:
ide2 = "no"
if scsi == "yes":
drive1 = "sda"
drive1_size = commands.getoutput('fdisk -l').strip()
pattern = "sda: (\d+)"
matchobj = re.search(pattern, drive1_size)
if matchobj:
drive1_size = matchobj.group(1)
if scsi2 == "yes":
drive2 = "sdb"
elif ide == "yes":
drive2 = "hda"
drive1 = "sda"
drive1_size = commands.getoutput('fdisk -l').strip()
pattern = "sda: (\d+)"
matchobj = re.search(pattern, drive1_size)
if matchobj:
drive1_size = matchobj.group(1)
if scsi2 == "yes":
drive2 = "sdb"
elif ide == "yes":
drive2 = "hda"
if scsi == "no":
if ide == "yes":
drive1 = "hda"
drive1_size = commands.getoutput('fdisk -l').strip()
pattern = "hda: (\d+)"
matchobj = re.search(pattern, drive1_size)
if ide == "yes":
drive1 = "hda"
drive1_size = commands.getoutput('fdisk -l').strip()
pattern = "hda: (\d+)"
matchobj = re.search(pattern, drive1_size)
if
matchobj:
drive1_size = matchobj.group(1)
drive1_size = matchobj.group(1)
if ide2 == "yes":
drive2 = "hdb"
drive2 = "hdb"
drive1_size = float(drive1_size)
drive_size_m = int(drive1_size) * 1024
output = commands.getoutput('cat /proc/meminfo').strip()
pattern = "MemTotal:(\s+)(\d+)"
pattern = "MemTotal:(\s+)(\d+)"
matchobj = re.search(pattern, output)
if matchobj:
mem_size = matchobj.group(2)
mem_size = float(mem_size)/1024
swap_size = int(mem_size * ram_swap_ratio)
if matchobj:
mem_size = matchobj.group(2)
mem_size = float(mem_size)/1024
swap_size = int(mem_size * ram_swap_ratio)
f = open('/tmp/part-include', 'w')
f.write("""# Drive partitioning information determined from %s
clearpart --drives=%s --initlabel
part /boot --fstype ext3 --size=%s -- --asprimary
clearpart --drives=%s --initlabel
part /boot --fstype ext3 --size=%s -- --asprimary
part pv.01 --size 100 --grow -->volgroup vgfs pv.01
logvol / --vgname=vgfs --size=%s --name=lvroot --fstype ext3
logvol swap --vgname=vgfs --size=%s --name=lvswap --fstype=swap
logvol /tmp --vgname=vgfs --size=%s --name=lvtmp --fstype=ext3
logvol /home --vgname=vgfs --size=%s --name=lvhome --fstype=ext3
logvol /var --vgname=vgfs --size=%s --name=lvvar --fstype=ext3
logvol /opt --vgname=vgfs --size=%s --name=lvopt --fstype=ext3
logvol /srv --vgname=vgfs --size=%s --name=lvsrv --fstype=ext3
logvol /usr --vgname=vgfs --size=%s --name=lvusr --fstype=ext3
logvol /usr/local --vgname=vgfs --size=%s --name=lvlocal --fstype=ext3
""" %(script_name, drive1, boot_size, drive1, drive1, root_size, swap_size, tmp_
size, home_size, var_size, opt_size, srv_size, usr_size, local_size) )
logvol / --vgname=vgfs --size=%s --name=lvroot --fstype ext3
logvol swap --vgname=vgfs --size=%s --name=lvswap --fstype=swap
logvol /tmp --vgname=vgfs --size=%s --name=lvtmp --fstype=ext3
logvol /home --vgname=vgfs --size=%s --name=lvhome --fstype=ext3
logvol /var --vgname=vgfs --size=%s --name=lvvar --fstype=ext3
logvol /opt --vgname=vgfs --size=%s --name=lvopt --fstype=ext3
logvol /srv --vgname=vgfs --size=%s --name=lvsrv --fstype=ext3
logvol /usr --vgname=vgfs --size=%s --name=lvusr --fstype=ext3
logvol /usr/local --vgname=vgfs --size=%s --name=lvlocal --fstype=ext3
""" %(script_name, drive1, boot_size, drive1, drive1, root_size, swap_size, tmp_
size, home_size, var_size, opt_size, srv_size, usr_size, local_size) )
f.close()
--
Kennedy van Dam Eric
Unix/Storage Team
Phone: +32 (0)2 529 3375