1 # Copyright 2009 Shikhar Bhushan
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
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,
34 def connect_ssh(*args, **kwds):
35 session = transport.SSHSession(capabilities.CAPABILITIES)
36 session.load_system_host_keys()
37 session.connect(*args, **kwds)
38 return Manager(session)
40 connect = connect_ssh # default
46 def __init__(self, session):
47 self._session = session
49 def _get(self, type, *args, **kwds):
50 op = OPERATIONS[type](self._session)
51 reply = op.request(*args, **kwds)
57 def request(op, *args, **kwds):
58 op = OPERATIONS[op](self._session)
59 reply = op.request(*args, **kwds)
64 def locked(self, target='running'):
65 return LockContext(self._session, target)
67 get = lambda self, *args, **kwds: self._get('get')
69 get_config = lambda self, *args, **kwds: self._get('get-config')
71 edit_config = lambda self, *args, **kwds: self.request('edit-config', *args, **kwds)
73 copy_config = lambda self, *args, **kwds: self.request('copy-config', *args, **kwds)
75 validate = lambda self, *args, **kwds: self.request('validate', *args, **kwds)
77 commit = lambda self, *args, **kwds: self.request('commit', *args, **kwds)
79 discard_changes = lambda self, *args, **kwds: self.request('discard-changes', *args, **kwds)
81 delete_config = lambda self, *args, **kwds: self.request('delete-config', *args, **kwds)
83 lock = lambda self, *args, **kwds: self.request('lock', *args, **kwds)
85 unlock = lambda self, *args, **kwds: self.request('unlock', *args, **kwds)
87 close_session = lambda self, *args, **kwds: self.request('close-session', *args, **kwds)
89 kill_session = lambda self, *args, **kwds: self.request('kill-session', *args, **kwds)
95 self._session.expect_close()