批量创建XEN虚拟机。
使用方法: xen_create.sh 虚拟机名(这里定义为VM-XEN-虚拟机名)
1 xen_create.sh
-
#!/bin/bash
-
UUID=$(uuidgen)
-
MAC=$(/opt/macgen.py)
-
echo name = \"VM-XEN-$1\" >>VM-XEN-$1
-
echo uuid = \"$UUID\" >>VM-XEN-$1
-
echo maxmem = 2048 >>VM-XEN-$1
-
echo memory = 2048 >>VM-XEN-$1
-
echo vcpus = 1 >>VM-XEN-$1
-
echo builder = \"hvm\" >>VM-XEN-$1
-
echo kernel = \"/usr/lib/xen/boot/hvmloader\" >>VM-XEN-$1
-
echo boot = \"c\" >>VM-XEN-$1
-
echo pae = 1 >>VM-XEN-$1
-
echo acpi = 1 >>VM-XEN-$1
-
echo apic = 1 >>VM-XEN-$1
-
echo localtime = 0 >>VM-XEN-$1
-
echo on_poweroff = \"destroy\" >>VM-XEN-$1
-
echo on_reboot = \"restart\" >>VM-XEN-$1
-
echo on_crash = \"restart\" >>VM-XEN-$1
-
echo device_model = \"/usr/lib64/xen/bin/qemu-dm\" >>VM-XEN-$1
-
echo sdl = 0 >>VM-XEN-$1
-
echo vnc = 1 >>VM-XEN-$1
-
echo vncunused = 1 >>VM-XEN-$1
-
echo keymap = \"en-us\" >>VM-XEN-$1
-
echo disk = [ \"file:/ddmap/xen/images/VM-XEN-$1.img,hda,w\", \",hdc:cdrom,r\" ] >>VM-XEN-$1
-
echo vif = [ \"mac="$MAC
2 macgen.py (随机产生MAC地址)
点击(此处)折叠或打开
-
#!/usr/bin/python
-
# macgen.py script to generate a MAC address for Red Hat Virtualization guests
-
#
-
import random
-
-
def randomMAC():
-
mac = [ 0x00, 0x16, 0x3e, random.randint(0x00, 0x7f), random.randint(0x00, 0xff), random.randint(0x00, 0xff) ]
-
return ':'.join(map(lambda x: "%02x" % x, mac))
-
-
print randomMAC()
阅读(1732) | 评论(4) | 转发(0) |