From dc3a1150503b266944c5d78dc6580511432ed8f8 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Tue, 7 Oct 2025 15:34:43 +0200 Subject: [PATCH] Allow overriding region Relates: https://github.com/copr-private/issues/issues/97 --- bin/resalloc-aws-delete | 7 +++++-- bin/resalloc-aws-list | 14 +++++++++++--- bin/resalloc-aws-new | 8 ++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/bin/resalloc-aws-delete b/bin/resalloc-aws-delete index 80fe15d..8f4d654 100755 --- a/bin/resalloc-aws-delete +++ b/bin/resalloc-aws-delete @@ -31,6 +31,7 @@ Instead of --name, you can use \$RESALLOC_NAME env var. Options: --name NAME Name of the VM to be stopped. --aws-profile Name of the aws profile, as defined in ~/.aws/config. + --region Region ID (might be set in aws-profile) --debug Print debugging info. EOHELP @@ -40,6 +41,7 @@ test -z "$1" || exit "$1" opt_debug=false opt_name=$RESALLOC_NAME opt_aws_profile= +opt_region= info() { echo >&2 " * $*" ; } debug() { if $opt_debug; then echo >&2 " - $*" ; fi } @@ -52,7 +54,7 @@ run_cmd() "$@" } -long_opts="name:,aws-profile:,debug,help" +long_opts="name:,aws-profile:,debug,help,region:" ARGS=$( getopt -o "h" -l "$long_opts" -n "getopt" -- "$@") || show_help 1 mandatory_options=" @@ -83,7 +85,7 @@ while true; do show_help 0 ;; - --name|--aws-profile) + --name|--aws-profile|--region) option_variable "$1" eval "$option_variable_result=\$2" shift 2 @@ -114,6 +116,7 @@ aws=( --output text ) +test -n "$opt_region" && aws+=( --region "$opt_region" ) instance_id=$( run_cmd "${aws[@]}" ec2 describe-instances \ diff --git a/bin/resalloc-aws-list b/bin/resalloc-aws-list index 80731c7..99d243f 100755 --- a/bin/resalloc-aws-list +++ b/bin/resalloc-aws-list @@ -36,13 +36,14 @@ Options: --pool NAME The name (id) of resalloc pool. --tag TAGNAME=VALUE Filter the instances by this tag. --aws-profile Name of the aws profile, as defined in ~/.aws/config. + --region Region ID (might be set in aws-profile) --help Print this help. EOHELP test -z "$1" || exit "$1" } -long_opts="pool:,tag:,aws-profile:,help" +long_opts="pool:,tag:,aws-profile:,help,region:" ARGS=$( getopt -o "h" -l "$long_opts" -n "getopt" -- "$@") || show_help 1 eval set -- "$ARGS" @@ -64,6 +65,7 @@ option_variable() opt_aws_profile=default opt_pool=$RESALLOC_POOL_ID opt_tag=() +opt_region= while true; do @@ -73,7 +75,7 @@ while true; do show_help 0 ;; - --pool|--aws-profile) + --pool|--aws-profile|--region) option_variable "$1" eval "$option_variable_result=\$2" shift 2 @@ -114,8 +116,14 @@ if $tag_found; then filters+=( "${tagspec_result[@]}" ) fi -cmd=( +aws=( aws --profile $opt_aws_profile +) + +test -n "$opt_region" && aws+=( --region "$opt_region" ) + +cmd=( + "${aws[@]}" ec2 describe-instances "${filters[@]}" --output text diff --git a/bin/resalloc-aws-new b/bin/resalloc-aws-new index fe6fab9..f319767 100755 --- a/bin/resalloc-aws-new +++ b/bin/resalloc-aws-new @@ -34,6 +34,7 @@ Options: --name NAME Name of the started VM instance --ami IMAGE Start the VM from this AMI. --aws-profile Name of the aws profile, as defined in ~/.aws/config. + --region Region ID (might be set in aws-profile) --ssh-key-name Name of the uploaded SSH key uploaded to AWS. --security-group-id SGID ID of the AWS security group to place this in (AWS @@ -95,7 +96,7 @@ test "${#@}" -eq 0 && show_help 1 long_opts="name:,ami:,initial-preparation,create-snapshot-image,help,spot-price:,\ playbook:,private-ip,debug,root-volume-size:,additional-volume-size:,no-print-ip,aws-profile:,\ -ssh-key-name:,security-group-id:,possible-subnet:,instance-type:,tag:" +ssh-key-name:,security-group-id:,possible-subnet:,instance-type:,tag:,region:" ARGS=$( getopt -o "h" -l "$long_opts" -n "getopt" -- "$@") || show_help 1 mandatory_options=" @@ -121,6 +122,7 @@ opt_spot_price= opt_playbook= opt_private_ip=false opt_print_ip=true +opt_region= opt_ssh_key_name= opt_security_group_id= opt_possible_subnet=() @@ -149,7 +151,7 @@ while true; do ;; --name|--ami|--spot-price|--playbook|--root-volume-size|--additional-volume-size|\ - --aws-profile|--ssh-key-name|--security-group-id|--instance-type) + --aws-profile|--ssh-key-name|--security-group-id|--instance-type|--region) option_variable "$1" eval "$option_variable_result=\$2" shift 2 @@ -198,6 +200,8 @@ aws=( --output text ) +test -n "$opt_region" && aws+=( --region "$opt_region" ) + debug "AWS base command '${aws[*]}'" info "Instance Name: $opt_name"