Statistics
| Branch: | Tag: | Revision:

root / ncclient / operations / retrieve.py @ 9667bcb2

History | View | Annotate | Download (2.3 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
        """
60
        :arg filter: optional; see :ref:`filter`
61

62
        :seealso: :ref:`return`
63
        """
64
        node = new_ele("get")
65
        if filter is not None:
66
            node.append(util.build_filter(filter))
67
        return self._request(node)
68

    
69

    
70
class GetConfig(RPC):
71

    
72
    "The *<get-config>* RPC"
73

    
74
    REPLY_CLS = GetReply
75

    
76
    def request(self, source, filter=None):
77
        """
78
        :arg source: See :ref:`source_target`
79

80
        :arg filter: optional; see :ref:`filter`
81

82
        :seealso: :ref:`return`
83
        """
84
        node = new_ele("get-config")
85
        node.append(util.datastore_or_url("source", source, self._assert))
86
        if filter is not None:
87
            node.append(util.build_filter(filter))
88
        return self._request(node)