public class Device
extends java.lang.Object
implements java.io.Serializable
DeviceUser which contain information
about how to connect to the device.
Associated to a device is a list of named sessions, each session is a
NetconfSession session inside an SSH channel. We can have several
sessions to one device. It can for example make sense to have one session
open to the configuration db(s) and another session open for NETCONF
notifications Typical usage pattern is:
String localUserName = "joe";
DeviceUser duser = new DeviceUser(localUserName, "admin", "secret");
Device dev = new Device("mydev", duser, "netconf.tail-f.com", 8023);
dev.connect(localUserName);
dev.newSession("cfg");
Element someConfigTree = makeMyTree();
dev.getSession("cfg").editConfig(someConfigTree);
Once we have a new session, we also get a configTree (Element) that we can use to accumulate changes in for the session. This usually handy since the manager code typically consists of bits and pieces that manipulate different parts of the configuration. Then it is convenient to let all manager code add Elements to the session specifig config tree. The tree can be accessed through the getConfig(String) method.
This class also provides basic backlog funtionality. If the device configuration is changed and the device is currently down for some reason, a backlog with the configuration change can be saved and run later when the device comes up again.
| Modifier and Type | Field and Description |
|---|---|
protected java.util.ArrayList<Element> |
backlog
A list of configuration changes.
|
protected SSHConnection |
con
An SSH Connection to this device.
|
protected java.util.ArrayList<com.tailf.jnc.Device.SessionConnData> |
connSessions
The NETCONF sessions (channels) for this device.
|
protected int |
defaultReadTimeout
Time to wait for read, in milliseconds.
|
protected java.lang.String |
mgmt_ip
ip address as string
|
protected int |
mgmt_port
port number
|
java.lang.String |
name
The name of the device, or its IP address.
|
protected java.util.ArrayList<com.tailf.jnc.Device.SessionTree> |
trees |
protected java.util.ArrayList<DeviceUser> |
users
A list of users.
|
| Constructor and Description |
|---|
Device(java.lang.String name,
DeviceUser user,
java.lang.String mgmt_ip,
int mgmt_port)
Constructor for the Device with on initial user.
|
Device(java.lang.String name,
java.lang.String mgmt_ip,
int mgmt_port)
Constructor for the Device with on initial user.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addBackLog(Element e)
Adds the given configuration tree to the list of backlogs.
|
void |
addUser(DeviceUser user)
Adds a user to the Device list of users.
|
void |
clearConfig(java.lang.String sessionName)
Clears the accumulation config tree for a named NETCONF session
|
void |
close()
end all NETCONF sessions and close the SSH socket associated to this
device It also clears all accumulated config trees.
|
void |
closeSession(java.lang.String sessionName)
Close the named session associated with this device.
|
void |
connect(java.lang.String localUser)
This method finds the
DeviceUser associated to the localUser
user name and SSH connects to the device, this method must be called
prior to establishing any sessions (channels) |
void |
connect(java.lang.String localUser,
int connectTimeout)
This connect() method has an additional timeout paramater.
|
Element[] |
getBacklog()
Return the backlog.
|
Element |
getConfig(java.lang.String sessionName)
Returns the accumulated config tree for a named NETCONF session.
|
long |
getReadTimeout(java.lang.String sessionName)
Gets the readTimeout associated to a named session
|
NetconfSession |
getSession(java.lang.String sessionName)
Returns a named NetconfSession for this NETCONF enabled device.
|
SSHSession |
getSSHSession(java.lang.String sessionName)
Returns a named SSHSession for this NETCONF enabled device.
|
java.util.ArrayList<DeviceUser> |
getUsers()
Return the list of users.
|
boolean |
hasBacklog()
Checks if a backlog is saved for this device.
|
boolean |
hasConfig(java.lang.String sessionName)
Check if the named session have a saved configuration tree.
|
boolean |
hasSession(java.lang.String name)
Checks if this device has any sessions with specified name.
|
void |
initTransients()
If Device is stored on disk as a serialized object, we need to init the
transient variables after we read a Device from disk.
|
void |
newSession(IOSubscriber sub,
java.lang.String sessionName)
Creates a new named NETCONF session We must not have an existing session
with the same name.
|
void |
newSession(java.lang.String sessionName)
Creates a new named NETCONF session.
|
void |
newSessionConfigTree(java.lang.String sessionName)
This method is mostly interesting if we want to use the backlog
functionality.
|
void |
runBacklog(java.lang.String sessionName)
Run the backlog.
|
void |
setConfig(java.lang.String sessionName,
Element e)
Sets the accumulation config tree for a named session
|
void |
setDefaultReadTimeout(int defaultReadTimeout)
Whenever new NetconfSession objects are created through newSession() set
this timeout value (milliseconds) as the readTimeout value
|
void |
setReadTimeout(java.lang.String sessionName,
int readTimeout)
Sets the readTimeout associated to a named session
|
java.lang.String |
toString()
Returns a string with information about this device.
|
public java.lang.String name
protected transient SSHConnection con
protected transient java.util.ArrayList<com.tailf.jnc.Device.SessionConnData> connSessions
protected transient java.util.ArrayList<com.tailf.jnc.Device.SessionTree> trees
protected java.util.ArrayList<Element> backlog
protected java.util.ArrayList<DeviceUser> users
protected java.lang.String mgmt_ip
protected int mgmt_port
protected int defaultReadTimeout
public Device(java.lang.String name,
DeviceUser user,
java.lang.String mgmt_ip,
int mgmt_port)
public Device(java.lang.String name,
java.lang.String mgmt_ip,
int mgmt_port)
public void initTransients()
public void addUser(DeviceUser user)
public java.util.ArrayList<DeviceUser> getUsers()
public void clearConfig(java.lang.String sessionName)
sessionName - symbolic Name of the sessionpublic Element getConfig(java.lang.String sessionName)
sessionName - symbolic Name of the sessionpublic void setReadTimeout(java.lang.String sessionName,
int readTimeout)
sessionName - symbolic Name of the sessionreadTimeout - timeout in millisecondspublic long getReadTimeout(java.lang.String sessionName)
sessionName - symbolic Name of the sessionpublic boolean hasConfig(java.lang.String sessionName)
sessionName - symbolic Name of the sessionpublic void setConfig(java.lang.String sessionName,
Element e)
sessionName - symbolic Name of the sessione - The config tree to insert.public boolean hasBacklog()
public void setDefaultReadTimeout(int defaultReadTimeout)
public void closeSession(java.lang.String sessionName)
sessionName - symbolic Name of the sessionpublic void close()
public boolean hasSession(java.lang.String name)
public NetconfSession getSession(java.lang.String sessionName)
Session s = ((SSHSession) d.getSession("cfg").getTransport()).getSession();
This is required to monitor the ganymed Session object for EOFpublic SSHSession getSSHSession(java.lang.String sessionName)
SSHSession object if we for example wish to check if an ssh
session is ready to read.public void connect(java.lang.String localUser)
throws java.io.IOException,
JNCException
DeviceUser associated to the localUser
user name and SSH connects to the device, this method must be called
prior to establishing any sessions (channels)java.io.IOExceptionJNCExceptionpublic void connect(java.lang.String localUser,
int connectTimeout)
throws java.io.IOException,
JNCException
localUser - The name of a local (for the EMS) userjava.io.IOExceptionJNCExceptionpublic void newSessionConfigTree(java.lang.String sessionName)
public void newSession(java.lang.String sessionName)
throws JNCException,
java.io.IOException,
YangException
sessionName - symbolic Name of the sessionJNCExceptionjava.io.IOExceptionYangExceptionpublic void newSession(IOSubscriber sub, java.lang.String sessionName) throws JNCException, java.io.IOException
sub - IO subscriber for trace messages.sessionName - symbolic Name of the sessionJNCExceptionjava.io.IOExceptionpublic void addBackLog(Element e)
e - Config tree to be saved.public Element[] getBacklog()
public void runBacklog(java.lang.String sessionName)
throws java.io.IOException,
JNCException
sessionName - symbolic Name of the sessionjava.io.IOExceptionJNCExceptionpublic java.lang.String toString()
toString in class java.lang.Object