Created
December 4, 2013 14:46
-
-
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...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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