root / ncclient / manager.py @ 94803aaf
History | View | Annotate | Download (1.5 kB)
1 |
# Copyright 2009 Shikhar Bhushan
|
---|---|
2 |
#
|
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
|
6 |
#
|
7 |
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
#
|
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.
|
14 |
|
15 |
import capabilities |
16 |
import operations |
17 |
import transport |
18 |
|
19 |
SESSION_TYPES = { |
20 |
'ssh': transport.SSHSession
|
21 |
} |
22 |
|
23 |
OPERATIONS = { |
24 |
'get': operations.Get,
|
25 |
'get-config': operations.GetConfig,
|
26 |
'edit-config': operations.EditConfig,
|
27 |
'copy-config': operations.CopyConfig,
|
28 |
'validate': operations.Validate,
|
29 |
'commit': operations.Commit,
|
30 |
'discard-changes': operations.DiscardChanges,
|
31 |
'delete-config': operations.DeleteConfig,
|
32 |
'lock': operations.Lock,
|
33 |
'unlock': operations.Unlock,
|
34 |
'close_session': operations.CloseSession,
|
35 |
'kill-session': operations.KillSession,
|
36 |
} |
37 |
|
38 |
class Manager(type): |
39 |
|
40 |
'Facade for the API'
|
41 |
|
42 |
def connect(self, session_type, *args, **kwds): |
43 |
self._session = SESSION_TYPES[session_type](capabilities.CAPABILITIES)
|
44 |
self._session.connect(*args, **kwds)
|
45 |
|
46 |
def __getattr__(self, name): |
47 |
if name in OPERATIONS: |
48 |
return OPERATIONS[name](self._session).request |
49 |
else:
|
50 |
raise AttributeError |