Make API URL an argument of the provisioning script

This commit is contained in:
Nicolas Jeannerod 2025-02-21 10:21:54 +01:00
parent 5c7ac44387
commit 9e95287715
Signed by untrusted user: Niols
GPG key ID: 35DB9EC8886E1CB8
2 changed files with 14 additions and 10 deletions

View file

@ -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

View file

@ -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
################################################################################