Skip to content

Commit 7edf7e1

Browse files
LakshmiSaiHarikaUbuntu
authored andcommitted
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 13ec06e commit 7edf7e1

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.8.0"
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

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

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

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

548578
resize_guest() {

0 commit comments

Comments
 (0)