Statistics
| Branch: | Tag: | Revision:

root / ncclient / operations / util.py @ 179b00d4

History | View | Annotate | Download (948 Bytes)

1
#!/usr/bin/env python
2

    
3
'Boilerplate'
4

    
5
from ncclient import OperationError
6

    
7
from . import MissingCapabilityError
8

    
9

    
10
def one_of(*args):
11
    'Verifies that only one of the arguments is not None'
12
    for i, arg in enumerate(args):
13
        if arg is not None:
14
            for argh in args[i+1:]:
15
                if argh is not None:
16
                    raise OperationError('Too many parameters')
17
            else:
18
                return
19
    raise OperationError('Insufficient parameters')
20

    
21

    
22
def store_or_url(store, url):
23
    one_of(store, url)
24
    node = {}
25
    if store is not None:
26
        node['tag'] = store
27
    else:
28
        node['tag'] = 'url'
29
        node['text'] = url
30
    return node
31

    
32

    
33
def build_filter(type, criteria):
34
    filter = {
35
        'tag': 'filter',
36
        'attributes': {'type': type}
37
    }
38
    if type == 'xpath':
39
        filter['attributes']['select'] = criteria
40
    else:
41
        filter['subtree'] = [criteria]
42
    return filter