Package com.tailf.ned
Class NedCliBaseTemplate
Object
com.tailf.ned.NedConnectionBase
com.tailf.ned.NedCliBase
com.tailf.ned.NedCliBaseTemplate
This class implements NED CLI template
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionint
static org.apache.logging.log4j.Logger
int
int
boolean
int
-
Constructor Summary
ConstructorDescriptionNedCliBaseTemplate
(String device_id, InetAddress ip, int port, String proto, String ruser, String pass, String secpass, boolean trace, int connectTimeout, int readTimeout, int writeTimeout, NedMux mux, NedWorker worker) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Is invoked by NCS to abort the configuration to the state before the previous prepare() invocation.void
applyConfig
(NedWorker worker, int cmd, String data) void
close()
This method is invoked when a connection close is forced and no NedWorker is involved.void
This method is invoked when the connection is terminated.void
command
(NedWorker worker, String cmdname, ConfXMLParam[] p) This is for any optional commands on the device that are not part of the yang files config data, but is modeled as tailf:actions or rpcs in the device yang files.void
This indicates that the current set of operations should be committed to the running configuration.The device_id is originally provided by NCS to properly identify the device.void
getTransId
(NedWorker worker) When this method is invoked the NED should produce a transaction id that must be changed if any changes has been made to the configuration since the last time the transaction id was requested.void
identity()
This should return the a unique (among registered NedConnection classes) identity.boolean
isAlive()
boolean
isConnection
(String device_id, InetAddress ip, int port, String proto, String ruser, String pass, String secpass, String keydir, boolean trace, int connectTimeout, int readTimeout, int writeTimeout) Used by the connection pool to find a matching connection.String[]
modules()
Which YANG modules are covered by the class instance.newConnection
(String device_id, InetAddress ip, int port, String proto, String ruser, String pass, String secpass, String publicKeyDir, boolean trace, int connectTimeout, int readTimeout, int writeTimeout, NedMux mux, NedWorker worker) Establish a new connection to a device and send response to NCS with information about the device.void
This method is invoked when the currently committed change set should be made permanent.void
Is invoked by NCS to take the configuration to a new state.void
prepareDry
(NedWorker worker, String data) Is invoked by NCS to tell the NED what actions it should take towards the device if it should do a prepare.void
Used for resuming a connection found in the connection pool.void
Is invoked by NCS to undo the changes introduced in the last commit operation (communicated to the NED in the prepare method invocation).void
void
setupTelnet
(NedWorker worker) void
Extract parts of the configuration and send it to NCS.string_dequote
(String aText) string_quote
(String aText) toString()
void
type()
The type is one of "cli" and "generic".Methods inherited from class com.tailf.ned.NedCliBase
initNoConnect, showOffline, showPartial, showPartial, showPartial
Methods inherited from class com.tailf.ned.NedConnectionBase
connection_id, createSubscription, getCapas, getConnectionId, getStatsCapas, getSystemStateData, getTimeInPool, getTransactionIdMode, getUseStoredCapas, getWantRevertDiff, initialize, isAlive, keepAlive, setCapabilities, setConnectionData, setPlatformData, showStatsFilter, showStatsFilter, showStatsFilter, showStatsPath, uninitialize, useStoredCapabilities
-
Field Details
-
device_id
-
connection
-
session
-
ip
-
port
public int port -
proto
-
ruser
-
pass
-
secpass
-
trace
public boolean trace -
tracer
-
connectTimeout
public int connectTimeout -
readTimeout
public int readTimeout -
writeTimeout
public int writeTimeout -
mux
-
LOGGER
public static org.apache.logging.log4j.Logger LOGGER
-
-
Constructor Details
-
NedCliBaseTemplate
public NedCliBaseTemplate() -
NedCliBaseTemplate
-
-
Method Details
-
setupSSH
- Throws:
Exception
-
setupTelnet
- Throws:
Exception
-
trace
-
handshake
- Throws:
Exception
-
reconnect
Description copied from class:NedConnectionBase
Used for resuming a connection found in the connection pool.- Specified by:
reconnect
in classNedConnectionBase
- Parameters:
worker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
-
device_id
Description copied from class:NedConnectionBase
The device_id is originally provided by NCS to properly identify the device. It is the name used for the device by NCS in the list of devices.- Specified by:
device_id
in classNedConnectionBase
-
type
Description copied from class:NedConnectionBase
The type is one of "cli" and "generic". This information is sent to NCS when the NedMux is started to let NCS know how to communicate with each device.- Specified by:
type
in classNedConnectionBase
-
modules
Description copied from class:NedConnectionBase
Which YANG modules are covered by the class instance. This information is defined by the setConnectionData() call and is sent to NCS after initiating a new connection, or when re-establishing a connection. The modules() method is not actually used.- Specified by:
modules
in classNedConnectionBase
-
identity
Description copied from class:NedConnectionBase
This should return the a unique (among registered NedConnection classes) identity. It will be used by NCS when creating new connections to control which of the registered NedConnection classes to use.- Overrides:
identity
in classNedConnectionBase
-
applyConfig
public void applyConfig(NedWorker worker, int cmd, String data) throws NedException, IOException, SSHSessionException, NedCliBaseTemplate.ApplyException -
prepare
Description copied from class:NedCliBase
Is invoked by NCS to take the configuration to a new state. The Ned may choose to apply the changes directly to the device, preferably to a candidate configuration, but if the device lacks candidate support it may choose to apply the changes directly to the running config (typically the case on IOS like boxes). If the configuration changes are later aborted, or reverted, the NCS will provide the necessary commands for restoring the configuration to its previous state. The device should invoke the w.prepareResponse() when the operation is completed. initialize (prepare transaction) / \ / uninitialize (undo preparations) v prepare (send data to device) / \ v v abort | commit(send confirmed commit (ios would do noop)) / \ v v revert | persist (send confirming commit)- Specified by:
prepare
in classNedCliBase
- Parameters:
worker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.data
- is the CLI commands for transforming the configuration to a new state. The commands are generated using the YANG data model in combination with the tailf: extensions to guide the mapping.- Throws:
Exception
-
prepareDry
Description copied from class:NedCliBase
Is invoked by NCS to tell the NED what actions it should take towards the device if it should do a prepare. The NED should invoke the methodprepareDryResponse()
when the operation is completed. If no changes needs to be done just answerprepareDryResponse(data)
If an error is detected answer this through a call toerror()
inNedWorker w
.- Specified by:
prepareDry
in classNedCliBase
- Parameters:
worker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements theNedTracer
API and can be used in, for example, theSSHSession
as a tracer.data
- is the CLI commands for transforming the configuration to a new state. The commands are generated using the YANG data model in combination with the tailf: extensions to guide the mapping.- Throws:
Exception
-
abort
Description copied from class:NedCliBase
Is invoked by NCS to abort the configuration to the state before the previous prepare() invocation. The NCS has calculated the commands needed to reach that state from the current state. The instance may choose to use there commands, or use some other mechanism to reach the same state. When the operation is completed it should invoke the w.abortResponse() method in the NedWorker.- Specified by:
abort
in classNedCliBase
- Parameters:
worker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.data
- is the commands for taking the config back to the previous state. The commands are generated using the YANG data model in combination with the tailf: extensions to guide the mapping.- Throws:
Exception
-
revert
Description copied from class:NedCliBase
Is invoked by NCS to undo the changes introduced in the last commit operation (communicated to the NED in the prepare method invocation). The difference between abort() and revert() is that revert() is invoked after commit() (but before persist), whereas abort() is invoked before commit(). Once the configuration has been made persistent by persist() it can no longer be restored to any previous (potentially saved) state. When the revert operation has been completed the w.revertResponse() method should be called.- Specified by:
revert
in classNedCliBase
- Parameters:
worker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.data
- is the commands for taking the config back to the previous state.- Throws:
Exception
-
commit
Description copied from class:NedConnectionBase
This indicates that the current set of operations should be committed to the running configuration. When completed the w.commitResponse() method should be invoked. Devices that does not support commit() should invoke the w.commitResponse() method without delay. On error invoke the w.error(NedCmd.COMMIT, Error, Reason) method.- Specified by:
commit
in classNedConnectionBase
- Parameters:
worker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.timeout
- If the commit operation does not complete within 'timeout' seconds the operation should be aborted.- Throws:
Exception
-
persist
Description copied from class:NedConnectionBase
This method is invoked when the currently committed change set should be made permanent. This corresponds to copying the running configuration to the startup configuration, on a running/startup device, or issuing the confirming commit operation on a device that supports that. When completed the w.persistResponse() should be invoked. On error invoke the w.error(NedCmd.PERSIST,Error, Reason) method.- Specified by:
persist
in classNedConnectionBase
- Parameters:
worker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.- Throws:
Exception
-
close
Description copied from class:NedConnectionBase
This method is invoked when the connection is terminated. It is not invoked when placing the connection in the connection pool. No response is required, but trace messages may be generated during the close down.- Specified by:
close
in classNedConnectionBase
- Parameters:
worker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.- Throws:
NedException
IOException
-
close
public void close()Description copied from class:NedConnectionBase
This method is invoked when a connection close is forced and no NedWorker is involved. This typically occurs when a connection is removed from the connection pool. No response or trace messages can be sent during the operation.- Specified by:
close
in classNedConnectionBase
-
isAlive
public boolean isAlive()- Overrides:
isAlive
in classNedConnectionBase
-
getTransId
Description copied from class:NedConnectionBase
When this method is invoked the NED should produce a transaction id that must be changed if any changes has been made to the configuration since the last time the transaction id was requested. The transaction id can either be requested from the system, or calculated by the callback, for example by calculating an MD5 checksum of the configuration text. The method should indicate its return status by invoking the method w.error() or w.getTransIdResponse() The method should be implemented if the NED claimed a NedWorker.TransactionIdMode which is not NONE in setConnectionData().- Specified by:
getTransId
in classNedConnectionBase
- Parameters:
worker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.- Throws:
Exception
-
show
Description copied from class:NedCliBase
Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.- Specified by:
show
in classNedCliBase
- Parameters:
worker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.toptag
- is the top level tag indicating which part of the config should be extracted.- Throws:
Exception
-
isConnection
public boolean isConnection(String device_id, InetAddress ip, int port, String proto, String ruser, String pass, String secpass, String keydir, boolean trace, int connectTimeout, int readTimeout, int writeTimeout) Description copied from class:NedCliBase
Used by the connection pool to find a matching connection. If the current connection is has the same parameters it should return true, otherwise false.- Specified by:
isConnection
in classNedCliBase
- Parameters:
device_id
- name of deviceip
- address to connect to deviceport
- port to connect toproto
- ssh or telnetruser
- name of user to connect aspass
- password to use when connectingsecpass
- secondary password to use when entering config mode, set to empty string if not configured in the authgrouptrace
- indicates if raw trace messages should be generated or notconnectTimeout
- in millisecondsreadTimeout
- in millisecondswriteTimeout
- in milliseconds
-
command
Description copied from class:NedConnectionBase
This is for any optional commands on the device that are not part of the yang files config data, but is modeled as tailf:actions or rpcs in the device yang files.- Specified by:
command
in classNedConnectionBase
- Parameters:
worker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.cmdname
- Name of the command (path to action?)- Throws:
Exception
-
newConnection
public NedCliBase newConnection(String device_id, InetAddress ip, int port, String proto, String ruser, String pass, String secpass, String publicKeyDir, boolean trace, int connectTimeout, int readTimeout, int writeTimeout, NedMux mux, NedWorker worker) Description copied from class:NedCliBase
Establish a new connection to a device and send response to NCS with information about the device. This information is set by using the setConnectionData() method. A new instance representing the new connection should be returned. That instance will then be used for further communication with the device. Different worker instances may be used for that communication and the instance cannot assume that the worker used in this invocation will be the same used for the invocations of the prepare, abort, revert, persist, show, etc methods.- Specified by:
newConnection
in classNedCliBase
- Parameters:
device_id
- name of deviceip
- address to connect to deviceport
- port to connect toproto
- ssh or telnetruser
- name of user to connect aspass
- password to use when connectingsecpass
- secondary password to use when entering config mode, set to empty string if not configured in the authgrouppublicKeyDir
- directory to read public keys. null if password is giventrace
- indicates if raw trace messages should be generated or notconnectTimeout
- in millisecondsreadTimeout
- in millisecondswriteTimeout
- in millisecondsworker
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with the NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.- Returns:
- the connection instance
-
toString
-
string_quote
-
string_dequote
-