1 # Copyright 2h009 Shikhar Bhushan
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 'Locking-related NETCONF operations'
17 from copy import deepcopy
19 from rpc import RPC, RPCReply, RPCError
21 #class LockReply(RPCReply):
23 # ERROR_CLS = LockDeniedError
25 #class LockDeniedError(RPCError):
27 # def __new__(cls, err_dict):
28 # if rpcerr['tag'] != 'lock-denied':
29 # return RPCError(err_dict)
31 # return object.__new__(LockDeniedError)
33 # def __init__(self, err_dict):
34 # RPCError.__init__(self, err_dict)
46 'subtree': {'tag': None }
50 #REPLY_CLS = LockReply
52 def request(self, target):
54 :arg target: see :ref:`source_target`
59 spec = deepcopy(Lock.SPEC)
60 spec['subtree']['subtree']['tag'] = target
61 return self._request(spec)
74 'subtree': {'tag': None }
78 def request(self, target):
80 :arg target: see :ref:`source_target`
85 spec = deepcopy(Unlock.SPEC)
86 spec['subtree']['subtree']['tag'] = target
87 return self._request(spec)
95 A context manager for the :class:`Lock` / :class:`Unlock` pair of RPC's.
97 Initialise with session instance (:class:`Session
98 <ncclient.transport.Session>`) and lock target (:ref:`source_target`)
101 def __init__(self, session, target):
102 self.session = session
106 reply = Lock(self.session).request(self.target)
112 def __exit__(self, *args):
113 reply = Unlock(self.session).request(self.target)