Skip to content

Commit

Permalink
Validate available plans in given facility
Browse files Browse the repository at this point in the history
  • Loading branch information
xorel committed Oct 25, 2019
1 parent bc93fc5 commit db355c0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions minione
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,30 @@ validate_packet() {
fi
}

validate_packet_plan_facility() {
URL="/projects/$EDGE_PACKET_PROJECT/plans/"
DATA=$(packet_req "$URL")
AVAILABLE_FACILITY_IDS=$(echo "$DATA" | jq -r ".plans | .[] | select(.name==\"$EDGE_PACKET_PLAN.x86\") | .\"available_in\" | .[] | .href" | awk -F\/ '{print $3}')
if [ -z "$AVAILABLE_FACILITY_IDS" ]; then
echo "Can not list Packet project plans"
return 1
fi

URL="/projects/$EDGE_PACKET_PROJECT/facilities/"
DATA=$(packet_req "$URL")
REQUIRED_FACILITY_ID=$(echo "$DATA" |jq -r ".facilities | .[] | select(.code==\"$EDGE_PACKET_FACILITY\") | .id")
if [ -z "$REQUIRED_FACILITY_ID" ]; then
echo "Can not list Packet project facilities"
return 1
fi

if [[ ! $AVAILABLE_FACILITY_IDS =~ "$REQUIRED_FACILITY_ID" ]]; then
echo "Required Packet plan($EDGE_PACKET_PLAN) is not available in facility($EDGE_PACKET_FACILITY)"
return 1
fi
}


#-------------------------------------------------------------------------------
# Checks & detection
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -979,6 +1003,7 @@ node && packet && {
check "validate_packet facilities code $EDGE_PACKET_FACILITY /projects/$EDGE_PACKET_PROJECT" "Checking Packet facility"
check "validate_packet operating-systems slug $EDGE_PACKET_OS" "Checking Packet operating system"
check "validate_packet plans name ${EDGE_PACKET_PLAN}.x86 /projects/$EDGE_PACKET_PROJECT" "Checking Packet plan"
check "validate_packet_plan_facility" "Checking packet facility and plan"
fi

check "curl -s -H \"${JSON_HEADERS}\" ${APPS_URL} \
Expand Down

0 comments on commit db355c0

Please sign in to comment.