Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 150aed9

Browse files
author
Dmitry
committed
Option --aws-zone added
1 parent 46283e6 commit 150aed9

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

nancy_run.sh

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ function check_cli_parameters() {
394394
err "NOTICE: AWS EC2 region not given. Will use us-east-1."
395395
AWS_REGION='us-east-1'
396396
fi
397+
if [[ -z ${AWS_ZONE+x} ]]; then
398+
err "NOTICE: AWS EC2 zone not given. Will determined by min price."
399+
else
400+
if [[ -z $AWS_ZONE ]]; then
401+
err "NOTICE: AWS EC2 zone not given. Will determined by min price."
402+
unset -v AWS_ZONE
403+
fi
404+
fi
397405
if [[ -z ${AWS_BLOCK_DURATION+x} ]]; then
398406
err "NOTICE: Container live time duration is not given. Will use 60 minutes."
399407
AWS_BLOCK_DURATION=60
@@ -437,6 +445,10 @@ function check_cli_parameters() {
437445
err "ERROR: option '--aws-region' must be used with '--run-on aws'."
438446
exit 1
439447
fi
448+
if [[ ! -z ${AWS_ZONE+x} ]]; then
449+
err "ERROR: option '--aws-zone' must be used with '--run-on aws'."
450+
exit 1
451+
fi
440452
if [[ "$AWS_BLOCK_DURATION" != "0" ]]; then
441453
err "ERROR: option '--aws-block-duration' must be used with '--run-on aws'."
442454
exit 1
@@ -718,22 +730,27 @@ function determine_history_ec2_spot_price() {
718730
--start-time=$(date +%s) --product-descriptions="Linux/UNIX (Amazon VPC)" \
719731
--query 'SpotPriceHistory[*].{az:AvailabilityZone, price:SpotPrice}'
720732
)
721-
minprice=$(echo $prices | jq 'min_by(.price) | .price')
722-
region=$(echo $prices | jq 'min_by(.price) | .az') #TODO(NikolayS) double-check zones&regions
733+
if [[ ! -z ${AWS_ZONE+x} ]]; then
734+
# zone given by option
735+
price_data=$(echo $prices | jq ".[] | select(.az == \"$AWS_REGION$AWS_ZONE\")")
736+
else
737+
# zone NOT given by options, will detected from min price
738+
price_data=$(echo $prices | jq 'min_by(.price)')
739+
fi
740+
region=$(echo $price_data | jq '.az')
741+
price=$(echo $price_data | jq '.price')
742+
#region=$(echo $price_data | jq 'min_by(.price) | .az') #TODO(NikolayS) double-check zones&regions
723743
region="${region/\"/}"
724744
region="${region/\"/}"
725-
minprice="${minprice/\"/}"
726-
minprice="${minprice/\"/}"
745+
price="${price/\"/}"
746+
price="${price/\"/}"
727747
AWS_ZONE=${region:$((${#region}-1)):1}
728748
AWS_REGION=${region:0:$((${#region}-1))}
729-
msg "Min price from history: $minprice in $region (zone: $AWS_ZONE)"
749+
msg "Min price from history: $price in $AWS_REGION (zone: $AWS_ZONE)"
730750
multiplier="1.01"
731-
price=$(echo "$minprice * $multiplier" | bc -l)
751+
price=$(echo "$price * $multiplier" | bc -l)
732752
msg "Increased price: $price"
733753
EC2_PRICE=$price
734-
if [[ -z $AWS_ZONE ]]; then
735-
AWS_ZONE='a' #default zone
736-
fi
737754
}
738755

739756
#######################################
@@ -975,6 +992,8 @@ while [ $# -gt 0 ]; do
975992
AWS_EBS_VOLUME_SIZE="$2"; shift 2 ;;
976993
--aws-region )
977994
AWS_REGION="$2"; shift 2 ;;
995+
--aws-zone )
996+
AWS_ZONE="$2"; shift 2 ;;
978997
--aws-block-duration )
979998
AWS_BLOCK_DURATION=$2; shift 2 ;;
980999

0 commit comments

Comments
 (0)