Last active
March 23, 2021 19:52
-
-
Save michaelwsherman/4faa4a4b8aad41ea1931dcf9b18d569b to your computer and use it in GitHub Desktop.
Set of commands for working with Google Cloud Notebooks
This file contains 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
export ZONE="us-west1-b" | |
export INSTANCE_NAME="my-instance" | |
export SSH_RULE_NAME="allow-ssh" | |
export SSH_TAG="ssh" | |
function create_notebook() { | |
export IMAGE_FAMILY="tf-latest-gpu" | |
export CREATION_INSTANCE_TYPE="n1-standard-4" | |
gcloud compute instances create $INSTANCE_NAME \ | |
--zone=$ZONE \ | |
--image-family=$IMAGE_FAMILY \ | |
--machine-type=$CREATION_INSTANCE_TYPE \ | |
--image-project=deeplearning-platform-release \ | |
--maintenance-policy=TERMINATE \ | |
--accelerator='type=nvidia-tesla-v100,count=1' \ | |
--no-boot-disk-auto-delete \ | |
--boot-disk-device-name=$INSTANCE_NAME-disk \ | |
--boot-disk-size=500GB \ | |
--boot-disk-type=pd-ssd \ | |
--scopes=https://www.googleapis.com/auth/cloud-platform \ | |
--metadata='install-nvidia-driver=True,proxy-mode=project_editors' | |
} | |
function ssh_vm() { | |
gcloud compute ssh $INSTANCE_NAME --zone=$ZONE | |
} | |
function create_ssh_rule() { | |
gcloud compute firewall-rules create $SSH_RULE_NAME \ | |
--allow=tcp:22 \ | |
--priority=0 \ | |
--description='Open port 22 for SSH.' \ | |
--target-tags=$SSH_TAG | |
} | |
function apply_ssh_rule() { | |
gcloud compute instances add-tags $INSTANCE_NAME \ | |
--zone=$ZONE \ | |
--tags=ssh | |
} | |
function remove_ssh_rule() { | |
gcloud compute instances remove-tags $INSTANCE_NAME \ | |
--zone=$ZONE \ | |
--tags=ssh | |
} | |
function stop_vm() { | |
gcloud compute instances stop $INSTANCE_NAME \ | |
--zone=$ZONE | |
} | |
# Parameter is new machine type, e.g., n1-standard-8. | |
function resize_vm() { | |
gcloud compute instances set-machine-type $INSTANCE_NAME \ | |
--zone=$ZONE \ | |
--machine-type=$1 | |
} | |
function start_vm() { | |
gcloud compute instances start $INSTANCE_NAME \ | |
--zone=$ZONE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment