Statistics
| Branch: | Tag: | Revision:

root / ncclient / operations / util.py @ 2f8bc438

History | View | Annotate | Download (804 Bytes)

1
#!/usr/bin/env python
2

    
3
'Boilerplate'
4

    
5
from ncclient import OperationError
6

    
7
from . import MissingCapabilityError
8

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

    
19

    
20
def assert_capability(key, capabilities):
21
    if key not in capabilities:
22
        raise MissingCapabilityError('[%s] capability is required for this operation' % key)
23

    
24

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