Statistics
| Branch: | Tag: | Revision:

root / ncclient / operations / retrieve.py @ dd8b8dd7

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.xml_ import *
18

    
19
import util
20

    
21
class GetReply(RPCReply):
22

    
23
    """Adds attributes for the *<data>* element to :class:`RPCReply`, which
24
    pertains to the :class:`Get` and :class:`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
    #: Same as :attr:`data_ele`
46
    data = data_ele
47
    
48
    #def __repr__(self):
49
    #    return self.data_xml
50

    
51

    
52
class Get(RPC):
53

    
54
    "The *<get>* RPC"
55

    
56
    REPLY_CLS = GetReply
57

    
58
    def request(self, filter=None):
59
        node = new_ele("get")
60
        if filter is not None:
61
            node.append(util.build_filter(filter))
62
        return self._request(node)
63

    
64

    
65
class GetConfig(RPC):
66

    
67
    "The *<get-config>* RPC"
68

    
69
    REPLY_CLS = GetReply
70

    
71
    def request(self, source, filter=None):
72
        node = new_ele("get-config")
73
        node.append(util.datastore_or_url("source", source, self._assert))
74
        if filter is not None:
75
            node.append(util.build_filter(filter))
76
        return self._request(node)