Git Product home page Git Product logo

stratosphere's Introduction

Stratosphere

A library and tool for creating Google Cloud Platform Deployment Manager templates.

Stratosphere is inspired by Troposphere for AWS.

Features

  • Lets you write pure python
  • Includes property and type validation
  • Interacts directly with the GCP Deployment Manager API without having to use the clunky gcloud CLI
  • Highly opinionated about naming to enforce consistent naming across deployments

Installation

Git clone this repository, then:

# python setup.py install

You'll need to get a valid OAuth auth JSON file to interact with the GCP DM API. This is most easily done by just installing the GCP API Client Library for Python.

Examples

See the example_templates directory for how to build a template.

$ stratosphere --project [MyGCPProject] --env dev --action template ./example_templates/networks.py
resources:
- name: dev-network
  properties: {autoCreateSubnetworks: false, description: dev-networks - MultiAZ Network}
  type: compute.v1.network
- name: dev-us-central1-b-subnetwork
  properties: {description: dev - us-central1-b Subnetwork, ipCidrRange: 10.100.0.0/20,
    network: $(ref.dev-network.selfLink), region: us-central1}
  type: compute.v1.subnetworks
- name: dev-us-central1-c-subnetwork
  properties: {description: dev - us-central1-c Subnetwork, ipCidrRange: 10.100.16.0/20,
    network: $(ref.dev-network.selfLink), region: us-central1}
  type: compute.v1.subnetworks
- name: dev-us-central1-f-subnetwork
  properties: {description: dev - us-central1-f Subnetwork, ipCidrRange: 10.100.32.0/20,
    network: $(ref.dev-network.selfLink), region: us-central1}
  type: compute.v1.subnetworks

This reads the networks.py template and generates a valid Google Compute Engine Deployment Manager YAML config, reading values from a constants.py that is shared across your deployments.

Local Validation Examples

Stratosphere resources know about required parameters, so if you define a resource that is missing a parameter or has an invalid field, you'll get an error like this (without having to wait for the Deployment Manager error).

Template defining a Firewall snippet:
Firewall(
    name='{}-ssh'.format(self.env),
    network="projects/{}/global/networks/{}".format(names.project, names.networkName),
    allowed=[
        FirewallAllowedPorts(
            IPProtocol=FirewallAllowedPorts.TCP,
            ports=[
                '22'
            ]
        ),
    ]
)

Results in this error:

ValueError: Either sourceRanges or sourceTags must be defined
Name field validation
for subnetwork in constants.ENV[self.env]['subnetworks']:
    self.add_resource(
        Subnetwork(
            name='SUBNETWORk-{}'.format(names.subnetworkName(subnetwork['zone'])),
            region=names.zone_to_region(subnetwork['zone']),
            description='{} - {} Subnetwork'.format(names.networkName, subnetwork['zone']),
            ipCidrRange=subnetwork['cidr'],
            network=network.Ref
        )
    )

Results in this error (only lowercase characters are allowed in names):

TypeError: <class 'stratosphere.compute.Subnetwork'>: name is SUBNETWORk-mynetwork-us-central1-b-subnetwork, expected values defined in function:
    @staticmethod
    def name(name):
        return ResourceValidators.regex_match('^(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)$', name)

License

Apache 2.0 - See LICENSE for more information.

stratosphere's People

Contributors

thecubed avatar victortrac avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.