Package backend :: Module callback
[hide private]
[frames] | no frames]

Source Code for Module backend.callback

 1  import json 
 2  import requests 
 3   
4 -class FrontendCallback(object):
5 """ Object to send data back to fronted """ 6
7 - def __init__(self, opts):
8 super(FrontendCallback, self).__init__() 9 self.frontend_url = opts.frontend_url 10 self.frontend_auth = opts.frontend_auth 11 self.msg = None
12
13 - def post_to_frontend(self, data):
14 """ Send data to frontend """ 15 headers = {'content-type': 'application/json'} 16 url = '%s/update/' % self.frontend_url 17 auth = ('user', self.frontend_auth) 18 19 self.msg = None 20 try: 21 r = requests.post(url, data=json.dumps(data), auth=auth, 22 headers=headers) 23 if r.status_code != 200: 24 self.msg = 'Failed to submit to frontend: %s: %s' % (r.status_code, r.text) 25 except requests.RequestException, e: 26 self.msg = 'Post request failed: %s' % e 27 28 if self.msg: 29 return False 30 else: 31 return True
32