Disallow multiple conf_files instances and have conf_files use curl with certificates.
[nodemanager.git] / curlwrapper.py
1 from subprocess import PIPE, Popen
2
3
4 class CurlException(Exception): pass
5
6 def retrieve(url, postdata=None):
7     options = ('/usr/bin/curl', '--cacert', '/usr/boot/cacert.pem')
8     if postdata: options += ('--data', '@-')
9     p = Popen(options + (url,), stdin=PIPE, stdout=PIPE, stderr=PIPE)
10     if postdata: p.stdin.write(postdata)
11     p.stdin.close()
12     data = p.stdout.read()
13     err = p.stderr.read()
14     rc = p.wait()
15     if rc != 0: raise CurlException(err)
16     else: return data