Revision 19e7c7f6 ncclient/operations/edit.py
b/ncclient/operations/edit.py | ||
---|---|---|
19 | 19 |
import util |
20 | 20 |
|
21 | 21 |
import logging |
22 |
|
|
22 | 23 |
logger = logging.getLogger("ncclient.operations.edit") |
23 | 24 |
|
24 | 25 |
"Operations related to changing device configuration" |
25 | 26 |
|
26 | 27 |
class EditConfig(RPC): |
28 |
"`edit-config` RPC" |
|
27 | 29 |
|
28 |
"*<edit-config>* RPC" |
|
29 |
|
|
30 | 30 |
def request(self, target, config, default_operation=None, test_option=None, error_option=None): |
31 |
"""Loads all or part of the specified *config* to the *target* configuration datastore. |
|
32 |
|
|
33 |
*target* is the name of the configuration datastore being edited |
|
34 |
|
|
35 |
*config* is the configuration, which must be rooted in the `config` element. It can be specified either as a string or an :class:`~xml.etree.ElementTree.Element`. |
|
36 |
|
|
37 |
*default_operation* if specified must be one of { `"merge"`, `"replace"`, or `"none"` } |
|
38 |
|
|
39 |
*test_option* if specified must be one of { `"test_then_set"`, `"set"` } |
|
40 |
|
|
41 |
*error_option* if specified must be one of { `"stop-on-error"`, `"continue-on-error"`, `"rollback-on-error"` } |
|
42 |
|
|
43 |
The `"rollback-on-error"` *error_option* depends on the `:rollback-on-error` capability. |
|
44 |
""" |
|
31 | 45 |
node = new_ele("edit-config") |
32 | 46 |
node.append(util.datastore_or_url("target", target, self._assert)) |
33 | 47 |
if error_option is not None: |
... | ... | |
38 | 52 |
self._assert(':validate') |
39 | 53 |
sub_ele(node, "test-option").text = test_option |
40 | 54 |
if default_operation is not None: |
41 |
# TODO: check if it is a valid default-operation
|
|
55 |
# TODO: check if it is a valid default-operation |
|
42 | 56 |
sub_ele(node, "default-operation").text = default_operation |
43 | 57 |
node.append(validated_element(config, ("config", qualify("config")))) |
44 | 58 |
return self._request(node) |
45 | 59 |
|
46 | 60 |
|
47 | 61 |
class DeleteConfig(RPC): |
48 |
|
|
49 |
"*<delete-config>* RPC" |
|
62 |
"`delete-config` RPC" |
|
50 | 63 |
|
51 | 64 |
def request(self, target): |
65 |
"""Delete a configuration datastore. |
|
66 |
|
|
67 |
:param target: name or URL of configuration datastore to delete |
|
68 |
:type: :ref:`srctarget_params`""" |
|
52 | 69 |
node = new_ele("delete-config") |
53 | 70 |
node.append(util.datastore_or_url("target", target, self._assert)) |
54 | 71 |
return self._request(node) |
55 | 72 |
|
56 | 73 |
|
57 | 74 |
class CopyConfig(RPC): |
75 |
"`copy-config` RPC" |
|
58 | 76 |
|
59 |
"*<copy-config>* RPC" |
|
60 |
|
|
61 | 77 |
def request(self, source, target): |
78 |
"""Create or replace an entire configuration datastore with the contents of another complete |
|
79 |
configuration datastore. |
|
80 |
|
|
81 |
:param source: configuration datastore to use as the source of the copy operation or `config` element containing the configuration subtree to copy |
|
82 |
:type source: :ref:`srctarget_params` |
|
83 |
|
|
84 |
:param target: configuration datastore to use as the destination of the copy operation |
|
85 |
:type target: :ref:`srctarget_params`""" |
|
62 | 86 |
node = new_ele("copy-config") |
63 | 87 |
node.append(util.datastore_or_url("target", target, self._assert)) |
64 | 88 |
node.append(util.datastore_or_url("source", source, self._assert)) |
... | ... | |
66 | 90 |
|
67 | 91 |
|
68 | 92 |
class Validate(RPC): |
69 |
|
|
70 |
"*<validate>* RPC. Depends on the *:validate* capability." |
|
93 |
"`validate` RPC. Depends on the `:validate` capability." |
|
71 | 94 |
|
72 | 95 |
DEPENDS = [':validate'] |
73 | 96 |
|
74 | 97 |
def request(self, source): |
98 |
"""Validate the contents of the specified configuration. |
|
99 |
|
|
100 |
:param source: name of the configuration datastore being validated or `config` element containing the configuration subtree to be validated |
|
101 |
:type source: :ref:`srctarget_params`""" |
|
75 | 102 |
node = new_ele("validate") |
76 | 103 |
try: |
77 | 104 |
src = validated_element(source, ("config", qualify("config"))) |
... | ... | |
83 | 110 |
|
84 | 111 |
|
85 | 112 |
class Commit(RPC): |
86 |
|
|
87 |
"*<commit>* RPC. Depends on the *:candidate* capability, and the *:confirmed-commit* " |
|
113 |
"`commit` RPC. Depends on the `:candidate` capability, and the `:confirmed-commit`." |
|
88 | 114 |
|
89 | 115 |
DEPENDS = [':candidate'] |
90 |
|
|
116 |
|
|
91 | 117 |
def request(self, confirmed=False, timeout=None): |
118 |
"""Commit the candidate configuration as the device's new current configuration. Depends on the `:candidate` capability. |
|
119 |
|
|
120 |
A confirmed commit (i.e. if *confirmed* is `True`) is reverted if there is no followup commit within the *timeout* interval. If no timeout is specified the confirm timeout defaults to 600 seconds (10 minutes). A confirming commit may have the *confirmed* parameter but this is not required. Depends on the `:confirmed-commit` capability. |
|
121 |
|
|
122 |
:param confirmed: whether this is a confirmed commit |
|
123 |
:type confirmed: bool |
|
124 |
|
|
125 |
:param timeout: confirm timeout in seconds |
|
126 |
:type timeout: int""" |
|
92 | 127 |
node = new_ele("commit") |
93 | 128 |
if confirmed: |
94 | 129 |
self._assert(":confirmed-commit") |
... | ... | |
99 | 134 |
|
100 | 135 |
|
101 | 136 |
class DiscardChanges(RPC): |
102 |
|
|
103 |
"*<discard-changes>* RPC. Depends on the *:candidate* capability." |
|
137 |
"`discard-changes` RPC. Depends on the `:candidate` capability." |
|
104 | 138 |
|
105 | 139 |
DEPENDS = [":candidate"] |
106 | 140 |
|
107 | 141 |
def request(self): |
142 |
"""Revert the candidate configuration to the currently running configuration. Any uncommitted changes are discarded.""" |
|
108 | 143 |
return self._request(new_ele("discard-changes")) |
Also available in: Unified diff