Ubuntu / Debian Linux: Install gcutil Tool To Manage Google Compute Engine

by on May 19, 2013 · 0 comments· LAST UPDATED September 21, 2013

in , , ,

How do I install and use gcutil - a command-line tool that is used to manage Google Compute Engine resources under Debian or Ubuntu or CentOS/Fedora Linux desktop operating systems?

Tutorial details
DifficultyIntermediate (rss)
Root privilegesNo
RequirementsGoogle Cloud Account/Python
& Unix/Linux
Estimated completion time10m
Google Compute Engine (GCE) is an IaaS product. It uses KVM and supports Debian and CentOS Linux running on Google platform. Google Compute Engine offers a RESTful API for managing resources such as disk, images, and instances. You need to install gcutil. The system requirements are as follows:

=> Operating system: Unix or Linux or Mac OS X

=> Python version 2.7.x or 2.6.x

Download and install gcutil

Open a terminal and use the wget command to grab gcutil tar ball, enter:
$ cd /tmp
$ wget https://google-compute-engine-tools.googlecode.com/files/gcutil-1.8.0.tar.gz

Use the tar command to untar gcutil-1.8.0.tar.gz in your $HOME directory, enter:
$ tar xvf gcutil-1.8.0.tar.gz -C $HOME
Create a softlink using the ln command, type:
$ ln -s gcutil-1.8.0 gcutil
Edit the bash statups file ~/.bashrc or ~/.bash_profile, enter:
$ vi ~/.bashrc
Add gcutil to your system path variable $PATH:

 
export PATH=$PATH:~/gcutil/
 

Save and close the file. Type the following command to update your path settings:
$ source ~/.bashrc

How do I use gcutil command?

First, you need to authenticating to GCE using the OAuth 2.0 protocol. The following commands will authenticate and authorize access to GCE. Request the required auth token, enter:

 ## syntax ##
gcutil auth --project=<project ID>
gcutil auth --project=xz-model-xyzABc-N
gcutil auth --project=xz-model-xyzABc-N --credentials_file ~/gcutil/.gcutil_auth
 

Sample outputs:

Fig.01: Authenticating to Google Compute Engine using gcutil command

Fig.01: Authenticating to Google Compute Engine using gcutil command


Open a web browser, and go to the specified URL > Click the Grant Access link:
Fig.02: Grant access to GCE gcutil command line tool

Fig.02: Grant access to GCE gcutil command line tool


You will get an authorization code as follows:
Fig.03: Copy this authorization code and paste at gcutil terminal prompt

Fig.03: Copy this authorization code and paste at gcutil terminal prompt


Copy this code and paste the authorization code into the waiting gcutil auth prompt and press [enter] key (see fig.01):

The token will be saved in the file ~/.gcutil_auth. Make sure you do not give this file to anyone and keep the contents of this file private. Where,

  1. --project-id=xz-model-xyzABc-N - You will find project ID such as xz-model-xyzABc-N at https://cloud.google.com/console.
  2. --credentials_file ~/gcutil/.gcutil_auth - Stores token in the file ~/gcutil/.gcutil_auth instead of the default ~/.gcutil_auth location.

gcutil command syntax

The basic syntax is:

 
gcutil --project=xz-model-XYZABC-t --credentials_file=~/gcutil/.gcutil_auth command-Here
 

Where command-Here can be one of the following:

  1. addaccessconfig - an access config to an instance's network
  2. adddisk - new machine disks.
  3. addfirewall - Create a new firewall rule to allow incoming traffic
  4. addimage - Create a new machine image.
  5. addinstance - new VM instances.
  6. addnetwork - Create a new network instance.
  7. addroute - Create a new entry in the project's routes
  8. addsnapshot - Create a new persistent disk snapshot.
  9. attachdisk - the given persistent disk to the given
  10. auth - for forcing client authorization.
  11. config - for forcing client authorization.
  12. deleteaccessconfig - an access config from an instance's network
  13. deletedisk - one or more machine disks.
  14. deletefirewall - one or more firewall rules.
  15. deleteimage - one or more machine images.
  16. deleteinstance - one or more VM instances.
  17. deletenetwork - one or more machine networks.
  18. deleteoperation - one or more operations.
  19. deleteroute - one or more objects from the routes
  20. deletesnapshot - one or more machine snapshots.
  21. deprecateimage - the deprecation status for an image.
  22. detachdisk - the given persistent disk from the given
  23. getaddress - Get a reserved address resource.
  24. getdisk - a machine disk.
  25. getfirewall - Get a firewall.
  26. getimage - Get a machine image.
  27. getinstance - Get a machine instance.
  28. getkernel - a kernel.
  29. getmachinetype - Get a machine type.
  30. getnetwork - a network instance.
  31. getoperation - an operation resource.
  32. getproject - the resource for a Google Compute Engine project.
  33. getregion - a region.
  34. getroute - a route.
  35. getserialportoutput - the output of an instance's serial port.
  36. getsnapshot - Get a machine snapshot.
  37. getzone - a zone.
  38. help - for all or selected command:
  39. listaddresses - the addresses for a project.
  40. listdisks - the disks for a project.
  41. listfirewalls - the firewall rules for a project.
  42. listimages - the images for a project.
  43. listinstances - the instances for a project.
  44. listkernels - the kernels for a project.
  45. listmachinetypes - the machine types for a project.
  46. listnetworks - the networks for a project.
  47. listoperations - the operations for a project.
  48. listregions - available regions for a project.
  49. listroutes - the routes collection for a project.
  50. listsnapshots - the machine snapshots for a project.
  51. listzones - available zones for a project.
  52. moveinstances - Move a set of instances from one zone to another
  53. pull - one or more files from an instance.
  54. push - one or more files to an instance.
  55. releaseaddress - one or more reserved address.
  56. reserveaddress - Reserve a new ip address.
  57. resumemove - a previously-failed move.
  58. setcommoninstancemetadata - the commonInstanceMetadata field for a Google
  59. setinstancemetadata - Sets instance metadata and sends new metadata to
  60. setinstancetags - Sets instance tags and sends new tags to the
  61. ssh - to an instance.
  62. version - the current version of this command.

