root / ncclient / operations / retrieve.py @ a7cb58ce
History | View | Annotate | Download (2.2 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 import content |
18 |
|
19 |
import util |
20 |
|
21 |
class GetReply(RPCReply): |
22 |
|
23 |
"""Adds attributes for the *<data>* element to :class:`RPCReply`, pertinent
|
24 |
to the *<get>* or *<get-config>* operations."""
|
25 |
|
26 |
def _parsing_hook(self, root): |
27 |
self._data = None |
28 |
if not self._errors: |
29 |
self._data = content.find(root, 'data', |
30 |
nslist=[content.BASE_NS, |
31 |
content.CISCO_BS]) |
32 |
|
33 |
@property
|
34 |
def data_ele(self): |
35 |
"As an :class:`~xml.etree.ElementTree.Element`"
|
36 |
if not self._parsed: |
37 |
self.parse()
|
38 |
return self._data |
39 |
|
40 |
@property
|
41 |
def data_xml(self): |
42 |
"As an XML string"
|
43 |
if not self._parsed: |
44 |
self.parse()
|
45 |
return content.ele2xml(self._data) |
46 |
|
47 |
data = data_ele |
48 |
|
49 |
|
50 |
class Get(RPC): |
51 |
|
52 |
"*<get>* RPC"
|
53 |
|
54 |
SPEC = { |
55 |
'tag': 'get', |
56 |
'subtree': []
|
57 |
} |
58 |
|
59 |
REPLY_CLS = GetReply |
60 |
|
61 |
def request(self, filter=None): |
62 |
spec = Get.SPEC.copy() |
63 |
if filter is not None: |
64 |
spec['subtree'].append(util.build_filter(filter)) |
65 |
return self._request(spec) |
66 |
|
67 |
|
68 |
class GetConfig(RPC): |
69 |
|
70 |
"*<get-config>* RPC"
|
71 |
|
72 |
SPEC = { |
73 |
'tag': 'get-config', |
74 |
'subtree': []
|
75 |
} |
76 |
|
77 |
REPLY_CLS = GetReply |
78 |
|
79 |
def request(self, source, filter=None): |
80 |
spec = GetConfig.SPEC.copy() |
81 |
spec['subtree'].append(util.store_or_url('source', source, self._assert)) |
82 |
if filter is not None: |
83 |
spec['subtree'].append(util.build_filter(filter)) |
84 |
return self._request(spec) |