Revision 10d68bc5 src/operations.py
b/src/operations.py | ||
---|---|---|
12 | 12 |
# See the License for the specific language governing permissions and |
13 | 13 |
# limitations under the License. |
14 | 14 |
|
15 |
from listener import Listener |
|
16 | 15 |
|
17 | 16 |
from threading import Event |
18 | 17 |
|
19 | 18 |
class OperationError(NETCONFError): pass |
20 | 19 |
|
21 |
class RPC: |
|
22 |
pass |
|
23 |
|
|
24 |
class RPCRequest(RPC): |
|
25 |
|
|
26 |
cur_msg_id = {} |
|
27 |
|
|
28 |
@cls |
|
29 |
def next_id(cls, session_id): |
|
30 |
cur_msg_id[session_id] = cur_msg_id.get(session_id, 0) + 1 |
|
31 |
return cur_msg_id[session_id] |
|
32 |
|
|
33 |
def __init__(self): |
|
34 |
self._reply = None |
|
35 |
self._event = Event() |
|
36 |
self._async = None |
|
37 |
|
|
38 |
def get_reply(self, timeout=2.0): |
|
39 |
self._event.wait(timeout) |
|
40 |
if self._event.isSet(): |
|
41 |
return self._reply |
|
42 |
|
|
43 |
def do(self, session, async=False): |
|
44 |
self._async = async |
|
45 |
|
|
46 |
@property |
|
47 |
def async(self): |
|
48 |
return self._async |
|
49 |
|
|
50 |
class RPCReply(RPC): |
|
51 |
pass |
|
52 |
|
|
53 |
class RPCError(OperationError): |
|
54 |
pass |
|
55 | 20 |
|
56 | 21 |
class Operation(RPCRequest): |
57 | 22 |
pass |
58 | 23 |
|
59 |
class ReplyListener(Listener): |
|
60 |
|
|
61 |
def __init__(self): |
|
62 |
self._id2op = {} |
|
63 |
|
|
64 |
def reply(self, msg): |
|
65 |
# if all good: |
|
66 |
op = id2op[id] |
|
67 |
op._reply = parsed_msg |
|
68 |
# else: |
|
69 |
self._error = True |
|
70 |
|
|
71 |
op._event.set() |
|
72 |
pass |
|
73 |
|
|
74 |
def error(self, buf): |
|
75 |
pass |
Also available in: Unified diff