root / src / session.py @ fd40449b
History | View | Annotate | Download (1.6 kB)
1 |
# Copyright 2009 Shikhar Bhushan
|
---|---|
2 |
#
|
3 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
# you may not use this file except in compliance with the License.
|
5 |
# You may obtain a copy of the License at
|
6 |
#
|
7 |
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
#
|
9 |
# Unless required by applicable law or agreed to in writing, software
|
10 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
# See the License for the specific language governing permissions and
|
13 |
# limitations under the License.
|
14 |
|
15 |
import threading |
16 |
|
17 |
class SessionError(NETCONFClientError): pass |
18 |
|
19 |
class Session(threading.Thread): |
20 |
|
21 |
def __init__(self, capabilities, reply_cb): |
22 |
Thread.__init__(self)
|
23 |
self.capabilities = {
|
24 |
'client': capabilities,
|
25 |
'server': None #yet |
26 |
} |
27 |
self._q = Queue.Queue()
|
28 |
self._cb = reply_cb
|
29 |
self.id = None # session-id |
30 |
self.connected = False |
31 |
|
32 |
def _make_hello(self): |
33 |
# <capabilities> should be repr(capabilities['client'])
|
34 |
# rest, hmm..
|
35 |
pass
|
36 |
|
37 |
def _init(self, msg): |
38 |
# session-id =
|
39 |
# capabilities['server'] =
|
40 |
self.connected = True |
41 |
|
42 |
def connect(self): |
43 |
self.start()
|
44 |
|
45 |
def run(self): |
46 |
raise NotImplementedError |
47 |
|
48 |
def send(self, msg): |
49 |
if self.connected: |
50 |
self._q.add(msg)
|
51 |
else:
|
52 |
raise SessionError('''Attempted to send message before |
53 |
NETCONF session initialisation''')
|
54 |
|