From 5aa5f58086ebec268653908232262cf9f4d7aa82 Mon Sep 17 00:00:00 2001 From: ronivay Date: Thu, 15 Jul 2021 13:51:17 +0300 Subject: [PATCH] add option to define SR where to import appliance --- xo-appliance.sh | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/xo-appliance.sh b/xo-appliance.sh index 037893d..60cf4f9 100755 --- a/xo-appliance.sh +++ b/xo-appliance.sh @@ -33,7 +33,7 @@ function NetworkChoose { # shellcheck disable=SC1117 IFS=$'\n' read -r -d '' -a networks <<< "$(xe network-list | grep "uuid\|name-label" | cut -d':' -f2 | sed 's/^ //' | paste - -)" - + echo echo "Which network should the VM use?" echo local PS3="Pick a number. CTRL+C to exit: " @@ -52,6 +52,42 @@ function NetworkChoose { } +function StorageChoose { + + set +e + + # shellcheck disable=SC1117 + IFS=$'\n' read -r -d '' -a storages <<< "$(xe sr-list content-type=user | grep "uuid\|name-description" | cut -d':' -f2 | sed 's/^ //' | paste - -)" + + if [[ ${#storages[@]} -eq 0 ]]; then + echo "No storage repositories found, can't import VM" + echo "Create SR and try again. More information: https://xcp-ng.org/docs/storage.html" + exit 1 + fi + + echo "Which storage repository should the VM use?" + echo "default will attempt to use pool default SR" + echo + local PS3="Pick a number. CTRL+C to exit: " + select storage in "${storages[@]}" "default" + do + read -r -a storage_split <<< "$storage" + storageuuid=${storage_split[0]} + + case $storage in + default) + sruuid=default + break + ;; + *) + sruuid=$storageuuid + break + ;; + esac + done + +} + function NetworkSettings { set -e @@ -102,7 +138,11 @@ function VMImport { echo "Downloading and importing XVA image..." echo - uuid=$(curl "$IMAGE_URL" | xe vm-import filename=/dev/stdin) + if [[ $sruuid == "default" ]]; then + uuid=$(curl "$IMAGE_URL" | xe vm-import filename=/dev/stdin) + else + uuid=$(curl "$IMAGE_URL" | xe vm-import filename=/dev/stdin sr-uuid="$sruuid") + fi # shellcheck disable=SC2181 if [[ $? != "0" ]]; then @@ -167,6 +207,7 @@ function VMImport { } OSCheck +StorageChoose NetworkChoose NetworkSettings VMImport