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" and then the "Registered apps" section.
  • Click the "REGISTER APP" button and give it a meaningful name.
  • Select "Web Application" and click "Register".
  • Select Certificate, then "Generate Certificate"
  • 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.
Supported commands:
# Create a few instances fro profile_name in /etc/salt/cloud.profiles - salt-cloud -p profile_name inst1 inst2 inst3 # Delete an instance - salt-cloud -d inst1 # Look up data on an instance - salt-cloud -a show_instance inst2 # List available locations (aka 'zones') for provider 'gce' - salt-cloud --list-locations gce # List available instance sizes (aka 'machine types') for provider 'gce' - salt-cloud --list-sizes gce # List available images for provider 'gce' - salt-cloud --list-images gce # Create a persistent disk - salt-cloud -f create_disk gce disk_name=pd location=us-central1-b ima... # Permanently delete a persistent disk - salt-cloud -f delete_disk gce disk_name=pd # Attach an existing disk to an existing instance - salt-cloud -a attach_disk myinstance disk_name=mydisk mode=READ_ONLY # Detach a disk from an instance - salt-cloud -a detach_disk myinstance disk_name=mydisk # Show information about the named disk - salt-cloud -a show_disk myinstance disk_name=pd - salt-cloud -f show_disk gce disk_name=pd # Create a snapshot of a persistent disk - salt-cloud -f create_snapshot gce name=snap-1 disk_name=pd # Permanently delete a disk snapshot - salt-cloud -f delete_snapshot gce name=snap-1 # Show information about the named snapshot - salt-cloud -f show_snapshot gce name=snap-1 # Create a network - salt-cloud -f create_network gce name=mynet cidr=10.10.10.0/24 # Delete a network - salt-cloud -f delete_network gce name=mynet # Show info for a network - salt-cloud -f show_network gce name=mynet # Create a firewall rule - salt-cloud -f create_fwrule gce name=fw1 network=mynet allow=tcp:80 # Delete a firewall rule - salt-cloud -f delete_fwrule gce name=fw1 # Show info for a firewall rule -salt-cloud -f show_fwrule gce name=fw1 # Create a load-balancer HTTP health check - salt-cloud -f create_hc gce name=hc path=/ port=80 # Delete a load-balancer HTTP health check - salt-cloud -f delete_hc gce name=hc # Show info about an HTTP health check - salt-cloud -f show_hc gce name=hc # Create a load-balancer configuration - salt-cloud -f create_lb gce name=lb region=us-central1 ports=80 ... # Delete a load-balancer configuration - salt-cloud -f delete_lb gce name=lb # Show details about load-balancer - salt-cloud -f show_lb gce name=lb # Add member to load-balancer - salt-cloud -f attach_lb gce name=lb member=www1 # Remove member from load-balancer - salt-cloud -f detach_lb gce name=lb member=www1
my-gce-config:
  # The Google Cloud Platform Project ID
  project: google.com:erjohnso
  # 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
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_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_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_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