salt.cloud.clouds.gce

Copyright 2013 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Google Compute Engine Module

The Google Compute Engine module. This module interfaces with Google Compute Engine. To authenticate to GCE, you will need to create a Service Account.

Setting up Service Account Authentication:
  • Go to the Cloud Console at: https://cloud.google.com/console.
  • Create or navigate to your desired Project.
  • Make sure Google Compute Engine service is enabled under the Services section.
  • Go to "APIs and auth" section, and then the "Credentials" link.
  • Click the "CREATE NEW CLIENT ID" button.
  • Select "Service Account" and click "Create Client ID" button.
  • This will automatically download a .json file; ignore it.
  • Look for a new "Service Account" section in the page, click on the "Generate New P12 key" button
  • Copy the Email Address for inclusion in your /etc/salt/cloud file in the 'service_account_email_address' setting.
  • Download the Private Key
  • The key that you download is a PKCS12 key. It needs to be converted to the PEM format.
  • Convert the key using OpenSSL (the default password is 'notasecret'): C{openssl pkcs12 -in PRIVKEY.p12 -passin pass:notasecret -nodes -nocerts | openssl rsa -out ~/PRIVKEY.pem}
  • Add the full path name of the converted private key to your /etc/salt/cloud file as 'service_account_private_key' setting.
  • Consider using a more secure location for your private key.
my-gce-config:
  # The Google Cloud Platform Project ID
  project: "my-project-id"
  # The Service ACcount client ID
  service_account_email_address: 1234567890@developer.gserviceaccount.com
  # The location of the private key (PEM format)
  service_account_private_key: /home/erjohnso/PRIVKEY.pem
  provider: gce
  # Specify whether to use public or private IP for deploy script.
  # Valid options are:
  #     private_ips - The salt-master is also hosted with GCE
  #     public_ips - The salt-master is hosted outside of GCE
  ssh_interface: public_ips
maintainer:Eric Johnson <erjohnso@google.com>
maturity:new
depends:libcloud >= 0.14.1
depends:pycrypto >= 2.1
salt.cloud.clouds.gce.attach_disk(name=None, kwargs=None, call=None)

Attach an existing disk to an existing instance.

CLI Example:

salt-cloud -a attach_disk myinstance disk_name=mydisk mode=READ_WRITE
salt.cloud.clouds.gce.attach_lb(kwargs=None, call=None)

Add an existing node/member to an existing load-balancer configuration.

CLI Example:

salt-cloud -f attach_lb gce name=lb member=myinstance
salt.cloud.clouds.gce.avail_images(conn=None)

Return a dict of all available VM images on the cloud provider with relevant data

Note that for GCE, there are custom images within the project, but the generic images are in other projects. This returns a dict of images in the project plus images in 'debian-cloud' and 'centos-cloud' (If there is overlap in names, the one in the current project is used.)

salt.cloud.clouds.gce.avail_locations(conn=None, call=None)

Return a dict of all available VM locations on the cloud provider with relevant data

salt.cloud.clouds.gce.avail_sizes(conn=None)

Return a dict of available instances sizes (a.k.a machine types) and convert them to something more serializable.

salt.cloud.clouds.gce.create(vm_=None, call=None)

Create a single GCE instance from a data dict.

salt.cloud.clouds.gce.create_address(kwargs=None, call=None)

Create a static address in a region.

CLI Example:

salt-cloud -f create_address gce name=my-ip region=us-central1 address=IP
salt.cloud.clouds.gce.create_disk(kwargs=None, call=None)

Create a new persistent disk. Must specify disk_name and location. Can also specify an image or snapshot but if neither of those are specified, a size (in GB) is required.

CLI Example:

salt-cloud -f create_disk gce disk_name=pd size=300 location=us-central1-b
salt.cloud.clouds.gce.create_fwrule(kwargs=None, call=None)

Create a GCE firewall rule. The 'default' network is used if not specified.

CLI Example:

salt-cloud -f create_fwrule gce name=allow-http allow=tcp:80
salt.cloud.clouds.gce.create_hc(kwargs=None, call=None)

Create an HTTP health check configuration.

CLI Example:

salt-cloud -f create_hc gce name=hc path=/healthy port=80
salt.cloud.clouds.gce.create_lb(kwargs=None, call=None)

Create a load-balancer configuration.

CLI Example:

salt-cloud -f create_lb gce name=lb region=us-central1 ports=80
salt.cloud.clouds.gce.create_network(kwargs=None, call=None)

Create a GCE network.

CLI Example:

salt-cloud -f create_network gce name=mynet cidr=10.10.10.0/24
salt.cloud.clouds.gce.create_snapshot(kwargs=None, call=None)

