Achieve more with new Google Compute Engine command-line tool in Google Cloud SDK
Friday, June 13, 2014
A couple of months ago, we shared some tips and tricks about bringing the power of Google Cloud Platform to your command-line using Google Cloud SDK and
Here are some guiding principles that we focused on while developing this new command-line tool. We certainly hope it will help you to be more productive with Google Compute Engine!

Great Windows support out-of-the-box
If you’re running on Windows, download and launch our new Google Cloud SDK installer. Once the installer completes, you should have
Using

To execute a process remotely on your VM, add “
To copy files to and from your instances, use
Finally, if you want to use SSH-based programs, like ssh or scp directly, run
Improved scripting support
You can easily combine individual commands into actions which would require tens of button clicks in the graphical interface, or tens of lines when programming directly against APIs. Here is a simple example.
Run the following command to list all of your virtual machine instances:
Similarly, to delete a particular VM instance (say named my-old-vm), run the following command:
Now, combine the previous two commands to delete all your VMs in us-central1-b zone:
Integrated documentation and command-line help
If you want to read a summary of a particular command’s usage, simply append

Flexible output formatting
The
Furthermore, you could use regular expressions via
Finally, if you care just about certain fields in the output, you can select them by passing “
Command suggestion and autocompletion
While (e.g. type to have it expanded to twice to see the operations which you can perform with firewall-rules. Also, if you mistype a command,
gcloud
. Today we are announcing that gcloud
family of command-line tools is being joined by gcloud compute
, a new command-line interface for Google Compute Engine.Here are some guiding principles that we focused on while developing this new command-line tool. We certainly hope it will help you to be more productive with Google Compute Engine!
Great Windows support out-of-the-box
If you’re running on Windows, download and launch our new Google Cloud SDK installer. Once the installer completes, you should have
gcloud compute
available on your system.Using
gcloud compute
you can easily connect to your VM instances, manage files and running processes on native Windows installations, as well as on Linux and Mac machines without any extra effort. For example, to SSH into your VM, simply run gcloud compute ssh INSTANCE_NAME --zone=us-central1-a
.To execute a process remotely on your VM, add “
--command
“ flag, e.g. gcloud compute ssh INSTANCE_NAME --command="ps aux" --zone=us-central1-a
.To copy files to and from your instances, use
copy-files
command:gcloud compute copy-files instance-1:file-1 instance-2:file-2 ... local-directory --zone=us-central1-a
gcloud compute copy-files file-1 file-2 ... instance:remote-directory --zone=us-central1-a
Finally, if you want to use SSH-based programs, like ssh or scp directly, run
gcloud compute config-ssh
, which will populate your per-user SSH configuration file with “Host” entries from each instance.Improved scripting support
You can easily combine individual commands into actions which would require tens of button clicks in the graphical interface, or tens of lines when programming directly against APIs. Here is a simple example.
Run the following command to list all of your virtual machine instances:
gcloud compute instances list
Similarly, to delete a particular VM instance (say named my-old-vm), run the following command:
gcloud compute instances delete my-old-vm
Now, combine the previous two commands to delete all your VMs in us-central1-b zone:
gcloud compute instances delete $(gcloud compute instances list --zone=us-central1-b)
Integrated documentation and command-line help
If you want to read a summary of a particular command’s usage, simply append
-h
to any command (for example, gcloud compute instances list -h
). Similarly, append --help
to any command to see its detailed man page entry on Linux or Mac. The detailed command-line reference for all platforms is also available on Cloud SDK’s documentation page.Flexible output formatting
The
gcloud compute instances list
example above prints detailed information about VM instances in YAML format by default. If you want to get the same data in JSON or in condensed, human-readable text formats (for example, to send it over the wire or to import it in a spreadsheet), simply pass the “--format=json
“ or “--format=text
“ flag to any list operation in gcloud compute
:gcloud compute firewall-rules list --format=text
orgcloud compute zones list --format=json
Furthermore, you could use regular expressions via
--regexp
to get information only about objects with specific names. For example, to return information about VM instances with names my-instance-1
, my-instance-2
, my-instance-3
, run the following command:gcloud compute instances list --regexp my-instance-.*
Finally, if you care just about certain fields in the output, you can select them by passing “
--fields
“ flag. For example, to see the disks attached to all your instances and their modes, run:gcloud compute instances list --fields name disks[].source disks[].mode
Command suggestion and autocompletion
While
gcloud
command-line tools are great for scripting, they’re also comfortable for humans to use. On Linux and Mac, all gcloud
commands can be autocompleted by pressing gcloud compute fi
and press gcloud compute firewall-rules
). Similarly, you can type gcloud compute firewall-rules
and press gcloud
will suggest a nearest match.
No comments :
Post a Comment