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):
27 def request(self, target=None, target_url=None, config=None,
28 default_operation=None, test_option=None, error_option=None):
29 util.one_of(target, target_url)
30 spec = EditConfig.SPEC.copy()
31 params = spec['children']
32 params.append({'tag': 'target', 'children': util.store_or_url(target, target_url)})
33 params.append({'tag': 'config', 'children': config})
34 if default_operation is not None:
35 params.append({'tag': 'default-operation', 'text': default_operation})
36 if test_option is not None:
37 params.append({'tag': 'test-option', 'text': test_option})
38 if error_option is not None:
39 params.append({'tag': 'test-option', 'text': test_option})
41 class DeleteConfig(RPC):
44 'tag': 'delete-config',
45 'children': [ { 'tag': 'target', 'children': None } ]
48 def request(self, target=None, target_url=None):
49 spec = DeleteConfig.SPEC.copy()
50 spec['children'][0]['children'] = util.store_or_url(target, target_url)
51 return self._request(spec)
54 class CopyConfig(RPC):
59 { 'tag': 'source', 'children': {'tag': None } },
60 { 'tag': 'target', 'children': {'tag': None } }
64 def request(self, source=None, source_url=None, target=None, target_url=None):
65 spec = CopyConfig.SPEC.copy()
66 spec['children'][0]['children'] = util.store_or_url(source, source_url)
67 spec['children'][1]['children'] = util.store_or_url(target, target_url)
68 return self._request(spec)
73 'config attr shd not include <config> root'
75 DEPENDS = [':validate']
82 def request(self, source=None, config=None):
83 util.one_of(source, capability)
85 if source is not None:
86 spec['children'].append({
87 'tag': 'source', 'children': {'tag': source}
90 spec['children'].append({'tag': 'config', 'children': config})
91 return self._request(spec)
96 DEPENDS = [':candidate']
98 SPEC = {'tag': 'commit', 'children': [] }
100 def _parse_hook(self):
103 def request(self, confirmed=False, timeout=None):
106 self._assert(':confirmed-commit')
107 children = spec['children']
108 children.append({'tag': 'confirmed'})
109 if timeout is not None:
111 'tag': 'confirm-timeout',
114 return self._request(Commit.SPEC)
117 class DiscardChanges(RPC):
119 DEPENDS = [':candidate']
121 SPEC = {'tag': 'discard-changes'}
123 request = lambda self: self._request(DiscardChanges.SPEC)