gcutil command examples

To list available Linux images or distro, enter:
$ gcutil --project=xz-model-XYZABC-t --credentials_file=~/gcutil/.gcutil_auth listimages
Sample outputs:

+----------------------------------------------------------------+----------------------------------------------------------------+-------------+--------+
|                              name                              |                          description                           | deprecation | status |
+----------------------------------------------------------------+----------------------------------------------------------------+-------------+--------+
| projects/centos-cloud/global/images/centos-6-v20130515         | SCSI-enabled CentOS 6; Created Wed, 15 May 2013 00:00:00 +0000 |             | READY  |
| projects/debian-cloud/global/images/debian-6-squeeze-v20130515 | Debian GNU/Linux 6.0.7 (squeeze) built on 2013-05-15           |             | READY  |
| projects/debian-cloud/global/images/debian-7-wheezy-v20130515  | Debian GNU/Linux 7.0 (wheezy) built on 2013-05-15              |             | READY  |
+----------------------------------------------------------------+----------------------------------------------------------------+-------------+--------+

To see of all running instances, enter:
$ gcutil --project=xz-model-XYZABC-t --credentials_file=~/gcutil/.gcutil_auth listinstances
Sample outputs:

Items in zones/us-central1-a:
+---------------+-------------------------------------+-------+---------+--------------+-----------------+----------------------------------------+---------------+---------+----------------+
|     name      |            machine-type             | image | network |  network-ip  |   external-ip   |                 disks                  |     zone      | status  | status-message |
+---------------+-------------------------------------+-------+---------+--------------+-----------------+----------------------------------------+---------------+---------+----------------+
| cbz-rpm-build | us-central1-a/machineTypes/f1-micro |       | default | 10.240.0.152 | 173.255.114.243 | us-central1-a/disks/boot-cbz-rpm-build | us-central1-a | RUNNING |                |
+---------------+-------------------------------------+-------+---------+--------------+-----------------+----------------------------------------+---------------+---------+----------------+
Items in zones/us-central1-b:
+--------------------+------------------------------------------------------------------+
|        code        |                             message                              |
+--------------------+------------------------------------------------------------------+
| NO_RESULTS_ON_PAGE | There are no results for scope ..es/us-central1-b' on this page. |
+--------------------+------------------------------------------------------------------+
Items in zones/europe-west1-a:
+--------------------+------------------------------------------------------------------+
|        code        |                             message                              |
+--------------------+------------------------------------------------------------------+
| NO_RESULTS_ON_PAGE | There are no results for scope ..s/europe-west1-a' on this page. |
+--------------------+------------------------------------------------------------------+
Items in zones/europe-west1-b:
+--------------------+------------------------------------------------------------------+
|        code        |                             message                              |
+--------------------+------------------------------------------------------------------+
| NO_RESULTS_ON_PAGE | There are no results for scope ..s/europe-west1-b' on this page. |
+--------------------+------------------------------------------------------------------+
Items in zones/us-central2-a:
+--------------------+------------------------------------------------------------------+
|        code        |                             message                              |
+--------------------+------------------------------------------------------------------+
| NO_RESULTS_ON_PAGE | There are no results for scope ..es/us-central2-a' on this page. |
+--------------------+------------------------------------------------------------------+
References:
  • Type the following command to see the list of available commands.
    $ gcutil help
  • Run gcutil help {command-name} to get help for {command-name}:
    gcutil help ssh
    gcutil help auth
  • gcutil Tool help page.
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: , , , , , ,

Previous Faq:

Next Faq: