Skip to content
Snippets Groups Projects
Commit 3887a549 authored by Krish Moodbidri's avatar Krish Moodbidri
Browse files

feat-launch-instance

parent df40c188
No related branches found
No related tags found
No related merge requests found
stages:
- deploy
variables:
OS_AUTH_URL: "https://keystone.cloud.rc.uab.edu:5000/v3"
OS_REGION_NAME: "bhm1"
OS_PROJECT_NAME: "your-project"
OS_USER_DOMAIN_NAME: "Default"
OS_IDENTITY_API_VERSION: "3"
create-instance:
stage: deploy
tags:
- openstack # Make sure your runner has OpenStack CLI installed
script:
- |
# Validate required parameters
if [ -z "$INSTANCE_NAME" ]; then
echo "ERROR: INSTANCE_NAME parameter is required"
exit 1
fi
# Base create command
CMD="openstack server create \
--flavor $FLAVOR \
--image $IMAGE \
--network $NETWORK \
--security-group $SECURITY_GROUP \
--key-name $SSH_KEY_NAME \
--format json \
$INSTANCE_NAME"
# Add optional parameters
if [ -n "$VOLUME_SIZE" ]; then
echo "Creating volume..."
VOLUME_ID=$(openstack volume create \
--size $VOLUME_SIZE \
--type $VOLUME_TYPE \
--format value -c id \
${INSTANCE_NAME}-volume)
CMD+=" --volume $VOLUME_ID"
fi
# Create instance
echo "Launching instance..."
INSTANCE_DATA=$(eval $CMD)
INSTANCE_ID=$(echo $INSTANCE_DATA | jq -r '.id')
# Assign floating IP if requested
if [ "$ASSIGN_FLOATING_IP" == "true" ]; then
echo "Assigning floating IP..."
FLOATING_IP=$(openstack floating ip create \
-f value -c floating_ip_address \
$FLOATING_IP_NETWORK)
openstack server add floating ip $INSTANCE_ID $FLOATING_IP
echo "Floating IP assigned: $FLOATING_IP"
fi
# Save output variables
echo "INSTANCE_ID=$INSTANCE_ID" >> build.env
echo "INSTANCE_NAME=$INSTANCE_NAME" >> build.env
[ -n "$FLOATING_IP" ] && echo "FLOATING_IP=$FLOATING_IP" >> build.env
artifacts:
reports:
dotenv: build.env
rules:
- if: $CI_PIPELINE_SOURCE == "web" # Manual trigger only
when: always
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment