Created
October 29, 2014 23:25
-
-
Save emilssolmanis/cbb7468108f83fba34ce to your computer and use it in GitHub Desktop.
Fetch all values from etcd
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 | |
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