Revision d6688264 ncclient/operations/retrieve.py

b/ncclient/operations/retrieve.py
12 12
# See the License for the specific language governing permissions and
13 13
# limitations under the License.
14 14

  
15
from copy import deepcopy
16

  
17
from ncclient.rpc import RPC
15
from ncclient.rpc import RPC, RPCReply
18 16

  
19 17
def build_filter(spec, type, criteria):
20 18
    filter = {
21 19
        'tag': 'filter',
22 20
        'attributes': {'type': type}
23 21
    }
24
    if type=='subtree':
25
        if isinstance(criteria, dict):
26
            filter['children'] = [criteria]
27
        else:
28
            filter['text'] = criteria
29
    elif type=='xpath':
22
    if type == 'subtree':
23
        filter['children'] = [criteria]
24
    elif type == 'xpath':
30 25
        filter['attributes']['select'] = criteria
26
    return filter
31 27

  
32
class Get(RPC):
28
class Get(RPC): # xx
33 29
    
34 30
    SPEC = {
35 31
        'tag': 'get',
36 32
        'children': []
37 33
    }
38 34
    
35
    REPLY_CLS = GetReply
36
    
39 37
    def request(self, filter=None):
40
        spec = deepcopy(SPEC)
38
        spec = Get.SPEC.copy()
41 39
        if filter is not None:
40
            #if filter[0] == 'xpath':
41
            #    self._assert(':xpath')
42 42
            spec['children'].append(build_filter(*filter))
43 43
        return self._request(spec)
44 44

  
45
class GetReply(RPCReply):
46
    
47
    def parse(self):
48
        RPCReply.parse(self)
45 49

  
46
class GetConfig(RPC):
50
class GetConfig(RPC): # xx
47 51
    
48 52
    SPEC = {
49 53
        'tag': 'get-config',
50 54
        'children': [ { 'tag': 'source', 'children': {'tag': None } } ]
51 55
    }
52 56
    
53
    def request(self, source='running', filter=None):
54
        spec = deepcopy(SPEC)
55
        spec['children'][0]['children']['tag'] = source
57
    REPLY_CLS = GetConfigReply
58
    
59
    def request(self, source=None, source_url=None, filter=None):
60
        self._one_of(source, source_url)
61
        spec = GetConfig.SPEC.copy()
62
        if source is not None:
63
            spec['children'][0]['children']['tag'] = source
64
        if source_url is not None:
65
            #self._assert(':url')
66
            spec['children'][0]['children']['tag'] = 'url'
67
            spec['children'][0]['children']['text'] = source_url        
56 68
        if filter is not None:
69
            #if filter[0] == 'xpath':
70
            #    self._assert(':xpath')
57 71
            spec['children'].append(build_filter(*filter))
58 72
        return self._request(spec)
73

  
74
class GetReply(RPCReply):
75
    
76
    def parse(self):
77
        RPCReply.parse(self)

Also available in: Unified diff