Package com.tailf.ned
Class NedCliBase
Object
com.tailf.ned.NedConnectionBase
com.tailf.ned.NedCliBase
- Direct Known Subclasses:
NedCliBaseTemplate
This class is used for connections between the NCS and CLI based
NEDs. A NedCli instance must be combined with a YANG data model
that models the data and CLI commands used for talking to the device.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
Is invoked by NCS to abort the configuration to the state before the previous prepare() invocation.initNoConnect
(String device_id, NedMux mux, NedWorker worker) Make a new instance of Ned object without establishing a connection towards the device.abstract boolean
isConnection
(String deviceId, 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.abstract NedCliBase
newConnection
(String deviceId, 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 w) Establish a new connection to a device and send response to NCS with information about the device.abstract void
Is invoked by NCS to take the configuration to a new state.abstract void
prepareDry
(NedWorker w, String data) Is invoked by NCS to tell the NED what actions it should take towards the device if it should do a prepare.abstract void
Is invoked by NCS to undo the changes introduced in the last commit operation (communicated to the NED in the prepare method invocation).abstract void
Extract parts of the configuration and send it to NCS.void
showOffline
(NedWorker w, String toptag, String data) Extract parts of the configuration and send it to NCS.void
showPartial
(NedWorker w, ConfPath[] paths) Extract parts of the configuration and send it to NCS.void
showPartial
(NedWorker w, ConfPath[] paths, String[] cmdpaths) Extract parts of the configuration and send it to NCS.void
showPartial
(NedWorker w, String[] cmdpaths) Deprecated.Methods inherited from class com.tailf.ned.NedConnectionBase
close, close, command, commit, connection_id, createSubscription, device_id, getCapas, getConnectionId, getStatsCapas, getSystemStateData, getTimeInPool, getTransactionIdMode, getTransId, getUseStoredCapas, getWantRevertDiff, identity, initialize, isAlive, isAlive, keepAlive, modules, persist, reconnect, setCapabilities, setConnectionData, setPlatformData, showStatsFilter, showStatsFilter, showStatsFilter, showStatsPath, type, uninitialize, useStoredCapabilities
-
Constructor Details
-
NedCliBase
public NedCliBase()
-
-
Method Details
-
prepare
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)- Parameters:
w
- 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
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
.- Parameters:
w
- 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
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.- Parameters:
w
- 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
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.- Parameters:
w
- 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
-
show
Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.- Parameters:
w
- 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
-
showPartial
Deprecated.Use the methodshowPartial(NedWorker,ConfPath[],String[])
instead. Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.- Parameters:
w
- 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.cmdpaths
- are cmd paths to filter the various parts of the configuration tree that should be extracted.- Throws:
Exception
-
showPartial
Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.- Parameters:
w
- 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.paths
- are paths to filter the various parts of the configuration tree that should be extracted.- Throws:
Exception
-
showPartial
Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.- Parameters:
w
- 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.paths
- are paths to filter the various parts of the configuration tree that should be extracted.cmdpaths
- are cmd paths to filter the various parts of the configuration tree that should be extracted.- Throws:
Exception
-
showOffline
Extract parts of the configuration and send it to NCS. The response is sent by invoking the w.showCliResponse() method in the provided NedWorker.- Parameters:
w
- 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.data
- is the CLI commands in native format.- Throws:
Exception
-
isConnection
public abstract boolean isConnection(String deviceId, 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. If the current connection is has the same parameters it should return true, otherwise false.- Parameters:
deviceId
- 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
-
newConnection
public abstract NedCliBase newConnection(String deviceId, 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 w) 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.- Parameters:
deviceId
- 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 millisecondsmux
-w
- 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
-
initNoConnect
public NedCliBase initNoConnect(String device_id, NedMux mux, NedWorker worker) throws NedWorker.NotEnoughDataException Make a new instance of Ned object without establishing a connection towards the device. The NED should use previously stored information about the device to initialize its state if needed or throw NedWorker.NotEnoughDataException. It should then send the information about the device using the setConnectionData() method. A new instance representing the new connection should be returned. That instance can only be used for invoking prepareDry() callback and not for actual communication with the device. close() callback will be invoked before destroying the NED instance, so the implementation of the close() callback should handle cleanup both for instances created with newConnection() and instanced created with initNoConnect()- Parameters:
device_id
- name of devicemux
-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.- Returns:
- the NED instance
- Throws:
NedWorker.NotEnoughDataException
-
showPartial(NedWorker,ConfPath[],String[])
instead.