Skip to content

Commit 09b6f06

Browse files
snp.sh: Update ubuntu guest image download to optimize the guest creation process
Updated the ubuntu guest download process to download it once and re-use the same image to quickly create multiple guests with the improved performance. Update of the guest image download structure in ubuntu also helps to easily add support for the same in the other OS linux distros. Signed-off-by: Harika Nittala <lnittala@amd.com>
1 parent 326c4d3 commit 09b6f06

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

tools/snp.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ SNPGUEST_URL="https://github.com/virtee/snpguest.git"
9898
SNPGUEST_BRANCH="tags/v0.7.1"
9999
NASM_SOURCE_TAR_URL="https://www.nasm.us/pub/nasm/releasebuilds/2.16.01/nasm-2.16.01.tar.gz"
100100
CLOUD_INIT_IMAGE_URL="https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
101+
CLOUD_INIT_IMAGE_URL_UBUNTU="https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
102+
IMAGE_BASENAME_UBUNTU=$(basename "${CLOUD_INIT_IMAGE_URL_UBUNTU}")
103+
IMAGE_BASENAME=""
101104
DRACUT_TARBALL_URL="https://github.com/dracutdevs/dracut/archive/refs/tags/059.tar.gz"
102105
SEV_SNP_MEASURE_VERSION="0.0.11"
103106

@@ -502,6 +505,33 @@ generate_guest_ssh_keypair() {
502505
ssh-keygen -q -t ed25519 -N '' -f "${GUEST_SSH_KEY_PATH}" <<<y
503506
}
504507

508+
download_guest_os_image(){
509+
local linux_distro=$(get_linux_distro)
510+
511+
# Set the guest OS image-cloud init URL, guest image basename based on the Host OS type
512+
case ${linux_distro} in
513+
ubuntu)
514+
CLOUD_INIT_IMAGE_URL=${CLOUD_INIT_IMAGE_URL_UBUNTU}
515+
IMAGE_BASENAME=${IMAGE_BASENAME_UBUNTU}
516+
;;
517+
*)
518+
>&2 echo -e "ERROR: ${linux_distro}"
519+
return 1
520+
;;
521+
esac
522+
523+
local base_launch_directory=${LAUNCH_WORKING_DIR//"/$GUEST_NAME"*/}
524+
local base_guest_image=${base_launch_directory}/${IMAGE_BASENAME}
525+
526+
# Download image if not present already
527+
if [ ! -f ${base_guest_image} ]; then
528+
wget "${CLOUD_INIT_IMAGE_URL}" -O ${base_guest_image}
529+
fi
530+
531+
# Copy image to launch directory
532+
cp -v ${base_guest_image} "${IMAGE}"
533+
}
534+
505535
cloud_init_create_data() {
506536
if [[ -f "${LAUNCH_WORKING_DIR}/${GUEST_NAME}-metadata.yaml" && \
507537
-f "${LAUNCH_WORKING_DIR}/${GUEST_NAME}-user-data.yaml" && \
@@ -540,8 +570,8 @@ EOF
540570
"${LAUNCH_WORKING_DIR}/${GUEST_NAME}-user-data.yaml" \
541571
"${LAUNCH_WORKING_DIR}/${GUEST_NAME}-metadata.yaml"
542572

543-
# Download ubuntu 20.04 and change name
544-
wget "${CLOUD_INIT_IMAGE_URL}" -O "${IMAGE}"
573+
# Download Guest Image from cloud init URL
574+
download_guest_os_image
545575
}
546576

547577
resize_guest() {

0 commit comments

Comments
 (0)