Skip to content

Instantly share code, notes, and snippets.

@emilssolmanis
Created October 29, 2014 23:25
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 emilssolmanis/cbb7468108f83fba34ce to your computer and use it in GitHub Desktop.
Save emilssolmanis/cbb7468108f83fba34ce to your computer and use it in GitHub Desktop.
Fetch all values from etcd
import urllib2
import json
import sys
ROOT = 'http://localhost:4001/v2/keys'
def walk_this_way(path):
response = urllib2.urlopen(ROOT + path)
content = json.load(response)
node = content['node']
if node.get('dir'):
children = node['nodes']
values = []
for child in children:
values += walk_this_way(child['key'])
return values
else:
return [(node['key'], node['value'])]
def main():
for key, value in walk_this_way(sys.argv[1]):
print('%s=%s' % (key[1:].replace('/', '.'), value))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment