Created
August 9, 2011 13:31
-
-
Save HarryR/1134043 to your computer and use it in GitHub Desktop.
Ultra-minimal serverdensity api
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
""" | |
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