convert device id or project from spot to on demand

master
Jeff Moe 3 years ago
parent fbb1bef592
commit c5efe3b056

@ -0,0 +1,46 @@
#!/bin/bash
# eqx-market-convert-spot
# Convert a "spot" server into "on demand" server
#
# Usage:
# eqx-market-convert-spot [device id]
# Example:
# eqx-market-convert-spot 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-deviceid-spot $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-deviceid-spot $EQXDEVICEID`"

@ -0,0 +1,37 @@
#!/bin/bash
# eqx-market-convert-spot-project
# Convert all the devices in a project from spot to on demand pricing.
#
# Usage:
# eqx-market-convert-spot-project [project name]
# Example:
# eqx-market-convert-spot-project fooproject
EQXPROJECT="$1"
if [[ $1 == "" ]]
then \
echo -e "Need project name, such as:\n"
eqx-get-project-names
echo
exit
fi
EQXPROJECTID=`eqx-get-project-uuid $EQXPROJECT`
EQXDEVICEIDS=`packet \
device \
get \
--json \
--project-id \
$EQXPROJECTID \
2>/dev/null \
| jq '.[].id' | \
sed -e 's/"//g'`
for i in $EQXDEVICEIDS
do \
echo "Converting $i ..."
eqx-market-convert-spot $i
done
Loading…
Cancel
Save