Ver código fonte

Add instance count to script

pull/4/head
Svitlana 4 anos atrás
pai
commit
aa93cebefd
2 arquivos alterados com 17 adições e 3 exclusões
  1. +1
    -0
      bin/compute/ec2/delete_test_instances.sh
  2. +16
    -3
      bin/compute/ec2/list_test_instances.sh

+ 1
- 0
bin/compute/ec2/delete_test_instances.sh Ver arquivo

@@ -14,6 +14,7 @@ if [[ ${INSTANCES_COUNT} -gt 0 ]] ; then

echo "Terminating ${INSTANCES_COUNT} test instances..."
aws ec2 terminate-instances --instance-ids "$INSTANCES"
echo "Now instances are terminated and will be deleted after few hours"

else
echo "No instances contains tag \"${TEST_TAG}\" to delete"


+ 16
- 3
bin/compute/ec2/list_test_instances.sh Ver arquivo

@@ -5,11 +5,24 @@
#
# List test Amazon EC2 instances
#
# Environment variables
#
# BUBBLE_ENV : env file to load. Default is ~/.bubble-test.env or /home/bubble/current/bubble-test.env (whichever is found first)
# AWS_ACCESS_KEY_ID : AWS access key ID
# AWS_SECRET_KEY : AWS secret access key

SCRIPT="${0}"
SCRIPT_DIR=$(cd $(dirname ${SCRIPT}) && pwd)

BUBBLE_ENV="${HOME}/.bubble-test.env"
if [[ -z "${BUBBLE_ENV}" ]] ; then
if [[ -f "${HOME}/.bubble-test.env" ]] ; then
BUBBLE_ENV="${HOME}/.bubble-test.env"
elif [[ -f "/home/bubble/current/.bubble-test.env" ]] ; then
BUBBLE_ENV="/home/bubble/current/.bubble-test.env"
else
die "bubble environment file not found"
fi
fi

if [[ -z "${TEST_TAG}" ]] ; then
TEST_TAG="$(cat ${BUBBLE_ENV} | egrep -v '\s*#' | grep TEST_TAG_CLOUD | awk -F '=' '{print $NF}' | tr -d "'" | tr -d '"')"
@@ -20,12 +33,12 @@ fi

INSTANCES=$(aws ec2 describe-instances --filters "Name=tag:test_instance,Values=${TEST_TAG}" --query "Reservations[].Instances[].InstanceId")

echo "$INSTANCES"
INSTANCES_COUNT="${#INSTANCES[@]}"
((INSTANCES_COUNT=$(echo "${INSTANCES}" | wc -l) - 2))

if [[ ${INSTANCES_COUNT} -gt 0 ]] ; then

echo "Found ${INSTANCES_COUNT} test instances contain tag ${TEST_TAG}"
echo "$INSTANCES"

else
echo "No instances contain tag \"${TEST_TAG}\" found"


Carregando…
Cancelar
Salvar