root / ncclient / operations / retrieve.py @ d215b592
History | View | Annotate | Download (2.4 kB)
1 |
# Copyright 2009 Shikhar Bhushan
|
---|---|
2 |
#
|
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
|
6 |
#
|
7 |
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
#
|
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.
|
14 |
|
15 |
from rpc import RPC, RPCReply |
16 |
|
17 |
from ncclient.xml_ import * |
18 |
|
19 |
import util |
20 |
|
21 |
class GetReply(RPCReply): |
22 |
|
23 |
"""Adds attributes for the *data* element to `RPCReply`. This pertains to the `Get` and
|
24 |
`GetConfig` operations."""
|
25 |
|
26 |
def _parsing_hook(self, root): |
27 |
self._data = None |
28 |
if not self._errors: |
29 |
self._data = root.find(qualify("data")) |
30 |
|
31 |
@property
|
32 |
def data_ele(self): |
33 |
"*data* element as an :class:`~xml.etree.ElementTree.Element`"
|
34 |
if not self._parsed: |
35 |
self.parse()
|
36 |
return self._data |
37 |
|
38 |
@property
|
39 |
def data_xml(self): |
40 |
"*data* element as an XML string"
|
41 |
if not self._parsed: |
42 |
self.parse()
|
43 |
return to_xml(self._data) |
44 |
|
45 |
data = data_ele |
46 |
"Same as :attr:`data_ele`"
|
47 |
|
48 |
|
49 |
class Get(RPC): |
50 |
|
51 |
"The *get* RPC."
|
52 |
|
53 |
REPLY_CLS = GetReply |
54 |
|
55 |
def request(self, filter=None): |
56 |
"""Retrieve running configuration and device state information.
|
57 |
|
58 |
*filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)
|
59 |
|
60 |
:seealso: :ref:`filter_params`
|
61 |
"""
|
62 |
node = new_ele("get")
|
63 |
if filter is not None: |
64 |
node.append(util.build_filter(filter))
|
65 |
return self._request(node) |
66 |
|
67 |
|
68 |
class GetConfig(RPC): |
69 |
|
70 |
"The *get-config* RPC."
|
71 |
|
72 |
REPLY_CLS = GetReply |
73 |
|
74 |
def request(self, source, filter=None): |
75 |
"""Retrieve all or part of a specified configuration.
|
76 |
|
77 |
*source* name of the configuration datastore being queried
|
78 |
|
79 |
*filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)
|
80 |
|
81 |
:seealso: :ref:`filter_params`"""
|
82 |
node = new_ele("get-config")
|
83 |
node.append(util.datastore_or_url("source", source, self._assert)) |
84 |
if filter is not None: |
85 |
node.append(util.build_filter(filter))
|
86 |
return self._request(node) |