Dump VM configuration after define to file

This ensure that VM configuration is persistent
between reboots

Change-Id: I1a3d55e165d57e088b48677cae32d1b767593104
Closes-Bug: 1491359
This commit is contained in:
Bartosz Kupidura 2015-09-02 17:58:10 +02:00
parent e4985aa83f
commit 0e37b0431f
3 changed files with 23 additions and 10 deletions

View File

@ -25,6 +25,7 @@ package { $packages:
service { $libvirt_service_name:
ensure => 'running',
require => Package[$packages],
before => Exec['generate_vms'],
}
file { "${libvirt_dir}/autostart":
@ -44,6 +45,5 @@ vm_config { $vms:
exec { 'generate_vms':
command => "/usr/bin/generate_vms.sh ${libvirt_dir} ${template_dir}",
path => ['/usr/sbin', '/usr/bin' , '/sbin', '/bin'],
notify => Service[$libvirt_service_name],
require => [File["${template_dir}"], File["${libvirt_dir}/autostart"]],
}

View File

@ -3,11 +3,12 @@ LIBVIRT_DIR=$1
TEMPLATE_DIR=$2
#Defaults
DEFAULT_DISK_SIZE="50G"
DEFAULT_DISK_SIZE="60G"
DEFAULT_CPU_COUNT="2"
DEFAULT_MEM_COUNT="2"
shopt -s globstar nullglob
trap 'rm -rf $TMP_FILE' EXIT INT HUP
usage() {
@ -84,21 +85,33 @@ for TEMPLATE_XML in $TEMPLATE_DIR/**/*.xml
do
VM_NAME=$(basename $TEMPLATE_XML | cut -f1 -d".")
DST_XML=${LIBVIRT_DIR}/${VM_NAME}.xml
TMP_FILE=$(mktemp /tmp/tmp.XXXXXXXXXX)
#Copy VMs xml file to libvirt and ensure autostart
if ! [[ -h "${LIBVIRT_DIR}/autostart/$VM_NAME.xml" ]]; then
ln -s $DST_XML ${LIBVIRT_DIR}/autostart/
fi
cp -f $TEMPLATE_XML $DST_XML
#Create disks for VMs
create_vm_disks $VM_NAME $DST_XML
#Check if VM is already defined
DOMID=$(virsh domid $VM_NAME)
if [[ -z "$DOMID" ]]; then
cp -f $TEMPLATE_XML $TMP_FILE
#Verify cpu settings
verify_cpu $VM_NAME $DST_XML
#Create disks for VMs
create_vm_disks $VM_NAME $TMP_FILE
#Verify memory settings
verify_mem $VM_NAME $DST_XML
#Verify cpu settings
verify_cpu $VM_NAME $TMP_FILE
#Verify memory settings
verify_mem $VM_NAME $TMP_FILE
#Define VM
virsh define $TMP_FILE || exit 1
#Start VM
virsh start $VM_NAME || exit 1
fi
done

View File

@ -14,7 +14,6 @@ describe manifest do
it 'should exec generate_vms' do
should contain_exec('generate_vms').with(
'command' => "/usr/bin/generate_vms.sh #{libvirt_dir} #{template_dir}",
'notify' => "Service[#{libvirt_service}]",
)
end
@ -42,6 +41,7 @@ describe manifest do
it "should start #{libvirt_service} service" do
should contain_service(libvirt_service).with(
'ensure' => 'running',
'before' => 'Exec[generate_vms]',
)
end