Revision dd8b8dd7
b/ncclient/operations/edit.py | ||
---|---|---|
29 | 29 |
|
30 | 30 |
def request(self, target, config, default_operation=None, test_option=None, |
31 | 31 |
error_option=None): |
32 |
""" |
|
33 |
:arg target: see :ref:`source_target` |
|
34 |
:type target: string |
|
35 |
|
|
36 |
:arg config: a config element in :ref:`dtree` |
|
37 |
:type config: `string` or `dict` or :class:`~xml.etree.ElementTree.Element` |
|
38 |
|
|
39 |
:arg default_operation: optional; one of {'merge', 'replace', 'none'} |
|
40 |
:type default_operation: `string` |
|
41 |
|
|
42 |
:arg error_option: optional; one of {'stop-on-error', 'continue-on-error', 'rollback-on-error'}. Last option depends on the *:rollback-on-error* capability |
|
43 |
:type error_option: string |
|
44 |
|
|
45 |
:arg test_option: optional; one of {'test-then-set', 'set'}. Depends on *:validate* capability. |
|
46 |
:type test_option: string |
|
47 |
|
|
48 |
:seealso: :ref:`return` |
|
49 |
""" |
|
32 |
#:arg default_operation: optional; one of {'merge', 'replace', 'none'} |
|
33 |
#:type default_operation: `string` |
|
34 |
# |
|
35 |
#:arg error_option: optional; one of {'stop-on-error', 'continue-on-error', 'rollback-on-error'}. Last option depends on the *:rollback-on-error* capability |
|
36 |
#:type error_option: string |
|
37 |
# |
|
38 |
#:arg test_option: optional; one of {'test-then-set', 'set'}. Depends on *:validate* capability. |
|
39 |
#:type test_option: string |
|
50 | 40 |
node = new_ele("edit-config") |
51 | 41 |
node.append(util.datastore_or_url("target", target, self._assert)) |
52 | 42 |
if error_option is not None: |
... | ... | |
68 | 58 |
"*<delete-config>* RPC" |
69 | 59 |
|
70 | 60 |
def request(self, target): |
71 |
""" |
|
72 |
:arg target: See :ref:`source_target` |
|
73 |
:type target: `string` or `dict` or :class:`~xml.etree.ElementTree.Element` |
|
74 |
|
|
75 |
:seealso: :ref:`return` |
|
76 |
""" |
|
77 | 61 |
node = new_ele("delete-config") |
78 | 62 |
node.append(util.datastore_or_url("target", target, self._assert)) |
79 | 63 |
return self._request(spec) |
... | ... | |
84 | 68 |
"*<copy-config>* RPC" |
85 | 69 |
|
86 | 70 |
def request(self, source, target): |
87 |
""" |
|
88 |
:arg source: See :ref:`source_target` |
|
89 |
:type source: `string` or `dict` or :class:`~xml.etree.ElementTree.Element` |
|
90 |
|
|
91 |
:arg target: See :ref:`source_target` |
|
92 |
:type target: `string` or `dict` or :class:`~xml.etree.ElementTree.Element` |
|
93 |
|
|
94 |
:seealso: :ref:`return` |
|
95 |
""" |
|
96 | 71 |
node = new_ele("copy-config") |
97 | 72 |
node.append(util.datastore_or_url("target", target, self._assert)) |
98 | 73 |
node.append(util.datastore_or_url("source", source, self._assert)) |
... | ... | |
106 | 81 |
DEPENDS = [':validate'] |
107 | 82 |
|
108 | 83 |
def request(self, source): |
109 |
""" |
|
110 |
:arg source: See :ref:`source_target` |
|
111 |
:type source: `string` or `dict` or :class:`~xml.etree.ElementTree.Element` |
|
112 |
|
|
113 |
:seealso: :ref:`return` |
|
114 |
""" |
|
115 | 84 |
node = new_ele("validate") |
116 | 85 |
try: |
117 | 86 |
src = validated_element(source, ("config", qualify("config"))) |
... | ... | |
132 | 101 |
""" |
133 | 102 |
Requires *:confirmed-commit* capability if *confirmed* argument is |
134 | 103 |
:const:`True`. |
135 |
|
|
136 |
:arg confirmed: optional; request a confirmed commit |
|
137 |
:type confirmed: `bool` |
|
138 |
|
|
139 |
:arg timeout: specify timeout for confirmed commit |
|
140 |
:type timeout: `int` |
|
141 |
|
|
142 |
:seealso: :ref:`return` |
|
143 | 104 |
""" |
105 |
#:arg confirmed: optional; request a confirmed commit |
|
106 |
#:type confirmed: `bool` |
|
107 |
# |
|
108 |
#:arg timeout: specify timeout for confirmed commit |
|
109 |
#:type timeout: `int` |
|
144 | 110 |
node = new_ele("commit") |
145 | 111 |
if confirmed: |
146 | 112 |
self._assert(":confirmed-commit") |
... | ... | |
158 | 124 |
DEPENDS = [":candidate"] |
159 | 125 |
|
160 | 126 |
def request(self): |
161 |
":seealso: :ref:`return`" |
|
162 | 127 |
return self._request(new_ele("discard-changes")) |
b/ncclient/operations/lock.py | ||
---|---|---|
27 | 27 |
"*<lock>* RPC" |
28 | 28 |
|
29 | 29 |
def request(self, target): |
30 |
""" |
|
31 |
:arg target: see :ref:`source_target` |
|
32 |
:type target: string |
|
33 |
|
|
34 |
:rtype: :ref:`return` |
|
35 |
""" |
|
36 | 30 |
node = new_ele("lock") |
37 | 31 |
sub_ele(sub_ele(node, "target"), "running") |
38 | 32 |
return self._request(node) |
... | ... | |
43 | 37 |
"*<unlock>* RPC" |
44 | 38 |
|
45 | 39 |
def request(self, target): |
46 |
""" |
|
47 |
:arg target: see :ref:`source_target` |
|
48 |
:type target: string |
|
49 |
|
|
50 |
:rtype: :ref:`return` |
|
51 |
""" |
|
52 | 40 |
node = new_ele("unlock") |
53 | 41 |
sub_ele(sub_ele(node, "target"), "running") |
54 | 42 |
return self._request(node) |
... | ... | |
61 | 49 |
|
62 | 50 |
RPC errors are always raised as exceptions. |
63 | 51 |
|
64 |
Initialise with session instance (:class:`Session
|
|
65 |
<ncclient.transport.Session>`) and lock target (:ref:`source_target`)
|
|
52 |
Initialise with (:class:`Session <ncclient.transport.Session>`) instance
|
|
53 |
and lock target.
|
|
66 | 54 |
""" |
67 | 55 |
|
68 | 56 |
def __init__(self, session, target): |
b/ncclient/operations/retrieve.py | ||
---|---|---|
56 | 56 |
REPLY_CLS = GetReply |
57 | 57 |
|
58 | 58 |
def request(self, filter=None): |
59 |
""" |
|
60 |
:arg filter: optional; see :ref:`filter` |
|
61 |
|
|
62 |
:seealso: :ref:`return` |
|
63 |
""" |
|
64 | 59 |
node = new_ele("get") |
65 | 60 |
if filter is not None: |
66 | 61 |
node.append(util.build_filter(filter)) |
... | ... | |
74 | 69 |
REPLY_CLS = GetReply |
75 | 70 |
|
76 | 71 |
def request(self, source, filter=None): |
77 |
""" |
|
78 |
:arg source: See :ref:`source_target` |
|
79 |
|
|
80 |
:arg filter: optional; see :ref:`filter` |
|
81 |
|
|
82 |
:seealso: :ref:`return` |
|
83 |
""" |
|
84 | 72 |
node = new_ele("get-config") |
85 | 73 |
node.append(util.datastore_or_url("source", source, self._assert)) |
86 | 74 |
if filter is not None: |
b/ncclient/operations/rpc.py | ||
---|---|---|
260 | 260 |
object. The :attr:`event` attribute will be set when the reply has been |
261 | 261 |
received (see :attr:`reply`) or an error occured (see :attr:`error`). |
262 | 262 |
|
263 |
:arg opspec: :ref:`dtree` for the operation |
|
264 | 263 |
:type opspec: :obj:`dict` or :obj:`string` or :class:`~xml.etree.ElementTree.Element` |
265 | 264 |
:rtype: :class:`RPCReply` (sync) or :class:`RPC` (async) |
266 | 265 |
""" |
... | ... | |
291 | 290 |
raise TimeoutExpiredError |
292 | 291 |
|
293 | 292 |
def request(self, *args, **kwds): |
294 |
"""Subclasses implement this method. Here, the operation is constructed |
|
295 |
in :ref:`dtree`, and the result of :meth:`_request` returned.""" |
|
293 |
"Subclasses implement this method." |
|
296 | 294 |
return self._request(self.SPEC) |
297 | 295 |
|
298 | 296 |
def _assert(self, capability): |
b/ncclient/operations/session.py | ||
---|---|---|
37 | 37 |
""" |
38 | 38 |
:arg session_id: *session-id* of NETCONF session to kill |
39 | 39 |
:type session_id: `string` |
40 |
|
|
41 |
:seealso: :ref:`return` |
|
42 | 40 |
""" |
43 | 41 |
node = new_ele("kill-session") |
44 | 42 |
if not isinstance(session_id, basestring): # make sure |
b/ncclient/transport/ssh.py | ||
---|---|---|
147 | 147 |
the publickey authentication method and then password authentication. |
148 | 148 |
|
149 | 149 |
To disable attemting publickey authentication altogether, call with |
150 |
*allow_agent* and *look_for_keys* as :const:`False`. This may be needed |
|
151 |
for Cisco devices which immediately disconnect on an incorrect |
|
152 |
authentication attempt. |
|
150 |
*allow_agent* and *look_for_keys* as :const:`False`. |
|
153 | 151 |
|
154 | 152 |
:arg host: the hostname or IP address to connect to |
155 | 153 |
:type host: `string` |
b/ncclient/xml_.py | ||
---|---|---|
13 | 13 |
# limitations under the License. |
14 | 14 |
|
15 | 15 |
|
16 |
"""The :mod:`xml` module provides methods for creating XML documents, parsing |
|
17 |
XML, and converting between different XML representations. It uses |
|
18 |
:mod:`~xml.etree.ElementTree` internally. |
|
19 |
""" |
|
16 |
"""The :mod:`xml_` module provides methods for creating, parsing, and dealing |
|
17 |
with XML. It uses :mod:`~xml.etree.ElementTree`.""" |
|
20 | 18 |
|
21 | 19 |
from cStringIO import StringIO |
22 | 20 |
from xml.etree import cElementTree as ET |
... | ... | |
30 | 28 |
|
31 | 29 |
#: Base NETCONF namespace |
32 | 30 |
BASE_NS_1_0 = 'urn:ietf:params:xml:ns:netconf:base:1.0' |
33 |
#: namespace for Tail-f data model
|
|
31 |
#: Namespace for Tail-f core data model
|
|
34 | 32 |
TAILF_AAA_1_1 = 'http://tail-f.com/ns/aaa/1.1' |
35 |
#: namespace for Tail-f data model
|
|
33 |
#: Namespace for Tail-f execd data model
|
|
36 | 34 |
TAILF_EXECD_1_1 = 'http://tail-f.com/ns/execd/1.1' |
37 |
#: namespace for Cisco data model
|
|
35 |
#: Namespace for Cisco data model
|
|
38 | 36 |
CISCO_CPI_1_0 = 'http://www.cisco.com/cpi_10/schema' |
39 |
#: namespace for Flowmon data model
|
|
37 |
#: Namespace for Flowmon data model
|
|
40 | 38 |
FLOWMON_1_0 = 'http://www.liberouter.org/ns/netopeer/flowmon/1.0' |
41 | 39 |
|
42 | 40 |
try: |
... | ... | |
63 | 61 |
#unqualify = lambda tag: tag[tag.rfind('}')+1:] |
64 | 62 |
|
65 | 63 |
def to_xml(ele, encoding="UTF-8"): |
66 |
"""Element -> XML
|
|
64 |
"""Convert an :class:`~xml.etree.ElementTree.Element` to XML.
|
|
67 | 65 |
|
68 |
:type spec: :class:`~xml.etree.ElementTree.Element`
|
|
66 |
:arg ele: the :class:`~xml.etree.ElementTree.Element`
|
|
69 | 67 |
:arg encoding: character encoding |
70 | 68 |
:rtype: :obj:`string` |
71 | 69 |
""" |
... | ... | |
73 | 71 |
return xml if xml.startswith('<?xml') else '<?xml version="1.0" encoding="%s"?>%s' % (encoding, xml) |
74 | 72 |
|
75 | 73 |
def to_ele(x): |
76 |
"""XML -> Element
|
|
74 |
"""Convert XML to :class:`~xml.etree.ElementTree.Element`.
|
|
77 | 75 |
|
78 | 76 |
:type xml: :obj:`string` |
79 | 77 |
:rtype: :class:`~xml.etree.ElementTree.Element` |
... | ... | |
86 | 84 |
"""Efficiently parses the root element of an XML document. |
87 | 85 |
|
88 | 86 |
:arg raw: XML document |
89 |
:type raw: string
|
|
90 |
:returns: a tuple of `(tag, attributes)`, where `tag` is the (qualified) name of the element and `attributes` is a dictionary of its attributes.
|
|
87 |
:returns: a tuple of `(tag, attrib)`, where *tag* is the (qualified)
|
|
88 |
name of the element and *attrib* is a dictionary of its attributes.
|
|
91 | 89 |
:rtype: `tuple` |
92 | 90 |
""" |
93 | 91 |
fp = StringIO(raw) |
... | ... | |
95 | 93 |
return (element.tag, element.attrib) |
96 | 94 |
|
97 | 95 |
def validated_element(x, tags=None, attrs=None): |
98 |
"""Checks if the root element meets the supplied criteria. Returns a |
|
99 |
:class:`~xml.etree.ElementTree.Element` instance if so, otherwise raises |
|
100 |
:exc:`ContentError`. |
|
101 |
|
|
96 |
"""Checks if the root element of an XML document or |
|
97 |
:class:`~xml.etree.ElementTree.Element` meets the supplied criteria. Raises |
|
98 |
:exc:`XMLError` if it is not met. |
|
99 |
|
|
100 |
:arg x: the XML document or :class:`~xml.etree.ElementTree.Element` to validate |
|
102 | 101 |
:arg tags: tag name or a sequence of allowable tag names |
103 | 102 |
:arg attrs: sequence of required attribute names, each item may be a list of allowable alternatives |
104 |
:arg text: textual content to match
|
|
105 |
:type rep: :class:`~xml.etree.ElementTree.Element`
|
|
103 |
:returns: validated element
|
|
104 |
:rtype: :class:`~xml.etree.ElementTree.Element`
|
|
106 | 105 |
""" |
107 | 106 |
ele = to_ele(x) |
108 | 107 |
if tags: |
Also available in: Unified diff