1 # Copyright 2009 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 from ncclient.rpc import RPC
16 from ncclient.content import iselement
20 class EditConfig(RPC):
30 def request(self, target=None, target_url=None, config=None,
31 default_operation=None, test_option=None, error_option=None):
32 util.one_of(target, target_url)
33 spec = EditConfig.SPEC.copy()
34 params = spec['subtree']
37 'subtree': util.store_or_url(target, target_url)
43 if default_operation is not None:
45 'tag': 'default-operation',
46 'text': default_operation
48 if test_option is not None:
50 self._assert(':validate')
55 if error_option is not None:
56 if error_option == 'rollback-on-error':
57 self._assert(':rollback-on-error')
59 'tag': 'error-option',
64 class DeleteConfig(RPC):
69 'tag': 'delete-config',
70 'subtree': [ { 'tag': 'target', 'subtree': None } ]
73 def request(self, target=None, target_url=None):
74 spec = DeleteConfig.SPEC.copy()
75 spec['subtree'][0]['subtree'] = util.store_or_url(target, target_url)
76 return self._request(spec)
79 class CopyConfig(RPC):
88 def request(self, source=None, source_url=None, target=None, target_url=None):
89 spec = CopyConfig.SPEC.copy()
90 spec['subtree'].append({
92 'subtree': util.store_or_url(source, source_url)
94 spec['subtree'].append({
96 'subtree': util.store_or_url(target, target_url)
98 return self._request(spec)
106 'config attr shd not include <config> root'
108 DEPENDS = [':validate']
115 def request(self, source=None, config=None):
116 util.one_of(source, capability)
118 if source is not None:
119 spec['subtree'].append({
121 'subtree': {'tag': source}
124 spec['subtree'].append({
128 return self._request(spec)
136 DEPENDS = [':candidate']
138 SPEC = { 'tag': 'commit', 'subtree': [] }
140 def _parse_hook(self):
143 def request(self, confirmed=False, timeout=None):
146 spec['subtree'].append({'tag': 'confirmed'})
147 if timeout is not None:
148 spec['subtree'].append({
149 'tag': 'confirm-timeout',
152 return self._request(Commit.SPEC)
155 class ConfirmedCommit(Commit):
161 DEPENDS = [':candidate', ':confirmed-commit']
163 def request(self, timeout=None):
164 "Commit changes; requireing that a confirming commit follow"
165 return Commit.request(self, confirmed=True, timeout=timeout)
168 "Make the confirming commit"
169 return Commit.request(self, confirmed=True)
172 class DiscardChanges(RPC):
177 DEPENDS = [':candidate']
179 SPEC = {'tag': 'discard-changes'}