参考文章:
xenserver 安装:
http://www.osyunwei.com/archives/6616.html
XCP/XenServer命令行方式安装VM:
http://heylinux.com/archives/2795.html
[root@xenserver-1 ~]# vim install.py
#!/bin/env python
import threading
import time
import os
loops=['192.168.11.203','192.168.11.204','192.168.11.205']
def work(ip):
cmd='bash -x ./install.sh '+ip
os.system(cmd)
def main():
threads=[]
nloops=range(len(loops))
for i in loops:
kscmd="sed -ci \'s/^network.*/network --onboot yes --device eth0 --bootproto=static --ip="+i+" --netmask=255.255.255.0 --gateway=192.168.11.21 --nameserver=114.114.114.114 --noipv6/\' /var/www/html/repo/ks/centos-6.3.ks
"
print kscmd
os.system(kscmd)
t=threading.Thread(target=work,args=(i,))
t.start()
time.sleep(40)
# work(i)
if __name__=="__main__":
main()
[root@xenserver-1 ~]# vim install.sh
#!/bin/bash
function installvm(){
networkip=$1
sruuid=`xe sr-list | grep -C 1 "Local"|head -3|grep uuid|awk -F': ' '{print $2}'`
#初始化一个空的VM
uuid=`xe vm-install new-name-label=centos6_$networkip sr-uuid=$sruuid template=Other\ install\ media`
#设置VM的CPU,内存
xe vm-param-set VCPUs-max=2 uuid=$uuid
xe vm-param-set VCPUs-at-startup=2 uuid=$uuid
xe vm-param-set memory-static-max=1073741824 uuid=$uuid
xe vm-param-set memory-dynamic-max=512435456 uuid=$uuid
xe vm-param-set memory-dynamic-min=512435456 uuid=$uuid
xe vm-param-set memory-static-min=268217728 uuid=$uuid
#xe vm-param-set memory-dynamic-max=906MiB uuid=$uuid
#xe vm-param-set memory-static-max=1024MiB uuid=$uuid
#xe vm-param-set memory-dynamic-min=812MiB uuid=$uuid
#xe vm-param-set memory-static-min=512MiB uuid=$uuid
#为自动化安装VM设置bootloader,httprepo,kickstart
xe vm-param-set HVM-boot-policy="" uuid=$uuid
xe vm-param-set PV-bootloader="eliloader" uuid=$uuid
xe vm-param-set other-config:install-repository="http://192.168.11.200:8080/repo/centos/6.3/" uuid=$uuid
xe vm-param-set PV-args="ip=$networkip netmask=255.255.255.0 gateway=192.168.11.21 ns=114.114.114.114 ks=http://192.168.11.200:8080/repo/ks/centos-6.3.ks ksdevice=eth0" uuid=$uuid
#为VM添加一块虚拟硬盘
xe vm-disk-add uuid=$uuid sr-uuid=$sruuid device=0 disk-size=20GiB
#设置虚拟硬盘为bootable
uuid1=`xe vbd-list vm-uuid=$uuid userdevice=0 params=uuid --minimal`
xe vbd-param-set bootable=true uuid=$uuid1
#为VM创建网络
networkid=`xe network-list bridge=xenbr0 --minimal`
xe vif-create vm-uuid=$uuid network-uuid=$networkid mac=random device=0
#启动VM,接下来,VM将自动化安装好所有的基础软件包,并启动SSH服务
xe vm-start uuid=$uuid
}
installvm $1
[root@xenserver-1 ~]# more /var/www/html//repo/ks/centos-6.3.ks
cmdline
skipx
install
cdrom
lang en_US.UTF-8
keyboard us
rootpw 12345678
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc Etc/UTC
bootloader --location=mbr --driveorder=xvda --append="crashkernel=auto"
zerombr
clearpart --all --initlabel
autopart
reboot
%packages --nobase
@core
%end
network --onboot yes --device eth0 --bootproto=static --ip=192.168.11.205 --netmask=255.255.255.0 --gateway=192.168.11.21 --nameserver=114.114.114.114 --noipv6
转载于:https://blog.51cto.com/monkeyzhu/1427387