Revision 4bc8021f ncclient/manager.py
b/ncclient/manager.py | ||
---|---|---|
12 | 12 |
# See the License for the specific language governing permissions and |
13 | 13 |
# limitations under the License. |
14 | 14 |
|
15 |
"Thin layer of abstraction around NCClient"
|
|
15 |
"This module is a thin layer of abstraction around the library. It exposes all core functionality."
|
|
16 | 16 |
|
17 | 17 |
import capabilities |
18 | 18 |
import operations |
... | ... | |
22 | 22 |
logger = logging.getLogger('ncclient.manager') |
23 | 23 |
|
24 | 24 |
|
25 |
#: :class:`Capabilities` object representing the capabilities currently supported by NCClient |
|
26 | 25 |
CAPABILITIES = capabilities.Capabilities([ |
27 | 26 |
"urn:ietf:params:netconf:base:1.0", |
28 | 27 |
"urn:ietf:params:netconf:capability:writable-running:1.0", |
... | ... | |
37 | 36 |
"urn:ietf:params:netconf:capability:interleave:1.0" |
38 | 37 |
#'urn:ietf:params:netconf:capability:notification:1.0', # TODO |
39 | 38 |
]) |
40 |
|
|
39 |
"""`~ncclient.capabilities.Capabilities` object representing the client's capabilities. This is used |
|
40 |
during the initial capability exchange. Modify this if you need to announce some capability not |
|
41 |
already included. |
|
42 |
""" |
|
41 | 43 |
|
42 | 44 |
OPERATIONS = { |
43 | 45 |
"get": operations.Get, |
... | ... | |
55 | 57 |
"poweroff_machine": operations.PoweroffMachine, |
56 | 58 |
"reboot_machine": operations.RebootMachine |
57 | 59 |
} |
58 |
|
|
60 |
"""Dictionary of method names and corresponding `~ncclient.operations.RPC` subclasses. `Manager` |
|
61 |
uses this to lookup operations, e.g. "get_config" is mapped to `~ncclient.operations.GetConfig`. It |
|
62 |
is thus possible to add additional operations to the `Manager` API. |
|
63 |
""" |
|
59 | 64 |
|
60 | 65 |
def connect_ssh(*args, **kwds): |
66 |
"""Initializes a NETCONF session over SSH, and creates a connected `Manager` instance. *host* |
|
67 |
must be specified, all the other arguments are optional and depend on the kind of host key |
|
68 |
verification and user authentication you want to complete. |
|
69 |
|
|
70 |
For the purpose of host key verification, on -NIX systems a user's :file:`~/.ssh/known_hosts` |
|
71 |
file is automatically considered. The *unknown_host_cb* argument specifies a callback that will |
|
72 |
be invoked when the server's host key cannot be verified. See |
|
73 |
:func:`~ncclient.transport.ssh.default_unknown_host_cb` for function signature. |
|
74 |
|
|
75 |
First, ``publickey`` authentication is attempted. If a specific *key_filename* is specified, it |
|
76 |
will be loaded and authentication attempted using it. If *allow_agent* is :const:`True` and an |
|
77 |
SSH agent is running, the keys provided by the agent will be tried. If *look_for_keys* is |
|
78 |
:const:`True`, keys in the :file:`~/.ssh/id_rsa` and :file:`~.ssh/id_dsa` will be tried. In case |
|
79 |
an encrypted key file is encountered, the *password* argument will be used as a decryption |
|
80 |
passphrase. |
|
81 |
|
|
82 |
If ``publickey`` authentication fails and the *password* argument has been supplied, |
|
83 |
``password`` / ``keyboard-interactive`` SSH authentication will be attempted. |
|
84 |
|
|
85 |
:param host: hostname or address on which to connect |
|
86 |
:type host: `string` |
|
87 |
|
|
88 |
:param port: port on which to connect |
|
89 |
:type port: `int` |
|
90 |
|
|
91 |
:param timeout: timeout for socket connect |
|
92 |
:type timeout: `int` |
|
93 |
|
|
94 |
:param unknown_host_cb: optional; callback that is invoked when host key verification fails |
|
95 |
:type unknown_host_cb: `function` |
|
96 |
|
|
97 |
:param username: username to authenticate with, if not specified the username of the logged-in user is used |
|
98 |
:type username: `string` |
|
99 |
|
|
100 |
:param password: password for ``password`` authentication or passphrase for decrypting private key files |
|
101 |
:type password: `string` |
|
102 |
|
|
103 |
:param key_filename: location of a private key file on the file system |
|
104 |
:type key_filename: `string` |
|
105 |
|
|
106 |
:param allow_agent: whether to try connecting to SSH agent for keys |
|
107 |
:type allow_agent: `bool` |
|
108 |
|
|
109 |
:param look_for_keys: whether to look in usual locations for keys |
|
110 |
:type look_for_keys: `bool` |
|
111 |
|
|
112 |
:raises: :exc:`~ncclient.transport.SSHUnknownHostError` |
|
113 |
:raises: :exc:`~ncclient.transport.AuthenticationError` |
|
114 |
|
|
115 |
:rtype: `Manager` |
|
116 |
""" |
|
61 | 117 |
session = transport.SSHSession(CAPABILITIES) |
62 | 118 |
session.load_known_hosts() |
63 | 119 |
session.connect(*args, **kwds) |
64 | 120 |
return Manager(session) |
65 | 121 |
|
66 |
#: Same as :meth:`connect_ssh` |
|
67 | 122 |
connect = connect_ssh |
68 |
|
|
123 |
"Same as :func:`connect_ssh`, since SSH is the default (and currently, the only) transport." |
|
69 | 124 |
|
70 | 125 |
class Manager(object): |
71 | 126 |
|
Also available in: Unified diff