pynetconf
libnetconf wrapper for Python
 All Classes Namespaces Functions Variables Pages
Session Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Parameters
hostClient side mandatory argument specifying a domain name or an IP address of the NETCONF server host where to connect.
portPort where to connect, if not specified, default NETCONF port value 830 is used.
userUsername 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.
transportNETCONF transport protocol specified as one of the NETCONF transport protocol constants.
capabilitiesThe list of NETCONF capabilities announced to the other side. By default, the internal list, as set by setCapabilities() function.
fd_inFile descriptor for reading NETCONF data from.
fd_outFile descriptor for writing NETCONF data to.
Returns
Created NETCONF Session object.

Member Function Documentation

def accept (   user = None,
  capabilities = None,
  fd_in = STDIN_FILENO,
  fd_out = STDOUT_FILENO 
)

Placeholder for the server side session constructor.

Parameters
userUsername of the session holder, used to get correct access rights. If not specified, it is extracted from the process UID.
capabilitiesThe list of NETCONF capabilities announced to the client side. By default, the internal list, as set by setCapabilities() function.
fd_inFile descriptor for reading NETCONF data from. By default, the NETCONF data are read from the standard input.
fd_outFile 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.

Parameters
hostMandatory argument specifying a domain name or an IP address of the NETCONF server host where to connect.
portPort where to connect, if not specified, default NETCONF port value 830 is used.
userUsername used for authentication when connecting to the remote host. If not specified, it is extracted from the process UID.
transportNETCONF transport protocol specified as one of the NETCONF transport protocol constants.
versionSupported 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_inFile descriptor for reading NETCONF data from. If set, the transport connection must be already established including the user authentication.
fd_outFile descriptor for writing NETCONF data to. If set, the transport connection must be already established including the user authentication.
Returns
Created NETCONF Session object.
def copyConfig (   source,
  target,
  wd = None 
)

Perform the NETCONF <copy-config> operation.

This function is supposed for the client side only.

Parameters
sourceSource 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.
targetTarget 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.
wdThe 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.

Parameters
targetTarget 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.

Parameters
filterOptional string representing NETCONF Subtree filter.
wdThe NETCONF :with-defaults mode. Possible values are provided as the WD_* constants of the netconf module.
Returns
The result data as a string.
def getConfig (   source,
  filter = None,
  wd = None 
)

Perform the NETCONF <get-config> operation.

This function is supposed for the client side only.

Parameters
sourceThe 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.
filterOptional string representing NETCONF Subtree filter.
wdThe NETCONF :with-defaults mode. Possible values are provided as the WD_* constants of the netconf module.
Returns
The result data as a string.
def isActive ( )

Ask if the Session is still active.

This function is generic for both the client and the server side.

Returns
True if the Session is still connected. If the Session was closed (due to error or close request from the client), the False is returned.
def killSession (   id)

Perform the NETCONF <kill-session> operation.

This function is supposed for the client side only.

Parameters
idString 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.

Parameters
targetThe 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.

Parameters
targetThe datastore to lock, accepted values are the datastore constants.

Member Data Documentation

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.