From ae3202da329d3c25f51b72d7da3a19df4f9a0294 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Thu, 1 Aug 2013 19:39:12 -0400 Subject: [PATCH] fix(image_to_vm): Add VM MAC address to Vagrantfile, create box image. Vagrant should now be good to go! --- build_library/virtualbox_ovf.sh | 30 ++++++++++++++++++--- build_library/vm_image_util.sh | 47 ++++++++++++++++++--------------- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/build_library/virtualbox_ovf.sh b/build_library/virtualbox_ovf.sh index ebbde4799c..dc25db872f 100755 --- a/build_library/virtualbox_ovf.sh +++ b/build_library/virtualbox_ovf.sh @@ -9,6 +9,8 @@ SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..) DEFINE_string vm_name "CoreOS" "Name for this VM" DEFINE_string disk_vmdk "" "Disk image to reference, only basename is used." DEFINE_integer memory_size 1024 "Memory size in MB" +DEFINE_string output_ovf "" "Path to write ofv file to, required." +DEFINE_string output_vagrant "" "Path to write Vagrantfile to, optional." # Parse command line FLAGS "$@" || exit 1 @@ -22,6 +24,11 @@ if [[ ! -e "${FLAGS_disk_vmdk}" ]]; then exit 1 fi +if [[ -z "${FLAGS_output_ovf}" ]]; then + echo "No ovf file path provided." >&2 + exit 1 +fi + DISK_NAME=$(basename "${FLAGS_disk_vmdk}") DISK_UUID=$(uuidgen) DISK_SIZE_BYTES=$(qemu-img info -f vmdk "${FLAGS_disk_vmdk}" \ @@ -39,12 +46,29 @@ macgen() { hexdump -n3 -e "\"${VBOX_MAC_PREFIX}%X\n\"" /dev/urandom } -# Date format as used in this file +# Used in both the ovf and Vagrantfile +PRIMARY_MAC=$(macgen) + +# Date format as used in ovf datez() { date -u "+%Y-%m-%dT%H:%M:%SZ" } -cat <"${FLAGS_output_vagrant}" <"${FLAGS_output_ovf}" < @@ -164,7 +188,7 @@ cat < - + diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index d9b1e7820a..3f8573b0e4 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -409,7 +409,7 @@ _write_ovf_conf() { --vm_name "$VM_NAME" \ --disk_vmdk "$VM_DST_IMG" \ --memory_size "$vm_mem" \ - > "$ovf" + --output_ovf "$ovf" local ovf_name=$(basename "${ovf}") cat > "${VM_README}" < "$ovf" + --output_ovf "$ovf" \ + --output_vagrant "$vfile" - cat > "${vfile}" < "${VM_README}" <= 1.2 is required. +Vagrant >= 1.2 is required. Use something like the following to get started: +vagrant box add coreos path/to/$(basename "${box}") +vagrant init coreos +vagrant up +vagrant ssh + +You will get a warning about "No guest additions were detected...", +this is expected and should be ignored. SSH should work just dandy. EOF - VM_GENERATED_FILES+=( "$ovf" "${vfile}" "${VM_README}" ) + # Replace list, not append, since we packaged up the disk image. + VM_GENERATED_FILES=( "${box}" "${VM_README}" ) +} + +vm_cleanup() { + info "Cleaning up temporary files" + rm -rf "${VM_TMP_DIR}" } print_readme() {