Skip to content

Instantly share code, notes, and snippets.

@chiradeep
Created June 5, 2014 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save chiradeep/a328d6be002f70c50d07 to your computer and use it in GitHub Desktop.
Save chiradeep/a328d6be002f70c50d07 to your computer and use it in GitHub Desktop.
Python script to diff 2 global configurations in CloudStack
# This script takes 2 json files as input. The json file describes the global configuration of a CloudStack installation
# To generate a json file of the configuration, use cloudmonkey:
#
# cloudmonkey -c staging.cfg
# > set display json
# > exit
# cloudmonkey -c production.cfg
# > set display json
# > exit
# cloudmonkey -c staging.cfg list configurations > staging.json
# cloudmonkey -c production.cfg list configurations > production.json
import json
def json_to_dict(jsonfile):
j = json.load(open(jsonfile, 'rb'))
a1 = map(lambda x: {x['name']: x.get('value')}, j['configuration'])
a2 = reduce( lambda x, y: x.update(y) or x, a1, {})
return a2
def print_diff(cfg1, cfg2):
diffkeys = [k for k in cfg1 if cfg1[k] != cfg2[k]]
for k in diffkeys:
print k, ':', cfg1[k], '->', cfg2[k]
print_diff(json_to_dict('staging.json'), json_to_dict('production.json'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment