Statistics
| Branch: | Tag: | Revision:

root / ncclient / operations / util.py @ d6688264

History | View | Annotate | Download (766 Bytes)

1
#!/usr/bin/env python
2

    
3
'boilerplate'
4

    
5
from ncclient import OperationError
6

    
7
class MissingCapabilityError(OperationError):
8
    pass
9

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

    
20

    
21
def assert_capability(key, capabilities):
22
    if key not in capabilities:
23
        raise MissingCapabilityError
24

    
25

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