歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> KVM腳本批量添加刪除虛擬機

KVM腳本批量添加刪除虛擬機

日期:2017/2/28 14:47:58   编辑:Linux教程

[背景]最近事情特別多,前段時間搞搞openstack,發現過與復雜,就想把KVM先好好學學,再過來搞它.因為工作關系,又用twisted開發了一個c/s的監控程序,但因還沒有寫完,所以暫時沒有發出來.如果不是強逼自己,我想我這個工具,也可能需要再等幾日才能發布吧.扯遠了,先不說這些,就說我這款工具能干嘛吧.簡單的說就像openstack的鏡像功能一般,不過,人家是提供Web Gui,點兩下就OK了,我這需要修改下配置文件vm.ini,不過它那個點兩下,不一定OK噢,反正我試過,沒那麼靈光.我的配置文件很簡單,就是告訴我是添加還是刪除虛擬機,如果添加則需要告訴模板鏡像文件在哪?模板xml文件在哪.當然這些都是要定義好的.也就是提前將鏡像文件做好嘛.openstack的glance也是需要的嘛.

[過程]

(1)安裝模板系統

(2)將模板img文件和xml文件分別copy到/template/img,/template/xml下,當然,你也可以更改,不過,程序也需要做修改.

(3)修改vm.ini文件

參考

模板xml文件

more /template/xml/Template_CentOS55x64_LAMP.xml


<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit Template_Centos55x64_LAMP
or other application using the libvirt API.
-->
<domain type='kvm'>
<name>Template_Centos55x64_LAMP</name>
<uuid>e7bbc1b0-e9b1-a0f2-bd1e-dd9f3fd48823</uuid>
<memory unit='KiB'>524288</memory>
<currentMemory unit='KiB'>524288</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='x86_64' machine='rhel6.3.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/Template_Centos55x64_LAMP.img'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<interface type='bridge'>
<mac address='52:54:00:88:d0:51'/>
<source bridge='br0'/>
<model type='virtio'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes'/>
<video>
<model type='cirrus' vram='9216' heads='1'/>
</video>
</devices>
</domain>

Copyright © Linux教程網 All Rights Reserved