Fix 'generate_vms.sh' idempotentency
This change fixes 'generate_vms.sh' idempotentency by undefining the domain on error, and also adds command execution output to the logs. Change-Id: I94a9b1340a521da2bbfd1c08d7e1e0dc47aa9f51 Closes-Bug: #1613241 Signed-off-by: Maksim Malchuk <mmalchuk@mirantis.com>
This commit is contained in:
parent
cd1aea0a58
commit
73ca52d4f7
|
@ -39,9 +39,10 @@ class osnailyfacter::generate_vms::generate_vms {
|
|||
}
|
||||
|
||||
exec { 'generate_vms':
|
||||
command => "/usr/bin/generate_vms.sh ${libvirt_dir} ${template_dir}",
|
||||
path => ['/usr/sbin', '/usr/bin' , '/sbin', '/bin'],
|
||||
require => [File[$template_dir], File["${libvirt_dir}/autostart"]],
|
||||
command => "/usr/bin/generate_vms.sh ${libvirt_dir} ${template_dir}",
|
||||
path => ['/usr/sbin', '/usr/bin' , '/sbin', '/bin'],
|
||||
require => [File[$template_dir], File["${libvirt_dir}/autostart"]],
|
||||
logoutput => true,
|
||||
}
|
||||
|
||||
if $::operatingsystem == 'Ubuntu' {
|
||||
|
|
|
@ -93,7 +93,7 @@ do
|
|||
fi
|
||||
|
||||
#Check if VM is already defined
|
||||
DOMID=$(virsh domid $VM_NAME)
|
||||
DOMID=$(virsh domid $VM_NAME 2>/dev/null)
|
||||
if [[ -z "$DOMID" ]]; then
|
||||
|
||||
if [[ -f "${TEMPLATE_DIR}/${VM_NAME}.xml" ]]; then
|
||||
|
@ -115,10 +115,15 @@ do
|
|||
virsh define $TMP_FILE || exit 1
|
||||
|
||||
#Start VM
|
||||
virsh start $VM_NAME || exit 1
|
||||
virsh start $VM_NAME
|
||||
|
||||
#Copy defined XML
|
||||
cp -r $DST_XML ${TEMPLATE_DIR}/${VM_NAME}.xml
|
||||
if [[ $? -eq 0 ]]; then
|
||||
#Copy defined XML
|
||||
cp -r $DST_XML ${TEMPLATE_DIR}/${VM_NAME}.xml
|
||||
else
|
||||
virsh undefine $VM_NAME
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue