Skip to main content

Python helper around gcloud

Project description

Purpose

Wouldn't be nice to script your GCP infrastructure without having to learn a new language ?

Description

This package simplifies the deployment of GCP services through the gcloud command line.

Installation

pip install pygcloud

Features

  • Leverage gcloud command line tool
  • Be as transparent to gcloud as possible
  • Capability to group deployment of services together
  • Capability to describe relationships between services
  • Capability to perform trial run

Enabling Features

  • Infrastructure governance
  • Diagramming

The above features are supported by employing the after_* methods of the GCPService class.

Categories of Services

  1. SingletonImmutable e.g. Firestore indexes
  2. RevisionBased e.g. Cloud Run service with revisions
  3. Updatable e.g. GCS bucket

For the "SingletonImmutable" category, we ignore exceptions arising from the service already being created. The "describe" facility might be or not available.

For the "RevisionBased", we skip the "update" step. The "create" method will be called. The "describe" facility might be or not available.

For the "Updatable", we do the complete steps i.e. describe, create or update.

Example Usage

from pygcloud.models import Param, EnvParam
from pygcloud.gcp.services.storage import StorageBucket
from pygcloud.deployer import Deployer

# Retrieve parameter from environment variables
# Useful in the context of using Cloud Build
project_id = EnvParam("--project", "_PROJECT_ID")

# The 'common_params' will be added at the end of the gcloud command
# The Deployer can be reused for multiple services
deployer = Deployer(common_params=[project_id])

# The first parameter is the name. Most services require a unique name.
# The second parameter is a list of parameters added to the gcloud command.
bucket = StorageBucket("my-bucket", ["--public-access-prevention"])

# Deploy the service
# For Storage Buckets, an existence check is done using the `describe` gcloud command
# before creating or updating the bucket.
deployer.deploy(bucket)

Additional usage tips can be found in the tests/gcp.services folder.

Use relationships

pygcloud supports specifying relationships between services. These are captured in the service instance labels.

The relation type use is defined directionally i.e. from one service to another. It is envisaged to be pertinent in the context of an application running on a compute related service (e.g. Cloud Run) utilizing another service (e.g. GCS).

About GCP Labels

Labels optionally carry the "use" relationships between service instances.

We work with the limitations (i.e. 64 entries, unique key names, value length limited to 63 characters) of GCP's labeling capability in the following manner:

  1. Each relationship takes 1 label
  2. Each label key is composed like so: pygcloud-use-$index
  3. The corresponding label value: $ns--$name

The field $name is sometimes encoded since the value contains characters not supported by GCP. Encoding strategy in these cases is always the same (bas64 with custom alphabet, padding = removed).

About Regions

Some services are more difficult to inventory than others. This is the case for Cloud Scheduler for example: gloud scheduler jobs list command requires specifying the --location where to perform the listing.

About Python 3.9

The gcloud command line is currently built for Python 3.9. The accompanied Docker image provided by Google is built for Python 3.9. To simplify usage of pygcloud, I opted to follow this gcloud constraint.

TODO

  • File bug report about GCS not supporting --clear-labels along with --update-labels (as in Cloud Run as example)
  • File bug report about Cloud Scheduler listing requiring --location (whilst most other services do not)

Links

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygcloud-0.0.53.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygcloud-0.0.53-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file pygcloud-0.0.53.tar.gz.

File metadata

  • Download URL: pygcloud-0.0.53.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for pygcloud-0.0.53.tar.gz
Algorithm Hash digest
SHA256 fbb31eff38cd21293b61a21f88e79ac4e5aac94808b2885ef53d2e92396ed5fd
MD5 72f9dfb736c47972e3ecff1a211a991e
BLAKE2b-256 a9e98f75c55d0a0a8ddf89d3ed8ed39a050813e106721ed519b2f84a53c1ed81

See more details on using hashes here.

File details

Details for the file pygcloud-0.0.53-py3-none-any.whl.

File metadata

  • Download URL: pygcloud-0.0.53-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for pygcloud-0.0.53-py3-none-any.whl
Algorithm Hash digest
SHA256 e7114adf460719a95ed2b7113e1d343568003a9bd6087baa0b40051c5f4946e6
MD5 9ae0210e7c964dcd830a30fefc693dc7
BLAKE2b-256 8c0e3dab39e82dd71c3ae70d4ed30e1bf31bbf163dc55258a77e868e78a6ffbe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page