RE: python in %pre

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

 



Ouch, that's a lot of coding for something that could have been found in the list archives.  Here is what I use:
 
# Determine how many drives we have
set $(list-harddrives)
let numd=$#/2
d1=$1
d2=$3
 
# This will give you all the drives in your system, and their sizes.
 
if [ $numd -ge 2 ] ; then
cat << EOF >> /tmp/partinfo
part pv.01 --size=1 --grow --fstype=ext3 -->volgroup volgrp01 pv.01
part pv.02 --size=1 --grow --fstype=ext3 -->volgroup volgrp02 pv.02
WHATEVER YOU WANT FOR PARTITIONING HERE
part swap --recommended -->EOF
 
Chip

 


From: kickstart-list-bounces@xxxxxxxxxx [mailto:kickstart-list-bounces@xxxxxxxxxx] On Behalf Of KENNEDY VAN DAM Eric
Sent: Friday, January 19, 2007 4:23 AM
To: Discussion list about Kickstart
Subject: python in %pre

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
 
# 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#
 
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"
 
pattern = "hda"
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 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"
 
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 matchobj:
         drive1_size = matchobj.group(1)
 
if ide2 == "yes":
   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+)"
 
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)
 
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
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) )
 
f.close()
 
--
Kennedy van Dam Eric
Unix/Storage Team
Phone: +32 (0)2 529 3375
Mail: eric.kennedyvandam@xxxxxxxxxxxxxx
 
 

[Index of Archives]     [Red Hat General]     [CentOS Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux