How To Build Linux Driver Into Booting img for PXE booting

How To Build Linux Driver Into Booting img for PXE booting

Written by: Libo.Ma
Created on July 28,2011

1. mkdir /tmp/testkernel/ # create testkernel package dir
2. gzip -cd /pxeist/tftpboot_centos54/initrd.img |cpio -ivd
3. cd modules; gzip -dc modules.cgz | cpio -ivd
4. cp /var/www/html/drivers/tg3.ko ./2.6.18-164.el5/x86_64 # Copy driver to kernel dir
5. modinfo -F alias 2.6.18-164.el5/x86_64/tg3.ko | sed -e ‘s/^/alias /’ -e ‘s/$/ tg3/’ >>modules.alias
6. find 2.6.18-164.el5 | cpio -o -H crc | gzip -9 > modules.cgz; rm -rf 2.6.18-164.el5
7. cd ..;find . | cpio -o -H newc | gzip -9 > /tmp/initrd.img
8. cd /pxeist/tftpboot_centos54/;
mv initrd.img bak_initrd.img
9. cp /tmp/initrd.img /pxeist/tftpboot_centos54/
10. OK

reference scripts:
#!/bin/sh

#This scripts is used to making kernel images for PXE BOOTING of linux
#installation.
#Created by Libo.ma @ July 26,2011
#
#

if [ ! -f $1 ]
then
echo “Usage: `basename $0` driver.ko”
exit 1
fi

FILE=$1

TKERNEL=/pxeist/tftpboot_centos54/testkernel
MODULES=/pxeist/tftpboot_centos54/testkernel/modules
FILE_NAME=$(basename $FILE)
FILE_ALIAS=${FILE_NAME%.*}
if [ -f $FILE ]
then
cp $FILE /var/www/html/drivers/2.6.18-164.el5/x86_64/ -rf
sed -i “/$FILE_ALIAS\$/d” $MODULES/modules.alias
modinfo -F alias 2.6.18-164.el5/x86_64/$FILE_NAME | sed -e “s/^/alias /” -e “s/$/ $FILE_ALIAS/” >> $MODULES/modules.alias
echo “Packag driver into modules.cgz”…
find 2.6.18-164.el5 | cpio -o -H crc | gzip -9 > $MODULES/modules.cgz
cd $TKERNEL
echo “Making kernel initrd.img…”
if find . | cpio -o -H newc | gzip -9 > /tmp/initrd.img;
then
echo “/tmp/initrd.img making successfully.”
else
echo “Failure.”
fi
fi

Refernece links:
http://lingho.com/mediawiki/index.php/Adding_driver_to_RHEL_PXE_initrd_file#Step_3_-_Add_or_replace_the_driver

Kickstart options notes

refer to :Fedora Kickstart Configration
Here is my Kickstart config file for general Centos Installation.

# Kickstart file automatically generated by anaconda.

install
url --url http://10.130.142.155/mirrors/centos5.4
lang en_US.UTF-8
keyboard us
network --device eth0 --bootproto static --ip 10.130.142.13 --netmask 255.255.255.0 --gateway 10.130.142.1 --nameserver 10.130.130.10,202.106.0.20 --hostname VIA-02
rootpw --iscrypted $1$Jd5lGnyJ$jcziaYiiCTqf4uWi8h4lc.
firewall --enabled --port=22:tcp
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Asia/Chongqing
bootloader --location=mbr --driveorder=sda
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --linux --drives=sda
part /boot --fstype ext3 --size=100 --ondisk=sda
part pv.7 --size=0 --grow --ondisk=sda
volgroup VolGroup00 --pesize=32768 pv.7
logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=40000
logvol /images --fstype ext3 --name=images.disk --vgname=VolGroup00 --size=60000
logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=1000 --grow --maxsize=5856

