Revision 4f650d54 ncclient/manager.py

b/ncclient/manager.py
28 28
RAISE_ALL, RAISE_ERROR, RAISE_NONE = range(3)
29 29

  
30 30
class Manager:
31
    
31

  
32 32
    "Thin layer of abstraction for the ncclient API."
33
    
34
    def __init__(self, session, rpc_error=RAISE_ALL):
33

  
34
    def __init__(self, session):
35 35
        self._session = session
36
        self._raise = rpc_error
36
        self._rpc_error_handling = RAISE_ALL
37

  
38
    def set_rpc_error_option(self, option):
39
        self._rpc_error_handling = option
37 40

  
38 41
    def do(self, op, *args, **kwds):
39 42
        op = operations.OPERATIONS[op](self._session)
......
46 49
                    if error.severity == 'error':
47 50
                        raise error
48 51
        return reply
49
    
52

  
50 53
    def __enter__(self):
51 54
        pass
52
    
55

  
53 56
    def __exit__(self, *args):
54 57
        self.close()
55 58
        return False
56
    
59

  
57 60
    def locked(self, target):
58
        """Returns a context manager for use withthe 'with' statement.
61
        """Returns a context manager for use with the 'with' statement.
59 62
        `target` is the datastore to lock, e.g. 'candidate
60 63
        """
61 64
        return operations.LockContext(self._session, target)
62
     
65

  
63 66
    get = lambda self, *args, **kwds: self.do('get', *args, **kwds).data
64
    
67

  
65 68
    get_config = lambda self, *args, **kwds: self.do('get-config', *args, **kwds).data
66
    
69

  
67 70
    edit_config = lambda self, *args, **kwds: self.do('edit-config', *args, **kwds)
68
    
71

  
69 72
    copy_config = lambda self, *args, **kwds: self.do('copy-config', *args, **kwds)
70
    
73

  
71 74
    validate = lambda self, *args, **kwds: self.do('validate', *args, **kwds)
72
    
75

  
73 76
    commit = lambda self, *args, **kwds: self.do('commit', *args, **kwds)
74
    
77

  
75 78
    discard_changes = lambda self, *args, **kwds: self.do('discard-changes', *args, **kwds)
76
    
79

  
77 80
    delete_config = lambda self, *args, **kwds: self.do('delete-config', *args, **kwds)
78
    
81

  
79 82
    lock = lambda self, *args, **kwds: self.do('lock', *args, **kwds)
80
    
83

  
81 84
    unlock = lambda self, *args, **kwds: self.do('unlock', *args, **kwds)
82
    
85

  
83 86
    close_session = lambda self, *args, **kwds: self.do('close-session', *args, **kwds)
84
    
87

  
85 88
    kill_session = lambda self, *args, **kwds: self.do('kill-session', *args, **kwds)
86
    
89

  
87 90
    def close(self):
88 91
        try: # try doing it clean
89 92
            self.close_session()
......
91 94
            pass
92 95
        if self._session.connected: # if that didn't work...
93 96
            self._session.close()
94
    
97

  
95 98
    @property
96 99
    def session(self, session):
97 100
        return self._session
98
    
101

  
99 102
    def get_capabilities(self, whose):
100 103
        if whose in ('manager', 'client'):
101 104
            return self._session._client_capabilities
102 105
        elif whose in ('agent', 'server'):
103 106
            return self._session._server_capabilities
104
    
107

  
105 108
    @property
106 109
    def capabilities(self):
107 110
        return self._session._client_capabilities
111

  
112
    @property
113
    def server_capabilities(self):
114
        return self._session._server_capabilities

Also available in: Unified diff