Added ReCreate. Also added try catch to api eval of rpc method.
[nodemanager.git] / curlwrapper.py
1 from subprocess import PIPE, Popen
2
3
4 class CurlException(Exception): pass
5
6 def retrieve(url, cacert=None, postdata=None, timeout=300):
7     options = ('/usr/bin/curl', '--fail', '--silent')
8     if cacert: options += ('--cacert', cacert)
9     if postdata: options += ('--data', '@-')
10     if timeout: options += ('--max-time', str(timeout))
11     p = Popen(options + (url,), stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
12     if postdata: p.stdin.write(postdata)
13     p.stdin.close()
14     data = p.stdout.read()
15     err = p.stderr.read()
16     rc = p.wait()
17     if rc != 0: raise CurlException(err)
18     else: return data