You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
eqx/eqx-market-spot-convert

47 lines
1.0 KiB

#!/bin/bash
# eqx-market-spot-convert
# Convert a "spot" server into "on demand" server
#
# Usage:
# eqx-market-spot-convert [device id]
# Example:
# eqx-market-spot-convert 00000001-2000-3000-4000-500000000000
EQXTOKEN=`cat ~/.packet-cli.json | jq ".token" --raw-output`
EQXDEVICEID="$1"
if [[ $1 == "" ]]
then \
echo -e "Need device ID"
echo -e "To get device IDs in a project, run:"
echo -e "eqx-get-project-devices [project name]"
echo
exit
fi
EQXFACILITY=`eqx-get-deviceid-facility $EQXDEVICEID`
generate_post_data()
{
cat <<EOF
{
"facility": "$EQXFACILITY",
"spot_instance": false
}
EOF
}
echo "Is spot? `eqx-market-spot-deviceid $EQXDEVICEID`"
echo "Converting to on demand..."
curl \
-X PUT \
--silent \
--header 'Content-Type: application/json' \
--header "X-Auth-Token: ${EQXTOKEN}" \
"https://api.equinix.com/metal/v1/devices/$EQXDEVICEID" \
--data "$(generate_post_data)" 1>/dev/null 2>/dev/null
echo "Is spot? `eqx-market-spot-deviceid $EQXDEVICEID`"