1 # Copyright 2009 Shikhar Bhushan
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 from rpc import RPC, RPCReply
17 from ncclient import xml_
18 from copy import deepcopy
22 class GetReply(RPCReply):
26 """Adds attributes for the *<data>* element to :class:`RPCReply`, which
27 pertains to the :class:`Get` and :class:`GetConfig` operations."""
29 def _parsing_hook(self, root):
32 self._data = xml_.find(root, 'data',
38 "*<data>* element as an :class:`~xml.etree.ElementTree.Element`"
45 "*<data>* element as an XML string"
48 return xml_.ele2xml(self._data)
52 "*<data>* element in :ref:`dtree`"
53 return xml_.ele2dtree(self._data)
55 #: Same as :attr:`data_ele`
65 SPEC = {'tag': 'get', 'subtree': []}
69 def request(self, filter=None):
71 :arg filter: optional; see :ref:`filter`
73 :seealso: :ref:`return`
75 spec = deepcopy(Get.SPEC)
76 if filter is not None:
77 spec['subtree'].append(util.build_filter(filter))
78 return self._request(spec)
85 "The *<get-config>* RPC"
87 SPEC = {'tag': 'get-config', 'subtree': []}
91 def request(self, source, filter=None):
93 :arg source: See :ref:`source_target`
95 :arg filter: optional; see :ref:`filter`
97 :seealso: :ref:`return`
99 spec = deepcopy(GetConfig.SPEC)
100 spec['subtree'].append(util.store_or_url('source', source, self._assert))
101 if filter is not None:
102 spec['subtree'].append(util.build_filter(filter))
103 return self._request(spec)