%packages
@admin-tools
@base
@core
@dns-server
@development-libs
@development-tools
@editors
@ftp-server
@network-server
@server-cfg
@text-internet
@xen
@web-server
keyutils
kexec-tools
iscsi-initiator-utils
trousers
bridge-utils
fipscheck
device-mapper-multipath
perl-XML-SAX
perl-XML-Twig
perl-XML-Dumper
perl-TimeDate
perl-libxml-perl
perl-Convert-ASN1
libstdc++44-devel
perl-XML-NamespaceSupport
perl-DateManip
perl-Crypt-SSLeay
perl-Mozilla-LDAP
perl-LDAP
perl-XML-Grove
python-imaging
perl-Archive-Zip
gcc44-c++
gcc44-gfortran
imake
gcc-objc
gcc-gnat
libgfortran44
gcc44
tftp
Virtualization-en-US
-gnome-applet-vm
%end

%pre
%end
%post
%end
reboot

significant Options explaination:

  • clearpart –all –drives=sda

    –all
    Erases all partitions from the system.

    –initlabel
    Initializes the disk label to the default for your architecture (for example msdos for x86 and gpt for Itanium). It is useful so that the installation program does not ask if it should initialize the disk label if installing to a brand new hard drive.

    –linux
    Erases all Linux partitions.
    –none (default)
    Do not remove any partitions.

  • firewall

    This option corresponds to the Firewall Configuration screen in the installation program:
    firewall –enabled|–disabled [options]

    –trust=
    Listing a device here, such as eth0, allows all traffic coming from that device to go through the firewall. To list more than one device, use –trust eth0 –trust eth1. Do NOT use a comma-separated format such as –trust eth0, eth1.

    Replace with none or more of the following to allow the specified services through the firewall.
    –ssh – The ssh option is enabled by default, regardless of the presence of this flag.
    –smtp
    –http
    –ftp
    –port=
    You can specify that ports be allowed through the firewall using the port:protocol format. You can also specify ports numerically. Multiple ports can be combined into one option as long as they are separeted by commas. For example:
    firewall –port=imap:tcp,1234:ucp,47
    –service=
    This option provides a higher-level way to allow services through the firewall. Some services (like cups, avahi, etc.) require multiple ports to be open in order for the service to work. You could specify each individual service with the –port option, or specify –service= and open them all at once. Valid options are anything recognized by the lokkit program in the system-config-firewall-base package

  • graphical

    Perform the kickstart installation in graphical mode. This is the default.

  • install

    Tells the system to install a fresh system rather than upgrade an existing system. This is the default mode. For installation, you must specify the type of installation from one of cdrom, harddrive, nfs, or url (for ftp or http installations). The install command and the installation method command must be on separate lines.
    cdrom
    Install from the first CD-ROM/DVD drive on the system.
    harddrive
    Install from a directory of ISO images on a local drive, which must be either vfat or ext2. In addition to this directory, you must also provide the install.img in some way. You can either do this by booting off the boot.iso or by creating an images/ directory in the same directory as the ISO images and placing install.img in there.
    –biospart=
    BIOS partition to install from (such as 82p2).
    –partition=
    Partition to install from (such as, sdb2).
    –dir=
    Directory containing both the ISO images and the images/install.img. For example:
    harddrive –partition=hdb2 –dir=/tmp/install-tree
    nfs
    Install from the NFS server specified. This can either be an exploded installation tree or a directory of ISO images. In the latter case, the install.img must also be provided subject to the same rules as with the harddrive installation method described above.
    –server=
    Server from which to install (hostname or IP).
    –dir=
    Directory containing the Packages/ directory of the installation tree. If doing an ISO install, this directory must also contain images/install.img.
    –opts=
    Mount options to use for mounting the NFS export. Any options that can be specified in /etc/fstab for an NFS mount are allowed. The options are listed in the nfs(5) man page. Multiple options are separated with a comma.
    For example:
    nfs –server=nfsserver.example.com –dir=/tmp/install-tree
    url
    Install from an installation tree on a remote server via FTP or HTTP.
    –url=
    The URL to install from.
    –proxy=[protocol://][username[:password]@]host[:port]
    Specify an HTTP/HTTPS/FTP proxy to use while performing the install. The various parts of the argument act like you would expect.
    –noverifyssl
    For a tree on a HTTPS server do not check the server’s certificate with what well-known CA validate and do not check the server’s hostname matches the certificate’s domain name.

  • logvol

    Create a logical volume for Logical Volume Management (LVM).
    logvol –vgname= –size= –name=

    –noformat
    Use an existing logical volume and do not format it.
    –useexisting
    Use an existing logical volume and reformat it.
    –fstype=
    Sets the file system type for the logical volume. Valid values include ext4, ext3, ext2, btrfs, swap, and vfat. Other filesystems may be valid depending on command line arguments passed to anaconda to enable other filesystems. Btrfs is a experimental filesystem. Do take regular backups if you are using it.
    –fsoptions=
    Specifies a free form string of options to be used when mounting the filesystem. This string will be copied into the /etc/fstab file of the installed system and should be enclosed in quotes.
    –grow
    Tells the logical volume to grow to fill available space (if any), or up to the maximum size setting. Note that –grow is not supported for logical volumes containing a RAID volume on top of them.
    –maxsize=
    The maximum size in megabytes when the logical volume is set to grow. Specify an integer value here, and do not append the number with MB.
    –recommended
    Determine the size of the logical volume automatically.
    –percent
    Specify the size of the logical volume as a percentage of available space in the volume group. Without the above –grow option, this may not work.
    –encrypted
    Specify that this logical volume should be encrypted.
    –passphrase=
    Specify the passphrase to use when encrypting this logical volume. Without the above –encrypted option, this option does nothing. If no passphrase is specified, the default system-wide one is used, or the installer will stop and prompt if there is no default.
    –escrowcert=
    Load an X.509 certificate from . Store the data encryption key of this logical volume, encrypted using the certificate, as a file in /root. Only relevant if –encrypted is specified as well.
    –backuppassphrase
    Only relevant if –escrowcert is specified as well. In addition to storing the data encryption key, generate a random passphrase and add it to this logical volume. Then store the passphrase, encrypted using the certificate specified by –escrowcert, as a file in /root. If more than one LUKS volume uses –backuppassphrase, the same passphrase will be used for all such volumes.
    Create the partition first, create the logical volume group, and then create the logical volume. For example:
    part pv.01 –size 3000
    volgroup myvg pv.01
    logvol / –vgname=myvg –size=2000 –name=rootvol

  • network

    Configures network information for target system and activates network devices in installer environment. Device of the first network command is activated if network is required, e.g. in case of network installation or using vnc. Activation of the device can be also explicitly required by –activate option. If the device has already been activated to get kickstart file (e.g. using configuration provided with boot options or entered in loader UI) it is re-activated with configuration from kickstart file.
    In F15, the device of first network command is activated also in case of non-network installs, and device is not re-activated using kickstart configuration.
    Additional devices configured in kickstart with network command can be activated in installer using –activate option (since F16).
    –bootproto=[dhcp|bootp|static|ibft]
    The default setting is dhcp. bootp and dhcp are treated the same.
    The DHCP method uses a DHCP server system to obtain its networking configuration. As you might guess, the BOOTP method is similar, requiring a BOOTP server to supply the networking configuration.
    The static method requires that you enter all the required networking information in the kickstart file. As the name implies, this information is static and will be used during and after the installation. The line for static networking is more complex, as you must include all network configuration information on one line. You must specify the IP address, netmask, gateway, and nameserver. For example: (the \ indicates that it is all one line):
    network –bootproto=static –ip=10.0.2.15 \
    –netmask=255.255.255.0 –gateway=10.0.2.254 \
    –nameserver=10.0.2.1
    If you use the static method, be aware of the following restriction:
    All static networking configuration information must be specified on one line; you cannot wrap lines using a backslash, for example.
    ibft setting is for reading the configuration from iBFT table. It was added in F16.
    –device=
    Specifies device to be configured and/or activated with the network command. The device can be specified in the same ways as ksdevice boot option. For example:
    network –bootproto=dhcp –device=eth0
    For the first network command, if the option is not specified it defaults to 1) ksdevice boot option, 2) device activated to fetch kickstart, or 3) selection dialog in UI. For following network commands, the –device option is required.
    –ip=
    IP address for the interface.
    –ipv6=
    IPv6 address for the interface. This can be the static address, “auto” for address assignment based on automatic neighbor discovery, or “dhcp” to use the DHCPv6 protocol.
    –gateway=
    Default gateway, as an IPv4 or IPv6 address.
    –nodefroute
    Prevents grabbing of the default route by the device. It can be useful when activating additional devices in installer using –activate option. Since F16.
    –nameserver=
    Primary nameserver, as an IP address. Multiple nameservers must be comma separated.
    –nodns
    Do not configure any DNS server.
    –netmask=
    Netmask for the installed system.
    –hostname=
    Hostname for the installed system.
    –ethtool=
    Specifies additional low-level settings for the network device which will be passed to the ethtool program.
    –essid=
    The network ID for wireless networks.
    –wepkey=
    The encryption key for wireless networks.
    –onboot=
    Whether or not to enable the device a boot time.
    –dhcpclass=
    The DHCP class.
    –mtu=
    The MTU of the device.
    –noipv4
    Disable IPv4 on this device.
    –noipv6
    Disable IPv6 on this device

  • selinux

    Sets the state of SELinux on the installed system. SELinux defaults to enforcing in anaconda.
    selinux [–disabled|–enforcing|–permissive]
    –disabled
    If this is present, SELinux is disabled.
    –enforcing
    If this is present, SELinux is set to enforcing mode.
    –permissive
    If this is present, SELinux is enabled, but only logs things that would be denied in enforcing mode

  • skipx
    If present, X is not configured on the installed system.
  • volgroup

    Use to create a Logical Volume Management (LVM) group.
    volgroup

    Name given to the volume group. The (which denotes that multiple partitions can be listed) lists the identifiers to add to the volume group.
    –noformat
    Use an existing volume group and do not format it.
    –useexisting
    Use an existing volume group and reformat it.
    –pesize=
    Set the size of the physical extents.
    Create the partition first, create the logical volume group, and then create the logical volume. For example:
    part pv.01 –size 3000
    volgroup myvg pv.01
    logvol / –vgname=myvg –size=2000 –name=rootvol

  • %packages

    refer to the repodata/*comps.xml file on the first CD-ROM for a list of groups.
    syntax:
    %packages
    @…
    @..
    @..
    %end

    PS: This may be handy if the kickstart file is used as a template and pulls in various other files with the %include mechanism.

  • Pre-installation Script

    This section must be at the end of the kickstart file (after the commands) and must start with the %pre command. You can access the network in the %pre section; however, name service has not been configured at this point, so only IP addresses will work.
    Preinstallation scripts are required to be closed with %end.

  • <2h2>post-install

    Examples

    Run a script named runme from an NFS share:
    %post
    mkdir /mnt/temp
    mount 10.10.0.2:/usr/new-machines /mnt/temp
    open -s -w — /mnt/temp/runme
    umount /mnt/temp
    %end
    Copy the file /etc/resolv.conf to the file system that was just installed:
    %post –nochroot
    cp /etc/resolv.conf /mnt/sysimage/etc/resolv.conf
    %end

  • Creating a Kickstart Boot CD-ROM
    Installation Boot CD-ROM section in the Red Hat Enterprise Linux Installation Guide for instruction on creating a boot CD-ROM; however, before making the file.iso image file, copy the ks.cfg kickstart file to the isolinux/ directory.

LVM Using snapot to backup data–from google searching..

This is a Daily script

#!/bin/bash
DIR=/root/backup
BACKUP_CMD=backup-lv.sh

VG=/dev/vg1 #whichever folder your xen files located at)
LV[0]=xen-1 # (name of diff, xen machines/guests)
LV[1]=xen-2
LV[2]=xen2-data #xen2 is a web server with large amount of data
LV[3]=xen-3

cd $DIR
COUNT=0
CAT_STR=""
while [ $COUNT -lt ${#LV[@]} ]
do
./$BACKUP_CMD $VG/${LV[$COUNT]} &> last-backup-${LV[$COUNT]}
CAT_STR="${CAT_STR} last-backup-${LV[$COUNT]}"
MOO=$((COUNT++))
done

ls -lh /mnt/system_backups/ &> last-backup-ls
cat $CAT_STR last-backup-ls > last-backup.txt
echo "daily backup report attached" | mutt -s "$HOSTNAME daily backup report" -a last-backup.txt MyEmail@MyCompany.com

Continue reading “LVM Using snapot to backup data–from google searching..”

Unix编程艺术——Unix哲学


Unix编程艺术——Unix哲学

Unix编程艺术主要介绍了Unix系统领域中的设计和开发哲学、思想文化体系、原则与经验。此文大致摘录了Unix的哲学。

web程序员也应该看看此书,软件开发和web开发很多地方都是相通的。看完之后,我甚至觉得Unix哲学对于做人也有很大的参考价值。
模块原则 (使用简洁的接口拼合简单的部件)

计算机编程的本质就是控制复杂度

要编写复杂软件而又不至于一败涂地的唯一方法就是降低其整体复杂度——用清晰的接口把若干简单的模块组合成一个复杂的软件。如此一来,多数问题只会局限于某个局部,那么就还有希望对局部进行改进而不至牵动全身。

清晰原则 (清晰胜于技巧)

维护成本是高昂的,在写程序时,要想到你不是写给执行代码的计算机看的,而是给人——将来阅读维护源码的人,包括你自己看的。

在Unix传统中,这个建议不仅意味着代码注释。良好的Unix实践同样信奉在选择算法和实现时就应该考虑到将来的可扩展性。为了取得程序一丁点性能的提升就大幅增加技术的复杂性和晦涩性,这个买卖做不得——这不仅仅是因为复杂的代码容易滋生bug,也因为它会使日后的阅读和维护工作更加艰难。

组合原则 (设计时考虑拼接组合)

如果程序彼此之间不能有效通信,那么软件就难免会陷入复杂度的泥淖。

在输入方面,Unix传统极力提倡采用简单、文本化、面向流、设备无关的格式。在经典的Unix下,多数程序都尽可能采用简单过滤器的形式,即将一个简单的文本输入流处理为一个简单的文本流输出。

Unix程序员偏爱这种做法并不是因为它们仇视视图界面,而是因为如果程序不采用简单的文本输入输出流,它们就极难衔接。

要想让程序具有组合性,就要使程序彼此独立。在文本流这一端的程序应该尽可能不要考虑到文本流另一端的程序。

分离原则 (策略同机制分离,接口同引擎分离)

把策略同机制揉成一团有两个负面影响:一来会使策略变得死板,难以适应用户需求的改变,二来也意味着任何策略的改变都可能会动摇机制。

可以将应用程序分成可以协作的前端和后端进程,通过socket专用应用协议进行通讯。这种双端设计方法大大降低了整体复杂度,bug有望减少。

简洁原则 (设计要简洁,复杂度能低就低)

来自多方面的压力常常会让程序变得复杂(bug更多),其中一种压力就是来自技术上的虚荣心理。Unix程序员相互比的是谁能够做到”简洁而漂亮”并以此为荣。

更为常见的是,过度的复杂性往往来自于项目的需求,要避免这种状况,就需要鼓励一种软件文化,以简洁为美,人人对庞大复杂的东西群起而攻之。
吝啬原则 (除非确无它法,不要编写庞大的程序)

“大”有两重含义:体积大,复杂程度高。程序大了,维护起来就困难。由于人们对花费了大量精力才做出来的东西难以割舍,结果导致在庞大的程序中把投资浪费的注定要失败或者并非最佳的方案上。

透明原则 (设计要可见,以便审查和调试)

软件系统的透明性是指你一眼就能够看出软件是在做什么以及怎样做的。显示性是指程序带有监视和显示内部状态的功能。

设计时如果充分考虑到这些要求会给整个项目全过程都带来好处。至少,调试选项的设置应该尽量不要在事后,而应该在设计之初便考虑进去。这是考虑到程序不但应该能够展示其正确性,也应该能够把原开发者解决问题的思维模型告诉后来者。

程序如果要展示其正确性,应该使用足够简单的输入输出格式,这样才能保证很容易地检验有效输入和正确输出之间的关系是否正确。

出于充分考虑透明性和显见性的目的,还应该提倡接口简洁,以方便其他程序对它进行操作。

健壮原则 (健壮源于透明与简洁)

软件的健壮性指软件不仅能在正常情况下运行良好,而且在超出设计者设想的意外条件下也能够运行良好。

大多数软件禁不起磕碰,毛病很多,就是因为过于复杂,很难通盘考虑。如果不能够正确理解一个程序的逻辑,就不能确信其是否正确,也就不能在出错时修复它。

这也就带来了让程序健壮的方法,就是让程序的内部逻辑更易于理解。要做到这一点主要有两种方法:透明化和简洁化。

上面曾说过,软件的透明性就是指一眼就能够看出是怎么回事,即人们不需要绞尽脑汁就能够推断出所有可能的情况,那么这个程序就是简洁的。程序越简洁,越透明,也就越健壮。
表示原则 (把知识代入数据以求逻辑质朴而健壮)

数据要比程序逻辑更容易驾驭。所以如果要在复杂数据和复杂代码中选择一个,宁愿选择前者。更进一步:在设计中,应该主动将代码的复杂度转移到数据中去。

通俗原则 (接口避免标新立异)

最易用的程序就是用户需要学习新东西最少的程序,换句话说最易用的程序就是最切合用户已有知识的程序。

缄默原则 (无话可说?那就沉默)

行为良好的程序应该默默工作,绝不唠唠叨叨,碍手碍脚。沉默是金。

简洁是Unix程序的核心风格。一旦程序的输出成为另一个程序的输入,就要很容易把需要的数据挑出来。站在人的角度上来说,重要的信息不应该混杂在冗长的程序内部行为信息中。
补救原则 (出现异常时,马上退出并给出足够错误信息)

软件在发生错误时也应该与在正常操作的情况下一样,有透明的逻辑。最理想的情况当然是软件能够适应和应付非正常操作;而如果补救措施明明没有成功,却悄无声息地埋下崩溃的隐患,这就是最坏的情况了。

宽容地收,谨慎地发。就算输入的数据很不规范,一个设计良好的程序也会尽量领会其中的意义,以尽量与别的程序协作。然后要么抛出异常,要么为工作链的下一环程序输出一个严谨干净正确的数据。

经济原则 (宁花机器一分,不花程序员一秒)

随着技术的发展,开发公司和大多数用户都能得到廉价的机器,所以这一准则的合理性就显然不用多说了。

如果我们在软件开发中严格遵循这条原则的话,大多数的应用场合应该使用高级语言,如Perl,Python,Java,Php,甚至Shell——这些语言可以将程序员从自行管理内存的负担中释放出来。
生成原则 (避免手工hack,尽量编写程序去生成程序)

人类很不善于干辛苦的细节工作。因此程序中任何手工hacking都是滋生错误和延误的温床。程序规格越简单越抽象,设计者就越容易做对。
优化原则 (过早优化是万恶之源)

还不知道瓶颈所在就匆忙进行优化,这可能是唯一一个比乱加功能更加损害设计的错误。从畸形的代码到杂乱无章的数据布局,牺牲透明性和简洁性而片面追求速度、内存或者磁盘使用的后果随处可见。

先制作原型,再精雕细琢。优化之前先确保能用。”极限编程”宗师Kent Beck从另一种不同的文化将这点有效地扩展为:先求运行,再求正确,最后求快。

借助原型化找出哪些功能不必实现,有助于对性能进行优化;那些不用写的代码显然无须优化。
多样原则 (绝不相信所谓”不二法门”的断言)

Unix传统有一点很好,即从不相信任何所谓的”不二法门”。Unix奉行的是广泛采用多种语言、开放的可扩展系统和用户定制机制。
扩展原则 (设计着眼未来,未来总比预想来得快)

要为数据格式和代码留下扩展的空间,否则就会发现自己常常被原先不明智选择捆住了手脚,因为你无法既要改变它们又要维持对原来的兼容性。

设计协议或是文本格式时,应使其具有充分的自描述性以便可以扩展。要么包含进一个版本号,要么采用独立、自描述的语句、按照可以随时插入新的而不会搞乱格式读取代码的方法组织格式。
Unix哲学一言以蔽之


CentOS yum repository management tools

CentOS yum repository management tool


    —- Search

  • 1. yum list package_name (simple search)
    yum list package_name* wildcard supported.
  • 2. yum search package_name (deep search)
  • 3. To do a search for any packages that provide php, you can use the following command
    yum provider php*
    —- Group

  • 1. yum grouplist
  • 2. yum groupinstall groupname

Python-OptParser Global args operations.


def setup_cmdline_parser():
    parser = _o.OptionParser()
    parser.add_option("-l", "--live", dest="live", action="store_true",
                      default=True, help = "show the ncurses live monitoring frontend (default)")
    parser.add_option("-n", "--notlive", dest="live", action="store_false",
                      default="True", help = "write to file instead of live monitoring")
    parser.add_option("-p", "--prefix", dest="prefix",
                      default = "log", help="prefix to use for output files")
    parser.add_option("-t", "--time", dest="duration", action="store", type="int", default=10,
            help="stop logging to file after this much time has elapsed (in seconds). set to 0 to keep logging indefinitely")
    return parser


def main():
    global options
    global args
    global domains

    parser = setup_cmdline_parser()
    (options, args) = parser.parse_args()

    if len(args):
        parser.error("No parameter required")
    if options.mspersample < 0:
        parser.error("option --ms_per_sample: invalid negative value: '%d'" %
                     options.mspersample)
    # If --ms_per_sample= is too large, no data may be logged.
    if not options.live and options.duration != 0 and \
       options.mspersample > options.duration * 1000:
        parser.error("option --ms_per_sample: too large (> %d ms)" %
                     (options.duration * 1000))

    start_xenbaked()
    if options.live:
        show_livestats(options.cpu)
    else:
        try:
            writelog()
        except:
            print 'Quitting.'
    stop_xenbaked()

Using options, args out of functions with “global”


Python learning schadule

1. Python Basic skills & fundamental — Programming Python 3rd Edition [book recommend]

2. Python cook book — learning the contents are associated with system administration :

  • text

 

  • re

 

  • os

 

  • file operation.

3. Ipython interactive shell —Python.for.Unix.and.Linux.System.Administration[book recommend]

Python-Django clean_data 和 cleaned_data

clean_data 和 cleaned_data

在我们使用Django的表单对象时我们会对表单对象进行验证,比如:
>>>python manage.py shell
>>>from pageage1 import MyForm
>>>form=MyForm({‘username’:’Eric’,’email’:’test@test.com’})
>>>form.is_valid()
True

如果验证通过,你可以通过form.clean_data访问这些验证通过的数据,不过这是在Django0.96中的方式,在Django1.0中这个属性变成了form.cleaned_data:

>>>form.clean_data # Django 0.96
>>>form.cleaned_data # Django 1.0