forked from Juniper/contrail-third-party
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ifmap-python-async.patch
57 lines (55 loc) · 1.76 KB
/
ifmap-python-async.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--- ifmap-python-client/ifmap/client.py.orig 2014-06-15 00:47:23.385531641 +0000
+++ ifmap-python-client/ifmap/client.py 2014-06-15 00:47:35.461538442 +0000
@@ -47,6 +47,23 @@
'meta' : "http://www.trustedcomputinggroup.org/2010/IFMAP-METADATA/2"
}
+class AsyncReadWrapper(object):
+ """ Perform the socket read in a separate greenlet """
+ def __init__(self, request):
+ self._greenlet = gevent.spawn(self.AsyncRead, request)
+ self._content = None
+
+ def AsyncRead(self, request):
+ self._content = request.read()
+
+ def __str__(self, *args, **kwargs):
+ self._greenlet.join()
+ return self._content
+
+ def __repr__(self, *args, **kwargs):
+ self._greenlet.join()
+ return self._content
+
class client:
"""
IF-MAP client
@@ -188,6 +205,30 @@
return content
except HttpException, e:
+ log.error("HTTP Connection error in IF-MAP client: %s", e.reason)
+ except Exception as e:
+ log.error("Uknown error sending IF-MAP message to server %s", str(e))
+ raise
+
+ def call_async_result(self, method, body):
+ xml = self.envelope(body)
+ base64string = base64.encodestring('%s:%s' % (self.__username, self.__password)).replace('\n', '')
+
+ # geventhttp
+ headers={
+ 'Content-type': 'text/xml; charset="UTF-8"',
+ 'Content-length': '%s' %(str(len(xml))),
+ 'Authorization': 'Basic %s' %(base64string),
+ 'SOAPAction': '%s' % (method),
+ }
+
+ try:
+ response = self._http.post('/', body = xml, headers = headers)
+ content = AsyncReadWrapper(response)
+
+ return content
+
+ except HttpException, e:
log.error("HTTP Connection error in IF-MAP client: %s", e.reason)
except:
log.error("Uknown error sending IF-MAP message to server")