pynetconf
libnetconf wrapper for Python
|
Representation of a connection between a NETCONF server and client. More...
Public Member Functions | |
def | __init__ |
Session constructor. More... | |
def | connect |
Placeholder for the client side session constructor. More... | |
def | accept |
Placeholder for the server side session constructor. More... | |
def | isActive |
Ask if the Session is still active. More... | |
def | get |
Perform the NETCONF <get> operation. More... | |
def | getConfig |
Perform the NETCONF <get-config> operation. More... | |
def | copyConfig |
Perform the NETCONF <copy-config> operation. More... | |
def | deleteConfig |
Perform the NETCONF <delete-config> operation. More... | |
def | killSession |
Perform the NETCONF <kill-session> operation. More... | |
def | lock |
Lock the specified NETCONF datastore. More... | |
def | unlock |
Unlock the specified NETCONF datastore. More... | |
def | processRequest |
Unlock the specified NETCONF datastore. More... | |
Public Attributes | |
id | |
NETCONF Session id. More... | |
host | |
Host where the Session is connected. More... | |
port | |
Port number where the Session is connected. More... | |
user | |
Username of the user connected with the Session. More... | |
transport | |
Transport protocol used for the Session. More... | |
version | |
NETCONF Protocol version used for the Session. More... | |
capabilities | |
List of NETCONF capabilities assigned to the Session. More... | |
Representation of a connection between a NETCONF server and client.
The constructor of the class can be used in two ways: a client side way (the host argument is set) and a server side way (the host argument is None). There are also class methods connect() and accept() making usage of both approaches easier.
def __init__ | ( | host = None , |
|
port = 830 , |
|||
user = None , |
|||
transport = netconf.TRANSPORT_SSH , |
|||
capabilities = None , |
|||
fd_in = -1 , |
|||
fd_out = -1 |
|||
) |
Session constructor.
The parameters have different meaning for calling from client and server. Client side constructor requires the host argument while the server side constructor expects the host argument to be None. The Session class provides connect() and accept() class functions for easier usage of the constructor.
For the client side, if the fd_in and fd_out arguments are specified, arguments host, port, user and transport are only informative. They are not used to establish a connection. In this case the function starts with writing the NETCONF <hello> message to the fd_out and expecting the server's <hello> message (in plain text) in fd_in.
For the server side, these arguments are set STDIN_FILENO and STDOUT_FILENO by default.
host | Client side mandatory argument specifying a domain name or an IP address of the NETCONF server host where to connect. |
port | Port where to connect, if not specified, default NETCONF port value 830 is used. |
user | Username of the session holder. For the client side, it is used to connect to the remote host, for the server side it is used to get correct access rights. In both cases, if not specified, it is extracted from the process UID. |
transport | NETCONF transport protocol specified as one of the NETCONF transport protocol constants. |
capabilities | The list of NETCONF capabilities announced to the other side. By default, the internal list, as set by setCapabilities() function. |
fd_in | File descriptor for reading NETCONF data from. |
fd_out | File descriptor for writing NETCONF data to. |
def accept | ( | user = None , |
|
capabilities = None , |
|||
fd_in = STDIN_FILENO , |
|||
fd_out = STDOUT_FILENO |
|||
) |
Placeholder for the server side session constructor.
user | Username of the session holder, used to get correct access rights. If not specified, it is extracted from the process UID. |
capabilities | The list of NETCONF capabilities announced to the client side. By default, the internal list, as set by setCapabilities() function. |
fd_in | File descriptor for reading NETCONF data from. By default, the NETCONF data are read from the standard input. |
fd_out | File descriptor for writing NETCONF data to. By default, the NETCONF data are written to the standard output. |
def connect | ( | host, | |
port = 830 , |
|||
user = None , |
|||
transport = netconf.TRANSPORT_SSH , |
|||
version = None , |
|||
fd_in = -1 , |
|||
fd_out = -1 |
|||
) |
Placeholder for the client side session constructor.
The Session class function.
When the fd_in and fd_out arguments are specified, arguments host, port, user and transport are only informative. They are not used to establish a connection. In this case the function starts with writing the NETCONF <hello> message to the fd_out and expecting the server's <hello> message (in plain text) in fd_in.
host | Mandatory argument specifying a domain name or an IP address of the NETCONF server host where to connect. |
port | Port where to connect, if not specified, default NETCONF port value 830 is used. |
user | Username used for authentication when connecting to the remote host. If not specified, it is extracted from the process UID. |
transport | NETCONF transport protocol specified as one of the NETCONF transport protocol constants. |
version | Supported NETCONF protocol version specified as the NETCONF capability value. It can be specified as one of the NETCONF version constants netconf::NETCONFv1_0 or netconf::NETCONFv1_1. By default, the supported protocol versions are decided from the capabilities list provided by the getCapabilities() function. During the NETCONF protocol handshake the highest common protocol version for both the server and client is selected for further communication. |
fd_in | File descriptor for reading NETCONF data from. If set, the transport connection must be already established including the user authentication. |
fd_out | File descriptor for writing NETCONF data to. If set, the transport connection must be already established including the user authentication. |
def copyConfig | ( | source, | |
target, | |||
wd = None |
|||
) |
Perform the NETCONF <copy-config> operation.
This function is supposed for the client side only.
source | Source datastore of the data to copy. The value can be one of the netconf::RUNNING, netconf::STARTUP and netconf::CANDIDATE, the URL string if the Session supports the NETCONF :url capability or the complete configuration datastore content provided as a string. |
target | Target datastore where copy the data. The value of the argument is one of the datastore constants or the URL string if the Session supports the NETCONF :url capability. |
wd | The NETCONF :with-defaults mode. Possible values are provided as the WD_* constants of the netconf module. |
def deleteConfig | ( | target | ) |
Perform the NETCONF <delete-config> operation.
This function is supposed for the client side only.
target | Target datastore to be removed. Accepted values are the datastore constants or the URL string if the Session supports the NETCONF :url capability. |
def get | ( | filter = None , |
|
wd = None |
|||
) |
Perform the NETCONF <get> operation.
This function is supposed for the client side only.
filter | Optional string representing NETCONF Subtree filter. |
wd | The NETCONF :with-defaults mode. Possible values are provided as the WD_* constants of the netconf module. |
def getConfig | ( | source, | |
filter = None , |
|||
wd = None |
|||
) |
Perform the NETCONF <get-config> operation.
This function is supposed for the client side only.
source | The datastore where to query. Possible values are netconf::RUNNING, netconf::STARTUP and netconf::CANDIDATE. To allow the last two values, the appropriate NETCONF capability must be supported by the connected server. |
filter | Optional string representing NETCONF Subtree filter. |
wd | The NETCONF :with-defaults mode. Possible values are provided as the WD_* constants of the netconf module. |
def isActive | ( | ) |
def killSession | ( | id | ) |
Perform the NETCONF <kill-session> operation.
This function is supposed for the client side only.
id | String with the ID of a NETCONF Session to kill. |
def lock | ( | target | ) |
Lock the specified NETCONF datastore.
This function is supposed for the client side only.
target | The datastore to lock, accepted values are the datastore constants. |
def processRequest | ( | ) |
Unlock the specified NETCONF datastore.
This function is supposed for the server side only.
It automatically process the next request from the NETCONF client connected via the Session. After the processing RPC, the caller should check if the Session wasn't closed using the isActive() method.
def unlock | ( | target | ) |
Unlock the specified NETCONF datastore.
This function is supposed for the client side only.
target | The datastore to lock, accepted values are the datastore constants. |
capabilities |
List of NETCONF capabilities assigned to the Session.
host |
Host where the Session is connected.
id |
NETCONF Session id.
Read-only.
port |
Port number where the Session is connected.
transport |
Transport protocol used for the Session.
user |
Username of the user connected with the Session.
version |
NETCONF Protocol version used for the Session.