Create a new disk snapshot. Must specify name and disk_name.

CLI Example:

salt-cloud -f create_snapshot gce name=snap1 disk_name=pd
salt.cloud.clouds.gce.delete_address(kwargs=None, call=None)

Permanently delete a static address.

CLI Example:

salt-cloud -f delete_address gce name=my-ip
salt.cloud.clouds.gce.delete_disk(kwargs=None, call=None)

Permanently delete a persistent disk.

CLI Example:

salt-cloud -f delete_disk gce disk_name=pd
salt.cloud.clouds.gce.delete_fwrule(kwargs=None, call=None)

Permanently delete a firewall rule.

CLI Example:

salt-cloud -f delete_fwrule gce name=allow-http
salt.cloud.clouds.gce.delete_hc(kwargs=None, call=None)

Permanently delete a health check.

CLI Example:

salt-cloud -f delete_hc gce name=hc
salt.cloud.clouds.gce.delete_lb(kwargs=None, call=None)

Permanently delete a load-balancer.

CLI Example:

salt-cloud -f delete_lb gce name=lb
salt.cloud.clouds.gce.delete_network(kwargs=None, call=None)

Permanently delete a network.

CLI Example:

salt-cloud -f delete_network gce name=mynet
salt.cloud.clouds.gce.delete_snapshot(kwargs=None, call=None)

Permanently delete a disk snapshot.

CLI Example:

salt-cloud -f delete_snapshot gce name=disk-snap-1
salt.cloud.clouds.gce.destroy(vm_name, call=None)

Call 'destroy' on the instance. Can be called with "-a destroy" or -d

CLI Example:

salt-cloud -a destroy myinstance1 myinstance2 ...
salt-cloud -d myinstance1 myinstance2 ...
salt.cloud.clouds.gce.detach_disk(name=None, kwargs=None, call=None)

Detach a disk from an instance.

CLI Example:

salt-cloud -a detach_disk myinstance disk_name=mydisk
salt.cloud.clouds.gce.detach_lb(kwargs=None, call=None)

Remove an existing node/member from an existing load-balancer configuration.

CLI Example:

salt-cloud -f detach_lb gce name=lb member=myinstance
salt.cloud.clouds.gce.get_configured_provider()

Return the first configured instance.

salt.cloud.clouds.gce.get_conn()

Return a conn object for the passed VM data

salt.cloud.clouds.gce.get_lb_conn(gce_driver=None)

Return a load-balancer conn object

salt.cloud.clouds.gce.list_nodes(conn=None, call=None)

Return a list of the VMs that are on the provider

salt.cloud.clouds.gce.list_nodes_full(conn=None, call=None)

Return a list of the VMs that are on the provider, with all fields

salt.cloud.clouds.gce.list_nodes_select(conn=None, call=None)

Return a list of the VMs that are on the provider, with select fields

salt.cloud.clouds.gce.reboot(vm_name, call=None)

Call GCE 'reset' on the instance.

CLI Example:

salt-cloud -a reboot myinstance
salt.cloud.clouds.gce.script(vm_)

Return the script deployment object

salt.cloud.clouds.gce.show_address(kwargs=None, call=None)

Show the details of an existing static address.

CLI Example:

salt-cloud -f show_address gce name=mysnapshot region=us-central1
salt.cloud.clouds.gce.show_disk(name=None, kwargs=None, call=None)

Show the details of an existing disk.

CLI Example:

salt-cloud -a show_disk myinstance disk_name=mydisk
salt-cloud -f show_disk gce disk_name=mydisk
salt.cloud.clouds.gce.show_fwrule(kwargs=None, call=None)

Show the details of an existing firewall rule.

CLI Example:

salt-cloud -f show_fwrule gce name=allow-http
salt.cloud.clouds.gce.show_hc(kwargs=None, call=None)

Show the details of an existing health check.

CLI Example:

salt-cloud -f show_hc gce name=hc
salt.cloud.clouds.gce.show_instance(vm_name, call=None)

Show the details of the existing instance.

salt.cloud.clouds.gce.show_lb(kwargs=None, call=None)

Show the details of an existing load-balancer.

CLI Example:

salt-cloud -f show_lb gce name=lb
salt.cloud.clouds.gce.show_network(kwargs=None, call=None)

Show the details of an existing network.

CLI Example:

salt-cloud -f show_network gce name=mynet
salt.cloud.clouds.gce.show_snapshot(kwargs=None, call=None)

Show the details of an existing snapshot.

CLI Example:

salt-cloud -f show_snapshot gce name=mysnapshot