Statistics
| Branch: | Tag: | Revision:

root / ncclient / operations / retrieve.py @ e52e8478

History | View | Annotate | Download (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 data attribute'
24
    
25
    # tested: no
26
    # combed: yes
27
    
28
    def _parsing_hook(self, root):
29
        self._data = None
30
        if not self._errors:
31
            self._data = content.find(root, 'data')
32
    
33
    @property
34
    def data(self):
35
        if not self._parsed:
36
            self.parse()
37
        return self._data
38

    
39
class Get(RPC):
40
    
41
    # tested: no
42
    # combed: yes
43
    
44
    SPEC = {
45
        'tag': 'get',
46
        'subtree': []
47
    }
48
    
49
    REPLY_CLS = GetReply
50
    
51
    def request(self, filter=None):
52
        spec = Get.SPEC.copy()
53
        if filter is not None:
54
            spec['subtree'].append(util.build_filter(filter))
55
        return self._request(spec)
56

    
57

    
58
class GetConfig(RPC):
59

    
60
    # tested: no
61
    # combed: yes
62
    
63
    SPEC = {
64
        'tag': 'get-config',
65
        'subtree': []
66
    }
67
    
68
    REPLY_CLS = GetReply
69
    
70
    def request(self, source, filter=None):
71
        """
72
        `filter` has to be a tuple of (type, criteria)
73
        The type may be one of 'xpath' or 'subtree'
74
        The criteria may be an ElementTree.Element, an XML fragment, or tree specification
75
        """
76
        spec = GetConfig.SPEC.copy()
77
        spec['subtree'].append(util.store_or_url('source', source, self._assert))
78
        if filter is not None:
79
            spec['subtree'].append(util.build_filter(filter))
80
        return self._request(spec)