-
-
Save casperdcl/71e01f1125b4ee7093386fadfa7e7d71 to your computer and use it in GitHub Desktop.
paperspace helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
MACHINE_ID=<...your id...> | |
API_KEY=<...your key...> | |
alias _paper_api="curl -fsSL -H 'X-Api-Key: $API_KEY' -X" | |
_paper_api_get(){ | |
_paper_api GET https://api.paperspace.io/machines/getMachinePublic?machineId=$MACHINE_ID | jq "$@" | |
} | |
_paper_api_post(){ | |
_paper_api POST https://api.paperspace.io/machines/$MACHINE_ID/"$@" | |
} | |
paper(){ | |
case "$1" in | |
up) | |
_paper_api_post start | |
while test $(_paper_api_get -r .state) != ready; do | |
sleep 5 | |
done | |
;; | |
ssh) | |
ssh paperspace@$(_paper_api_get -r .publicIpAddress) "${@:2}" | |
;; | |
down) | |
_paper_api_post stop | |
;; | |
state) | |
_paper_api_get '{(.name): .state, storUse: .storageUsed, storTot: .storageTotal}' | |
;; | |
*) | |
echo >&2 "expected one of: up ssh down state" | |
(exit 1) | |
;; | |
esac | |
} | |
complete -W 'up ssh down state' paper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment