Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions bin/resalloc-aws-delete
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 }
Expand All @@ -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="
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -114,6 +116,7 @@ aws=(
--output text
)

test -n "$opt_region" && aws+=( --region "$opt_region" )

instance_id=$(
run_cmd "${aws[@]}" ec2 describe-instances \
Expand Down
14 changes: 11 additions & 3 deletions bin/resalloc-aws-list
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -64,6 +65,7 @@ option_variable()
opt_aws_profile=default
opt_pool=$RESALLOC_POOL_ID
opt_tag=()
opt_region=


while true; do
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions bin/resalloc-aws-new
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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="
Expand All @@ -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=()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down