Create jobs to handle and delete nolabs bookings
[infra/cicd.git] / jjb / nolabs / delete-booking.sh
1 #!/bin/bash
2
3 cd $WORKSPACE
4
5 # install dependencies
6 sudo apt install -y virtualenv jq > /dev/null
7 /bin/rm -rf $NOLABS_VENV && mkdir -p $NOLABS_VENV
8 virtualenv -p python3 $NOLABS_VENV > /dev/null
9 source $NOLABS_VENV/bin/activate > /dev/null
10 pip install httpie python-openstackclient python-heatclient python-novaclient > /dev/null
11 source /tmp/openrc
12
13 export STACK_NAME="nordix-nolabs-booking${BOOKING_ID}-${DEPLOY_SCENARIO}"
14 echo "Info: STACK_NAME is set to $STACK_NAME"
15 echo "Info: Deleting stack $STACK_NAME"
16 echo "-------------------------------------------------"
17 echo openstack stack delete -y --wait $STACK_NAME
18 openstack stack delete -y --wait $STACK_NAME
19 echo "-------------------------------------------------"
20
21 # get authentication token
22 echo "API Request: http --ignore-stdin POST http://188.212.108.245/api/tokens --auth dummy@dummy.com:dummy | jq -r '.token'"
23 NOLABS_TOKEN=$(http --ignore-stdin POST http://188.212.108.245/api/tokens --auth $NOLABS_API_USERNAME:$NOLABS_API_PASSWORD | jq -r '.token')
24
25 # update booking status
26 echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \"status_text=deploying\" \"Authorization:Bearer DUMMY_TOKEN\""
27 http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \
28         "Authorization:Bearer $NOLABS_TOKEN" \
29         status_text=expired \
30         floating_ip="N/A"