root / ncclient / operations / retrieve.py @ 179b00d4
History | View | Annotate | Download (1.8 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 ncclient.rpc import RPC, RPCReply |
16 |
|
17 |
import util |
18 |
|
19 |
class GetReply(RPCReply): |
20 |
|
21 |
# tested: no
|
22 |
|
23 |
def __init__(self, *args, **kwds): |
24 |
RPCReply.__init__(self, *args, **kwds)
|
25 |
self._data = None |
26 |
|
27 |
def parse(self): |
28 |
RPCReply.parse(self)
|
29 |
if self.ok: |
30 |
self.root.find('data') |
31 |
|
32 |
@property
|
33 |
def data(self): |
34 |
return ET.tostring(self._data) |
35 |
|
36 |
class Get(RPC): |
37 |
|
38 |
# tested: no
|
39 |
|
40 |
SPEC = { |
41 |
'tag': 'get', |
42 |
'subtree': []
|
43 |
} |
44 |
|
45 |
REPLY_CLS = GetReply |
46 |
|
47 |
def request(self, filter=None): |
48 |
spec = Get.SPEC.copy() |
49 |
if filter is not None: |
50 |
spec['subtree'].append(util.build_filter(*filter)) |
51 |
return self._request(spec) |
52 |
|
53 |
class GetConfig(RPC): |
54 |
|
55 |
SPEC = { |
56 |
'tag': 'get-config', |
57 |
'subtree': []
|
58 |
} |
59 |
|
60 |
REPLY_CLS = GetReply |
61 |
|
62 |
def request(self, source=None, source_url=None, filter=None): |
63 |
util.one_of(source, source_url) |
64 |
spec = GetConfig.SPEC.copy() |
65 |
subtree = spec['subtree']
|
66 |
subtree.append({'tag': 'source', 'subtree': util.store_or_url(source, source_url)}) |
67 |
if filter is not None: |
68 |
subtree.append(util.build_filter(*filter))
|
69 |
return self._request(spec) |