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