Revision 1fca349b ncclient/operations/session.py

b/ncclient/operations/session.py
15 15
'Session-related NETCONF operations'
16 16

  
17 17
from rpc import RPC
18
from copy import deepcopy
18 19

  
19 20
class CloseSession(RPC):
20 21
    
21 22
    'CloseSession is always synchronous'
22 23
    
23
    def __init__(self, *args, **kwds):
24
        RPC.__init__(self, *args, **kwds)
25
        self.spec = { 'tag': 'close-session' }
24
    SPEC = { 'tag': 'close-session' }
26 25
    
27 26
    def _delivery_hook(self):
28 27
        if self.reply.ok:
......
30 29
        self.session.close()
31 30
    
32 31
    def request(self):
33
        return self._request(self.spec)
32
        return self._request(CloseSession.SPEC)
34 33

  
35 34

  
36 35
class KillSession(RPC):
37 36
    
38
    def __init__(self, *args, **kwds):
39
        RPC.__init__(self, *args, **kwds)
40
        self.spec = {
41
            'tag': 'kill-session',
42
            'children': [ { 'tag': 'session-id', 'text': None} ]
43
            }
37
    SPEC = {
38
        'tag': 'kill-session',
39
        'children': [ { 'tag': 'session-id', 'text': None} ]
40
    }
44 41
    
45 42
    def request(self, session_id):
46
        if not isinstance(session_id, basestring): # just make sure...
43
        if not isinstance(session_id, basestring): # just making sure...
47 44
            session_id = str(session_id)
48
        self.spec['children'][0]['text'] = session_id
49
        return self._request(self.spec)
45
        spec = deepcopy(SPEC)
46
        spec['children'][0]['text'] = session_id
47
        return self._request(spec)

Also available in: Unified diff