#!/bin/bash
#kvm batch create vm tool
#version:0.1
#author:name
#需要事先准备模板镜像和配置文件模板
echo "1.创建自定义配置单个虚拟机
2.批量创建自定义配置虚拟机
3.批量创建默认配置虚拟机
read -p "选取你的操作(1/2/3):" op
batch_self_define() {
kvmname=`openssl rand -hex 5`
sourceimage=/var/lib/libvirt/images/vmmodel.img
sourcexml=/etc/libvirt/qemu/vmmodel.xml
newimg=/var/lib/libvirt/images/${kvmname}.img
newxml=/etc/libvirt/qemu/${kvmname}.xml
cp $sourceimage $newimg
cp $sourcexml $newxml
kvmuuid=`uuidgen`
kvmmem=${1}000000
kvmcpu=$2
kvmimg=$newimg
kvmmac=`openssl rand -hex 3 | sed -r 's/..\B/&:/g'`
sed -i "s@kvmname@$kvmname@;s@kvmuuid@$kvmuuid@;s@kvmmem@$kvmmem@;s@kvmcpu@$kvmcpu@;s@kvmimg@$kvmimg@;s@kvmmac@$kvmmac@" $newxml
virsh define $newxml
virsh list --all
}
self_define() {
read -p "请输入新虚机名称:" newname
read -p "请输入新虚机内存大小(G):" newmem
read -p "请输入新虚机cpu个数:" newcpu
sourceimage=/var/lib/libvirt/images/vmmodel.img
sourcexml=/etc/libvirt/qemu/vmmodel.xml
newimg=/var/lib/libvirt/images/${newname}.img
newxml=/etc/libvirt/qemu/${newname}.xml
cp $sourceimage $newimg
cp $sourcexm
自动化脚本管理kvm
最新推荐文章于 2025-04-23 15:55:39 发布