mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-7143: more reliable support for vagrant box export
Veewee supports exporting vagrant boxes out of virtualbox, out of the box. However, it assumes that it can export a disk if the shutdown of the vm that is using that disk has succeeded. This assumption is not strictly always true (see previous commit). So, we replicate the bit of logic in veewee for making vagrant boxes. This has the added side benefit of creating an .ovf export only once, rather than once for vmware and then again for vagrant.
This commit is contained in:
parent
be8b2d7c21
commit
00b39de0f8
|
|
@ -146,6 +146,9 @@ fi
|
|||
|
||||
appliance_build_name=${appliance}${branch_tag}${version_tag}
|
||||
|
||||
# mac address of the vm we create
|
||||
mac_address=
|
||||
|
||||
###
|
||||
### Generic helper functions
|
||||
###
|
||||
|
|
@ -308,6 +311,14 @@ function veewee_halt() {
|
|||
bundle exec veewee vbox halt "${appliance_build_name}" ${VEEWEE_ARGS}
|
||||
}
|
||||
|
||||
function save_mac_address() {
|
||||
log INFO "saving new vm mac address"
|
||||
mac_address=`vboxmanage showvminfo --details --machinereadable ${appliance_build_name} | grep macaddress1= | sed 's/macaddress1=//' | sed 's/"//g'`
|
||||
if [ "${mac_address}" == "" ]; then
|
||||
error "Could not find mac address for appliance ${appliance_build_name}"
|
||||
fi
|
||||
}
|
||||
|
||||
function check_appliance_shutdown() {
|
||||
log INFO "waiting for veewee appliance to shut down..."
|
||||
! (vboxmanage list runningvms | grep "${appliance_build_name}")
|
||||
|
|
@ -446,6 +457,32 @@ function vmware_export() {
|
|||
log INFO "${appliance} exported for VMWare: dist/${appliance_build_name}-vmware.ova"
|
||||
}
|
||||
|
||||
function vagrant_export() {
|
||||
log INFO "creating vagrant export"
|
||||
# this is based on veewee export logic, but, we don't want to use veewee export,
|
||||
# since it makes optimistic assumptions about VM shutdown/halt leading to available
|
||||
# disks and the like
|
||||
disk="${appliance_build_name}-vmware.ovf"
|
||||
mkdir -p "box/${appliance_build_name}"
|
||||
cp "${disk}" "box/${appliance_build_name}/box.ovf"
|
||||
cat >box/${appliance_build_name}/Vagrantfile <<END
|
||||
Vagrant::Config.run do |config|
|
||||
# This Vagrantfile is auto-generated by `vagrant package` to contain
|
||||
# the MAC address of the box. Custom configuration should be placed in
|
||||
# the actual `Vagrantfile` in this box.
|
||||
config.vm.base_mac = "${mac_address}"
|
||||
end
|
||||
|
||||
# Load include vagrant file if it exists after the auto-generated
|
||||
# so it can override any of the settings
|
||||
include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)
|
||||
load include_vagrantfile if File.exist?(include_vagrantfile)
|
||||
END
|
||||
( cd box/${appliance_build_name}; tar cf "../${appliance_build_name}.box" . )
|
||||
mv "box/${appliance_build_name}.box" dist/
|
||||
log INFO "${appliance} exported for vagrant: dist/${appliance_build_name}.box"
|
||||
}
|
||||
|
||||
function hyperv_export() {
|
||||
log INFO "creating hyperv export"
|
||||
local hdd_uuid="${1}"
|
||||
|
|
@ -473,6 +510,7 @@ function main() {
|
|||
veewee_destroy # in case of left-over cruft from failed build
|
||||
add_on_exit veewee_destroy
|
||||
veewee_build
|
||||
save_mac_address
|
||||
veewee_halt
|
||||
stop_vbox # some extra encouragement for virtualbox to stop things
|
||||
retry 10 check_appliance_shutdown
|
||||
|
|
@ -490,6 +528,7 @@ function main() {
|
|||
xen_server_export "${hdd_path}"
|
||||
kvm_export "${hdd_path}"
|
||||
vmware_export "${machine_uuid}" "${hdd_uuid}"
|
||||
vagrant_export "${machine_uuid}" "${hdd_uuid}"
|
||||
hyperv_export "${hdd_uuid}"
|
||||
add_on_exit log INFO "BUILD SUCCESSFUL"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue