Revision 179b00d4 ncclient/operations/edit.py
b/ncclient/operations/edit.py | ||
---|---|---|
19 | 19 |
|
20 | 20 |
class EditConfig(RPC): |
21 | 21 |
|
22 |
# tested: no |
|
23 |
# combed: no |
|
24 |
|
|
22 | 25 |
SPEC = { |
23 | 26 |
'tag': 'edit-config', |
24 |
'children': [ ]
|
|
27 |
'subtree': []
|
|
25 | 28 |
} |
26 | 29 |
|
27 | 30 |
def request(self, target=None, target_url=None, config=None, |
28 | 31 |
default_operation=None, test_option=None, error_option=None): |
29 | 32 |
util.one_of(target, target_url) |
30 | 33 |
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 |
params = spec['subtree'] |
|
35 |
params.append({ |
|
36 |
'tag': 'target', |
|
37 |
'subtree': util.store_or_url(target, target_url) |
|
38 |
}) |
|
39 |
params.append({ |
|
40 |
'tag': 'config', |
|
41 |
'subtree': config |
|
42 |
}) |
|
34 | 43 |
if default_operation is not None: |
35 |
params.append({'tag': 'default-operation', 'text': default_operation}) |
|
44 |
params.append({ |
|
45 |
'tag': 'default-operation', |
|
46 |
'text': default_operation |
|
47 |
}) |
|
36 | 48 |
if test_option is not None: |
37 |
params.append({'tag': 'test-option', 'text': test_option}) |
|
49 |
if test_option == '': |
|
50 |
self._assert(':validate') |
|
51 |
params.append({ |
|
52 |
'tag': 'test-option', |
|
53 |
'text': test_option |
|
54 |
}) |
|
38 | 55 |
if error_option is not None: |
39 |
params.append({'tag': 'test-option', 'text': test_option}) |
|
56 |
if error_option == 'rollback-on-error': |
|
57 |
self._assert(':rollback-on-error') |
|
58 |
params.append({ |
|
59 |
'tag': 'error-option', |
|
60 |
'text': error_option |
|
61 |
}) |
|
62 |
|
|
40 | 63 |
|
41 | 64 |
class DeleteConfig(RPC): |
42 | 65 |
|
66 |
# tested: no |
|
67 |
|
|
43 | 68 |
SPEC = { |
44 | 69 |
'tag': 'delete-config', |
45 |
'children': [ { 'tag': 'target', 'children': None } ]
|
|
70 |
'subtree': [ { 'tag': 'target', 'subtree': None } ]
|
|
46 | 71 |
} |
47 | 72 |
|
48 | 73 |
def request(self, target=None, target_url=None): |
49 | 74 |
spec = DeleteConfig.SPEC.copy() |
50 |
spec['children'][0]['children'] = util.store_or_url(target, target_url)
|
|
75 |
spec['subtree'][0]['subtree'] = util.store_or_url(target, target_url)
|
|
51 | 76 |
return self._request(spec) |
52 | 77 |
|
53 | 78 |
|
54 | 79 |
class CopyConfig(RPC): |
55 | 80 |
|
81 |
# tested: no |
|
82 |
|
|
56 | 83 |
SPEC = { |
57 | 84 |
'tag': 'copy-config', |
58 |
'children': [ |
|
59 |
{ 'tag': 'source', 'children': {'tag': None } }, |
|
60 |
{ 'tag': 'target', 'children': {'tag': None } } |
|
61 |
] |
|
85 |
'subtree': [] |
|
62 | 86 |
} |
63 | 87 |
|
64 | 88 |
def request(self, source=None, source_url=None, target=None, target_url=None): |
65 | 89 |
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) |
|
90 |
spec['subtree'].append({ |
|
91 |
'tag': 'target', |
|
92 |
'subtree': util.store_or_url(source, source_url) |
|
93 |
}) |
|
94 |
spec['subtree'].append({ |
|
95 |
'tag': 'target', |
|
96 |
'subtree': util.store_or_url(target, target_url) |
|
97 |
}) |
|
68 | 98 |
return self._request(spec) |
69 | 99 |
|
70 | 100 |
|
71 | 101 |
class Validate(RPC): |
72 | 102 |
|
103 |
# tested: no |
|
104 |
# combed: yes |
|
105 |
|
|
73 | 106 |
'config attr shd not include <config> root' |
74 | 107 |
|
75 | 108 |
DEPENDS = [':validate'] |
76 | 109 |
|
77 | 110 |
SPEC = { |
78 | 111 |
'tag': 'validate', |
79 |
'children': []
|
|
112 |
'subtree': []
|
|
80 | 113 |
} |
81 | 114 |
|
82 | 115 |
def request(self, source=None, config=None): |
83 | 116 |
util.one_of(source, capability) |
84 | 117 |
spec = SPEC.copy() |
85 | 118 |
if source is not None: |
86 |
spec['children'].append({ |
|
87 |
'tag': 'source', 'children': {'tag': source} |
|
88 |
}) |
|
119 |
spec['subtree'].append({ |
|
120 |
'tag': 'source', |
|
121 |
'subtree': {'tag': source} |
|
122 |
}) |
|
89 | 123 |
else: |
90 |
spec['children'].append({'tag': 'config', 'children': config}) |
|
124 |
spec['subtree'].append({ |
|
125 |
'tag': 'config', |
|
126 |
'subtree': config |
|
127 |
}) |
|
91 | 128 |
return self._request(spec) |
92 | 129 |
|
93 | 130 |
|
94 | 131 |
class Commit(RPC): |
95 | 132 |
|
133 |
# tested: no |
|
134 |
# combed: yes |
|
135 |
|
|
96 | 136 |
DEPENDS = [':candidate'] |
97 | 137 |
|
98 |
SPEC = {'tag': 'commit', 'children': [] }
|
|
138 |
SPEC = { 'tag': 'commit', 'subtree': [] }
|
|
99 | 139 |
|
100 | 140 |
def _parse_hook(self): |
101 | 141 |
pass |
... | ... | |
103 | 143 |
def request(self, confirmed=False, timeout=None): |
104 | 144 |
spec = SPEC.copy() |
105 | 145 |
if confirmed: |
106 |
self._assert(':confirmed-commit') |
|
107 |
children = spec['children'] |
|
108 |
children.append({'tag': 'confirmed'}) |
|
146 |
spec['subtree'].append({'tag': 'confirmed'}) |
|
109 | 147 |
if timeout is not None: |
110 |
children.append({
|
|
148 |
spec['subtree'].append({
|
|
111 | 149 |
'tag': 'confirm-timeout', |
112 | 150 |
'text': timeout |
113 | 151 |
}) |
114 | 152 |
return self._request(Commit.SPEC) |
115 | 153 |
|
116 | 154 |
|
155 |
class ConfirmedCommit(Commit): |
|
156 |
"psuedo-op" |
|
157 |
|
|
158 |
# tested: no |
|
159 |
# combed: yes |
|
160 |
|
|
161 |
DEPENDS = [':candidate', ':confirmed-commit'] |
|
162 |
|
|
163 |
def request(self, timeout=None): |
|
164 |
"Commit changes; requireing that a confirming commit follow" |
|
165 |
return Commit.request(self, confirmed=True, timeout=timeout) |
|
166 |
|
|
167 |
def confirm(self): |
|
168 |
"Make the confirming commit" |
|
169 |
return Commit.request(self, confirmed=True) |
|
170 |
|
|
171 |
|
|
117 | 172 |
class DiscardChanges(RPC): |
118 | 173 |
|
174 |
# tested: no |
|
175 |
# combed: yes |
|
176 |
|
|
119 | 177 |
DEPENDS = [':candidate'] |
120 | 178 |
|
121 | 179 |
SPEC = {'tag': 'discard-changes'} |
122 |
|
|
123 |
request = lambda self: self._request(DiscardChanges.SPEC) |
Also available in: Unified diff