Revision 4de03d63 ncclient/manager.py

b/ncclient/manager.py
16 16
import operations
17 17
import transport
18 18

  
19
OPERATIONS = {
20
    'get': operations.Get,
21
    'get-config': operations.GetConfig,
22
    'edit-config': operations.EditConfig,
23
    'copy-config': operations.CopyConfig,
24
    'validate': operations.Validate,
25
    'commit': operations.Commit,
26
    'discard-changes': operations.DiscardChanges,
27
    'delete-config': operations.DeleteConfig,
28
    'lock': operations.Lock,
29
    'unlock': operations.Unlock,
30
    'close_session': operations.CloseSession,
31
    'kill-session': operations.KillSession,
32
}
33 19

  
34 20
def connect_ssh(*args, **kwds):
35 21
    session = transport.SSHSession(capabilities.CAPABILITIES)
......
39 25

  
40 26
connect = connect_ssh # default session type
41 27

  
28
RAISE_ALL, RAISE_ERROR, RAISE_NONE = range(3)
29

  
42 30
class Manager:
43 31
    
44 32
    "Thin layer of abstraction for the API."
45 33
    
46
    RAISE_ALL, RAISE_ERROR, RAISE_NONE = range(3)
47
    
48
    def __init__(self, session, rpc_errors=Manager.RAISE_ALL):
34
    def __init__(self, session, rpc_error=RAISE_ALL):
49 35
        self._session = session
50 36
        self._raise = rpc_error
51 37

  
52 38
    def do(self, op, *args, **kwds):
53
        op = OPERATIONS[op](self._session)
39
        op = operations.OPERATIONS[op](self._session)
54 40
        reply = op.request(*args, **kwds)
55 41
        if not reply.ok:
56
            if self._raise == Manager.RAISE_ALL:
42
            if self._raise == RAISE_ALL:
57 43
                raise reply.error
58
            elif self._raise == Manager.RAISE_ERROR:
44
            elif self._raise == RAISE_ERROR:
59 45
                for error in reply.errors:
60 46
                    if error.severity == 'error':
61 47
                        raise error

Also available in: Unified diff