Skip to content

Instantly share code, notes, and snippets.

@eizenberg
Created December 4, 2013 14:46
Show Gist options
  • Save eizenberg/7788627 to your computer and use it in GitHub Desktop.
Save eizenberg/7788627 to your computer and use it in GitHub Desktop.
Python snippet for reporting deployments to BigPanda. Useful for python-based deployment systems like ansible, fabric, etc...
import urllib2
import json
START_URL = 'https://api.bigpanda.io/data/events/deployments/start'
END_URL = 'https://api.bigpanda.io/data/events/deployments/end'
API_TOKEN = '<YOUR API TOKEN>'
HEADERS = {'Content-Type': 'application/json', 'Authorization' : 'Bearer ' + API_TOKEN}
def start_deployment(**args):
req = urllib2.Request(START_URL, json.dumps(args), HEADERS)
urllib2.urlopen(req)
def deployment_success(**args):
args["status"] = 'success'
req = urllib2.Request(END_URL, json.dumps(args), HEADERS)
urllib2.urlopen(req)
def deployment_failed(**args):
args["status"] = 'failure'
req = urllib2.Request(END_URL, json.dumps(args), HEADERS)
urllib2.urlopen(req)
# How to structure args:
# component - the affected application or component ('billing')
# version - the version of the deployment (e.g. '1.0.3')
# hosts - an array of affected hosts (e.g. ['srv1', 'srv2'])
# owner [optional]- who deployed (e.g. 'dan')
# env [optional]- the affected namespace / environment (e.g. 'prod' or 'ny datacenter')
# source - the system emitting the event (e.g. 'fabric' or 'ansible')
#
# Example:
# start_deployment(component='billing', version='1.0.3', hosts=['srv1'], owner='john', source='fabric')
# deployment_success(component='billing', version='1.0.3', hosts=['srv1'], owner='john', source='fabric')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment