The netconf.client
Module¶
-
class
netconf.client.
NetconfClientSession
(stream, debug=False)¶ Bases:
netconf.base.NetconfSession
Netconf Protocol
-
close
()¶ Close the session.
-
edit_config
(target='running', method='', newconf='', testopt='', erroropt='', timeout=None)¶ Operate on config in ~target~ using ~newconf~ according to ~method~ (“merge”, “replace” or “none”). If “none” then no nodes are modified until a element specifies the mode as an attribute.
Parameters: - target – the target of the config, defaults to “running”.
- method – “merge” (netconf default), “replace” or “none”.
- newconf – The new configuration.
- testopt – “test-then-set” (netconf default), “set” or “test-only”.
- erroropt – “stop-on-error” (netconf default), “continue-on-error” or “rollback-on-error”.
- timeout – A value in fractional seconds to wait for the operation to complete or None for no timeout.
Returns: The result of the edit operation
Return type: lxml.Element
Raises: ReplyTimeoutError, RPCError, SessionError
-
edit_config_async
(target, method, newconf, testopt, erroropt)¶ Operate on config in ~target~ using ~newconf~ according to ~method~ (“merge”, “replace”, “none”). If “none” then no nodes are modified until a element specifies the mode as an attribute.
Parameters: - target – the target of the config.
- method – “merge”, “replace”, “none”.
- newconf – The new configuration.
- testopt – “test-then-set” (netconf default), “set” or “test-only”.
- erroropt – “stop-on-error” (netconf default), “continue-on-error” or “rollback-on-error”.
Returns: The RPC message id which can be passed to wait_reply for the results.
Raises: SessionError
-
get
(select=None, timeout=None)¶ Get operational state from the server. If select is specified it is either an XPATH expression or XML subtree filter for selecting a subsection of the state. If timeout is not None it specifies how long to wait for the get operation to complete.
Parameters: - select – A XML subtree filter or XPATH expression to select a subsection of state.
- timeout – A value in fractional seconds to wait for the operation to complete or None for no timeout.
Returns: The Parsed XML state (i.e., “<data>…</data>”.)
Return type: lxml.Element
Raises: ReplyTimeoutError, RPCError, SessionError
-
get_async
(select)¶ Get operational state asynchronously from the server. If select is specified it is either an XPATH expression or XML subtree filter for selecting a subsection of the state. If timeout is not None it specifies how long to wait for the get operation to complete.
Parameters: select – A XML subtree filter or XPATH expression to select a subsection of state. Returns: The RPC message id which can be passed to wait_reply for the results. Raises: SessionError
-
get_config
(source='running', select=None, timeout=None)¶ Get config for a given source from the server. If select is specified it is either an XPATH expression or XML subtree filter for selecting a subsection of the config. If timeout is not None it specifies how long to wait for the get operation to complete.
Parameters: - source – the source of the config, defaults to “running”.
- select – An XML subtree filter or XPATH expression to select a subsection of config.
- timeout – A value in fractional seconds to wait for the operation to complete or None for no timeout.
Returns: The Parsed XML config (i.e., “<nc:config>…</config>”.)
Return type: lxml.Element
Raises: ReplyTimeoutError, RPCError, SessionError
-
get_config_async
(source, select)¶ Get config asynchronously for a given source from the server. If select is specified it is either an XPATH expression or XML subtree filter for selecting a subsection of the config.
Parameters: - source – the source of the config, defaults to “running”.
- select – An XML subtree filter or XPATH expression to select a subsection of config.
Returns: The RPC message id which can be passed to wait_reply for the results.
Raises: SessionError
-
is_reply_ready
(msg_id)¶ Check whether reply is ready (or session closed)
-
lock
(target='running', timeout=None)¶ Lock target datastore asynchronously.
If timeout is not None it specifies how long to wait for the get operation to complete.
Parameters: target – A string specifying the config datastore to lock. Returns: None Raises: RPCError, SessionError
-
lock_async
(target)¶ Lock target datastore asynchronously.
Parameters: target – A string specifying the config datastore to lock. Returns: The RPC message id which can be passed to wait_reply for the results. Raises: SessionError
-
send_rpc
(rpc, timeout=None)¶ Send a generic RPC to the server and await the reply.
Parameters: (string) (rpc) – The XML of the netconf RPC, not including the <rpc> tag. Returns: (Message as an lxml tree, Parsed reply content, Parsed message content). Return type: (lxml.etree, lxml.Element, lxml.Element) Raises: RPCError, SessionError
-
send_rpc_async
(rpc, noreply=False)¶ Send a generic RPC to the server and await the reply.
Parameters: - rpc (str or lxml.Element) – The XML of the netconf RPC, not including the <nc:rpc> tag.
- noreply (Boolean) – True if no reply is required.
Returns: The RPC message id which can be passed to wait_reply for the results.
-
unlock
(target='running', timeout=None)¶ Unlock target datastore asynchronously.
If timeout is not None it specifies how long to wait for the get operation to complete.
Parameters: target – A string specifying the config datastore to unlock. Returns: None Raises: RPCError, SessionError
-
unlock_async
(target)¶ Unlock target datastore asynchronously.
Parameters: target – A string specifying the config datastore to unlock. Returns: The RPC message id which can be passed to wait_reply for the results. Raises: SessionError
-
wait_reply
(msg_id, timeout=None)¶ Wait for a reply to a given RPC message ID.
Parameters: msg_id – the RPC message ID returned from one of the async method calls Returns: (Message as an lxml tree, Parsed reply content, Parsed message content). Return type: (lxml.etree, lxml.Element, lxml.Element) Raises: RPCError, SessionError
-
-
class
netconf.client.
NetconfSSHSession
(host, port=830, username=None, password=None, debug=False, cache=None, proxycmd=None)¶
-
netconf.client.
connect_ssh
(host, port=830, username=None, password=None, debug=False, cache=None, proxycmd=None)¶ A context manager method for opening a netconf SSH session.
If username is not specified then it will be obtained with getpass.getuser(). If an ssh agent is available it will be used for authentication. A users .ssh/config will be processed for making the ssh connection and any proxycmd found therein will also be utilized.
Parameters: - host – The host to connect to.
- port – The port to connect to.
- username – The username to connect with. If not specified getpass.getuser() will be used
- password – The password or passkey to authenticate with.
- debug – Enable debug logging
- cache – An SSH cache (sshutil.cache) to use for caching connections.
- proxycmd – A proxy command string for connecting with