Merge "Store and reuse generated VM config"

This commit is contained in:
Jenkins 2015-10-12 09:55:28 +00:00 committed by Gerrit Code Review
commit c6877e0fb6
3 changed files with 14 additions and 6 deletions

View File

@ -1,7 +1,7 @@
notice('MODULAR: generate_vms.pp')
$libvirt_dir = '/etc/libvirt/qemu'
$template_dir = '/var/lib/vms'
$template_dir = '/var/lib/nova'
$packages = ['qemu-utils', 'qemu-kvm', 'libvirt-bin', 'xmlstarlet']
$libvirt_service_name = 'libvirtd'
@ -11,7 +11,7 @@ define vm_config {
$details = $name
$id = $details['id']
file { "${template_dir}/${id}_vm.xml":
file { "${template_dir}/template_${id}_vm.xml":
owner => 'root',
group => 'root',
content => template('osnailyfacter/vm_libvirt.erb'),

View File

@ -81,9 +81,9 @@ if (($# < 2)); then
usage
fi
for TEMPLATE_XML in $TEMPLATE_DIR/**/*.xml
for TEMPLATE_XML in $TEMPLATE_DIR/**/template_*.xml
do
VM_NAME=$(basename $TEMPLATE_XML | cut -f1 -d".")
VM_NAME=$(basename $TEMPLATE_XML | sed -e 's/template_\(.*\).xml/\1/')
DST_XML=${LIBVIRT_DIR}/${VM_NAME}.xml
TMP_FILE=$(mktemp /tmp/tmp.XXXXXXXXXX)
@ -95,7 +95,12 @@ do
#Check if VM is already defined
DOMID=$(virsh domid $VM_NAME)
if [[ -z "$DOMID" ]]; then
cp -f $TEMPLATE_XML $TMP_FILE
if [[ -f "${TEMPLATE_DIR}/${VM_NAME}.xml" ]]; then
cp -f ${TEMPLATE_DIR}/${VM_NAME}.xml $TMP_FILE
else
cp -f $TEMPLATE_XML $TMP_FILE
fi
#Create disks for VMs
create_vm_disks $VM_NAME $TMP_FILE
@ -111,6 +116,9 @@ do
#Start VM
virsh start $VM_NAME || exit 1
#Copy defined XML
cp -r $DST_XML ${TEMPLATE_DIR}/${VM_NAME}.xml
fi
done

View File

@ -5,7 +5,7 @@ manifest = 'generate_vms/generate_vms.pp'
describe manifest do
shared_examples 'catalog' do
libvirt_dir = '/etc/libvirt/qemu'
template_dir = '/var/lib/vms'
template_dir = '/var/lib/nova'
libvirt_service = 'libvirtd'
packages = ['qemu-utils', 'qemu-kvm', 'libvirt-bin', 'xmlstarlet']