Skip to content

Instantly share code, notes, and snippets.

@HarryR
Created August 9, 2011 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HarryR/1134043 to your computer and use it in GitHub Desktop.
Save HarryR/1134043 to your computer and use it in GitHub Desktop.
Ultra-minimal serverdensity api
"""
The server density API is so easy with a shake of jsonpath :)
Example:
groups = sdapi.call('servers/listGroups', '$..groups')
web_server_ids = sdapi.call('servers/getByGroup', '$..serverId', group='Web')
For a jsonpath reference, try: http://code.google.com/p/jsonpath/wiki/Javascript
"""
import urllib
import json
import jsonpath
def call(command, _jsonpath_expr, **kwargs):
kwargs['account'] = 'account-name.serverdensity.com'
kwargs['c'] = command
params = urllib.urlencode(kwargs)
f = urllib.urlopen("https://username:password@api.serverdensity.com/1.2/?"+params)
o = json.loads(f.read())
found = jsonpath.jsonpath(o, _jsonpath_expr)
return found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment