From 9e952877153312046e41ca90942c8e0630f70bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=E2=80=9CNiols=E2=80=9D=20Jeannerod?= Date: Fri, 21 Feb 2025 10:21:54 +0100 Subject: [PATCH] Make API URL an argument of the provisioning script --- deployment/proxmox/provision.sh | 14 ++++++++------ deployment/proxmox/remove.sh | 10 ++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/deployment/proxmox/provision.sh b/deployment/proxmox/provision.sh index 74b92717..605ef4c4 100755 --- a/deployment/proxmox/provision.sh +++ b/deployment/proxmox/provision.sh @@ -4,8 +4,6 @@ set -euC ################################################################################ ## Constants -readonly api_url=https://192.168.51.81:8006/api2/json - ## FIXME: There seems to be a problem with file upload where the task is ## registered to `node051` no matter what node we are actually uploading to? For ## now, let us just use `node051` everywhere. @@ -17,6 +15,7 @@ mkdir $tmpdir ################################################################################ ## Parse arguments +api_url= username= password= sockets=1 @@ -31,6 +30,7 @@ help () { Usage: $0 [OPTION...] ID [ID...] Options: + --api-url STR Base URL of the Proxmox API (required) --username STR Username, with provider (eg. niols@pve; required) --password STR Password (required) @@ -44,6 +44,7 @@ Options: Options can also be provided by adding assignments to a '.proxmox' file in the current working directory. For instance, it could contain: + api_url=https://192.168.51.81:8006/api2/json cores=7 username=mireille@pve debug=true @@ -55,7 +56,7 @@ EOF # shellcheck disable=SC2059 die () { printf '\033[31m'; printf "$@"; printf '\033[0m\n'; exit 2; } # shellcheck disable=SC2059 -die_with_help () { printf '\033[31m'; printf "$@"; printf '\033[0m\n'; help; exit 2; } +die_with_help () { printf '\033[31m'; printf "$@"; printf '\033[0m\n\n'; help; exit 2; } # shellcheck disable=SC2059 debug () { if $debug; then printf >&2 '\033[37m'; printf >&2 "$@"; printf >&2 '\033[0m\n'; fi } @@ -68,6 +69,7 @@ while [ $# -gt 0 ]; do argument=$1 shift case $argument in + --api-url|--api_url) readonly api_url="$1"; shift ;; --username) readonly username="$1"; shift ;; --password) readonly password="$1"; shift ;; @@ -86,11 +88,11 @@ while [ $# -gt 0 ]; do done if [ -z "$vm_ids" ]; then - die_with_help "Required: at least one VM id.\n" + die_with_help "Required: at least one VM id." fi -if [ -z "$username" ] || [ -z "$password" ]; then - die_with_help "Required: '--username' and '--password'.\n" +if [ -z "$api_url" ] || [ -z "$username" ] || [ -z "$password" ]; then + die_with_help "Required: '--api-url', '--username' and '--password'." fi readonly sockets diff --git a/deployment/proxmox/remove.sh b/deployment/proxmox/remove.sh index 9555380b..a579b0bc 100755 --- a/deployment/proxmox/remove.sh +++ b/deployment/proxmox/remove.sh @@ -4,8 +4,6 @@ set -euC ################################################################################ ## Constants -readonly api_url=https://192.168.51.81:8006/api2/json - ## FIXME: There seems to be a problem with file upload where the task is ## registered to `node051` no matter what node we are actually uploading to? For ## now, let us just use `node051` everywhere. @@ -17,6 +15,7 @@ mkdir $tmpdir ################################################################################ ## Parse arguments +api_url= username= password= vm_ids= @@ -26,6 +25,7 @@ help () { Usage: $0 [OPTION...] ID [ID...] Options: + --api-url STR Base URL of the Proxmox API (required) --username STR Username, with provider (eg. niols@pve) --password STR Password @@ -34,6 +34,7 @@ Options: Options can also be provided by adding assignments to a '.proxmox' file in the current working directory. For instance, it could contain: + api_url=https://192.168.51.81:8006/api2/json cores=7 username=mireille@pve debug=true @@ -55,6 +56,7 @@ while [ $# -gt 0 ]; do argument=$1 shift case $argument in + --api-url|--api_url) readonly api_url="$1"; shift ;; --username) readonly username=$1; shift ;; --password) readonly password=$1; shift ;; @@ -70,8 +72,8 @@ if [ -z "$vm_ids" ]; then die_with_help "Required: at least one VM id.\n" fi -if [ -z "$username" ] || [ -z "$password" ]; then - die_with_help "Required: '--username' and '--password'.\n" +if [ -z "$api_url" ] || [ -z "$username" ] || [ -z "$password" ]; then + die_with_help "Required: '--api-url', '--username' and '--password'." fi ################################################################################