|
AdventNet CLI 2.0 API Specification | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.adventnet.cli.config.ConfigAPI
This class can be used for configuring all CLI based devices. The Cisco IOS application will use these APIs to perform the various configuration tasks. A configuration is nothing but a set of tasks to be executed in a sequence, to achieve a desired funtionality. It has APIs which can be invoked to add, delete, modify and run a configuration and also APIs to do similar kind of operations with a task. The configurations are initially defined in a XML file from where it is read.
A sample code snippet for invoking the ConfigAPI is as follows-
public class Test{
public static void main(String args[]){
try{
ConfigAPI capi = new ConfigAPI("ConfigDriver.xml");
System.out.println(" main ********");
Test tst =new Test();
CLIProtocolOptions cliProtOpts = tst.getCLIProtocolOptions(args[0], 23);
capi.openSession(cliProtOpts);
Hashtable result = capi.runConfiguration("confName");
// the result
Iterator itor = result.values().iterator();
while(itor.hasNext())
System.out.println(" result "+itor.next());
capi.closeSession(cliProtOpts.getID());
}
// code to get the CLIProtocolOptions
public CLIProtocolOptions getCLIProtocolOptions(String remoteHost, int remotePort)
throws Exception
{
TelnetProtocolOptionsImpl protocolOptions = new TelnetProtocolOptionsImpl();
protocolOptions.setRemoteHost(remoteHost);
protocolOptions.setRemotePort(remotePort);
protocolOptions.setLoginName("guest");
protocolOptions.setPassword("guest");
protocolOptions.setLoginPrompt("login:");
protocolOptions.setPasswdPrompt("Password:");
protocolOptions.setPrompt("$");
return protocolOptions;
}
}
| Constructor Summary | |
ConfigAPI()
Creates a new ConfigAPI instance (default constructor). |
|
ConfigAPI(java.lang.String confXml)
Creates a new ConfigAPI instance. |
|
| Method Summary | |
void |
addConfiguration(ConfigObject cobject)
Adds the configuration to the existing list of configuration. |
void |
appendTask(java.lang.String configName,
Task task)
Appends the task to the end of the tasklist. |
void |
closeSession(java.lang.Object id)
Closes the session established by the user and also removes the ExecutionInterface maintained for the session id. |
ConfigObject |
deleteConfiguration(java.lang.String configName)
Deletes the configuration with the given name. |
Task |
deleteTask(java.lang.String configName,
java.lang.String taskName)
Deletes the task with the given name belonging the specified configuration. |
java.util.Hashtable |
getConfigList()
Gets the configurations defined in the xml file, along with their tasks. |
ConfigObject |
getConfiguration(java.lang.String configName)
Gets the configuration with the name passed to it. |
java.lang.String[] |
getConfigWithData(java.lang.String configName,
TaskData[] data,
java.lang.Object id)
This API can be used when 'ready to run' cmd / script is required for a given configuration. |
java.lang.String |
getCurrentLoginLevel()
Gets the loginLevel currently used for the session. |
java.lang.String |
getExecutionIfcClassName()
Gets the name of the ExecutionInterface implementation class. |
ExecutionInterface |
getExecutionIfcInstance()
Gets the ExecutionInterface implementation class instance. |
ExecutionInterface |
getExecutionInterface()
Gets the ExecutionInterface implementation instance of the current session in the ConfigAPI. |
LoginLevel |
getLoginLevel(java.lang.String loginLevel)
Gets the LoginLevel object with the given name. |
java.lang.String[] |
getParamsOfCommand(java.lang.String cmdName)
Gets the parameters present in the command (both optional and compulsory ones). |
java.util.Hashtable |
getResultOfConfig(java.lang.String configName,
java.lang.String[] configCmds)
Executes the command and returns the result of the command as a string. |
java.lang.String |
getResultOfTask(java.lang.String taskName,
java.lang.String taskCmd,
java.lang.String configName)
Returns the result after the execution of the command. |
java.lang.String |
getTaskCmd(java.lang.String taskName,
java.lang.String configName,
TaskData data,
java.lang.Object id)
Gets the command for the specified task name. |
Task |
getTaskOfConfig(java.lang.String configName,
java.lang.String taskName)
Gets the task belonging to the given configuration of the ConfigAPI. |
void |
insertTask(java.lang.String configName,
Task task,
java.lang.String beforeTask)
Adds the task to the existing list of tasks for the specified configuration. |
void |
loadConfiguration(java.lang.String configXML)
This method can be used for dynamically loading a xml file. |
void |
openSession(CLIProtocolOptions cliProtOpts)
Opens a CLI Session with the remote host set in the CLIProtocolOptions. |
java.util.Hashtable |
runConfiguration(java.lang.String configName)
Executes the configuration given to it. |
java.util.Hashtable |
runConfiguration(java.lang.String configName,
TaskData[] data)
Executes the configuration given to it. |
java.util.Hashtable |
runConfiguration(java.lang.String configName,
TaskData[] data,
java.lang.Object id)
Executes the configuration for the session, whose ID is taken from the third argument of the API. |
java.lang.String |
runTask(java.lang.String taskName,
java.lang.String configName,
TaskData data)
Executes the task in a configuration. |
java.lang.String |
runTask(java.lang.String taskName,
java.lang.String configName,
TaskData data,
java.lang.Object id)
Executes the task in a configuration. |
void |
saveChangesToXmlFile()
Saves the changes made to the task or configuration to the xml file. |
void |
setCurrentLoginLevel(java.lang.String logLevelName)
Sets the current login level as the given name. |
void |
setDataInterface(java.lang.String configName,
DataInterface iface)
Sets the DataInterface of the given configuration. |
void |
setExecutionIfcClassName(java.lang.String className)
Sets the ExecutionInterface implementation classname. |
void |
setExecutionInterface(ExecutionInterface iface)
Sets the Execution Interface implementation instance for the current session. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public ConfigAPI()
ConfigAPI instance (default constructor).
public ConfigAPI(java.lang.String confXml)
throws ConfigException
ConfigAPI instance. It also instantiates the
configXmlParser which parses the xml file passed to it.confXml - the name of the Xml file that contains data for
configuration.| Method Detail |
public java.util.Hashtable getConfigList()
Hashtable having the configuration name and
configObject as the key-value pairs.public java.lang.String getExecutionIfcClassName()
getExecutionIfcInstance() method for
instantiation. It takes the default value as
"com.adventnet.cli.config.ExecutionInterfaceImpl".setExecutionIfcClassName(String),
getExecutionInterface()public void setExecutionIfcClassName(java.lang.String className)
className - the fully qualified classname as a String
value.getExecutionIfcClassName(),
setExecutionInterface(ExecutionInterface)
public ConfigObject getConfiguration(java.lang.String configName)
throws ConfigException
configName - the configuration name.ConfigObject with values as given in the
conf file.
public void loadConfiguration(java.lang.String configXML)
throws ConfigException
configXML - the name of the XML file to be loaded.
public void setDataInterface(java.lang.String configName,
DataInterface iface)
throws ConfigException
saveChangesToXmlFile() method is invoked.configName - the name of the configurationiface - the DataInterface value to be set.public ExecutionInterface getExecutionInterface()
public void setExecutionInterface(ExecutionInterface iface)
iface - the ExecutionInterface implementation class instance.
public java.util.Hashtable runConfiguration(java.lang.String configName)
throws ConfigException
DataInterface.getConfigData(ConfigObject) method of
DataInterface is invoked for
the data. Only if the data is available for the whole configuration, it
proceeds further to run the configuration.
The execution of the task is decided based on the 'mandatory' and 'dataRequired' properties of the Task (command or script). These properties takes boolean value true(t) or false(f).
Mandatory DataRequired Action
f f skips the task (command/script task).
f t if no data, skips the task. otherwise
executes the task.
t f executes the task with the cmd/script.
t t if no data, throws exception. otherwise
executes the task.
When the LoginLevel of the task differs from that of the configuration, this method will switch to the login level of the task before executing it. The LoginLevel will be switched only if its one of the levels/modes defined in the xml, if not it throws an exception. It also exits from the loginlevel after executing the task.
configName - the name of configuration to be run.Hashtable of taskName and result pairs for all
tasks in the configuration.runConfiguration(String, TaskData[]),
getConfigWithData(String, TaskData[], Object)
public java.util.Hashtable runConfiguration(java.lang.String configName,
TaskData[] data)
throws ConfigException
DataInterface.getConfigData(ConfigObject) method of
DataInterface.
Only if the data is available for the whole configuration, it
proceeds further to run the configuration.
The execution of the task is decided based on the 'mandatory' and 'dataRequired' properties of the Task (command or script). These properties takes boolean value true(t) or false(f).
Mandatory DataRequired Action
f f skips the task (command/script task).
f t if no data, skips the task. otherwise
executes the task.
t f executes the task with the cmd/script.
t t if no data, throws exception. otherwise
executes the task.
It executes the configuration in the LoginLevel specified and exits the level after execution of the configuration. When the LoginLevel of the task differs from that of the configuration, this method will switch to the login level of the task before executing it. The LoginLevel will be switched only if its, one of the levels/modes defined in the xml, if not it throws an exception. It also exits from the loginlevel after executing the task.
configName - the name of configuration to be run.data - a TaskData[] array having the data for all the
tasks.Hashtable of taskName and result pairs for all
tasks in the configuration.runConfiguration(String, TaskData[], Object),
getConfigWithData(String, TaskData[], Object),
getResultOfConfig(String, String[])
public java.util.Hashtable runConfiguration(java.lang.String configName,
TaskData[] data,
java.lang.Object id)
throws ConfigException
DataInterface.getConfigData(ConfigObject) method of
DataInterface.
Only if the data is available for the whole configuration, it
proceeds further to run the configuration.
The execution of the task is decided based on the 'mandatory' and 'dataRequired' properties of the Task (command or script). These properties takes boolean value true(t) or false(f).
Mandatory DataRequired Action
f f skips the task (command/script task).
f t if no data, skips the task. otherwise
executes the task.
t f executes the task with the cmd/script.
t t if no data, throws exception. otherwise
executes the task.
It executes the configuration in the LoginLevel specified and exits the level after execution of the configuration. When the LoginLevel of the task differs from that of the configuration, this method will switch to the login level of the task before executing it. The LoginLevel will be switched only if its, one of the levels specified in the xml file, if not it throws an exception. It also exits from the loginlevel after executing the task.
configName - the name of configuration to be run.data - a TaskData[] array having the data for all the
tasks.Hashtable of taskName and result pairs for all
tasks in the configuration.runConfiguration(String, TaskData[], Object),
getConfigWithData(String, TaskData[], Object),
getResultOfConfig(String, String[])
public java.lang.String[] getConfigWithData(java.lang.String configName,
TaskData[] data,
java.lang.Object id)
throws ConfigException
The user can later execute the tasks
by invoking getResultOfConfig(String, String[]) API with
the result obtained from this method. It executes the tasks for the
session ID given to the method.
configName - the name of the configuration which it to be run.data - the data for the configuration as a TaskData[]
array.id - the id of the connection.String[] array containing the commands or scripts
ready to be run, with the data substituted.
public java.util.Hashtable getResultOfConfig(java.lang.String configName,
java.lang.String[] configCmds)
throws ConfigException
getConfigWithData(String, TaskData[], Object) and feeding the
output of the method as an input to this API.
When the LoginLevel of the task differs from that of the configuration, this method will switch to the login level of the task before executing it. It also exits from the loginlevel after executing the task.
It returns a hashtable which contains the taskName and the response corresponding to the task. If a task is skipped, then there would be no entry for the task in the hashtable.
configName - the name of the configuration.configCmds - the commands to be executed with the parameters
substituted in it.Hashtable that contains taskName, response pairs
for a task.
public void addConfiguration(ConfigObject cobject)
throws ConfigException
Also note that the added configuration can be saved to the xml file,
say ConfigDriver.xml, by invoking the method
saveChangesToXmlFile().
cobject - configuration to be added.
public ConfigObject deleteConfiguration(java.lang.String configName)
throws ConfigException
It also updates the xml file, removing the entry for the
configuration from the file, if saveChangesToXmlFile()
is invoked.
configName - name of the configuration to be deleted.
public void insertTask(java.lang.String configName,
Task task,
java.lang.String beforeTask)
throws ConfigException
Also note that the added task is written into the xml file, if
saveChangesToXmlFile() is invoked.
configName - an existing configuration to which the task should
be added.task - the task to be added.beforeTask - the task before which the new task is
to be added.
public void appendTask(java.lang.String configName,
Task task)
throws ConfigException
configName - a String valuetask - a Task value
public Task deleteTask(java.lang.String configName,
java.lang.String taskName)
throws ConfigException
saveChangesToXmlFile() is invoked, it also updates
the xml file, removing
the entry for the task from the file.configName - the configuration to which the task belongs.taskName - the task to be deleted.
public void saveChangesToXmlFile()
throws ConfigException
public java.lang.String getCurrentLoginLevel()
String value
public void setCurrentLoginLevel(java.lang.String logLevelName)
throws ConfigException
ExecutionInterface.setLoginLevel(LoginLevel) method which
should be implemented by the user incase the user wants to override
the default implementation.logLevelName - the login level for the device, one of those defined
in the xml file.
public void openSession(CLIProtocolOptions cliProtOpts)
throws ConfigException
ExecutionInterface.login(CLIProtocolOptions) method for
opening a session to the remote host. It also maintains the
ExecutionInterface corresponding to the Session ID.cliProtOpts - the CLIProtocolOptions with the logging
parameters set.
public void closeSession(java.lang.Object id)
throws ConfigException
id - the ID of the session.
public ExecutionInterface getExecutionIfcInstance()
throws java.lang.Exception
getExecutionIfcClassName() as the class name.public java.lang.String[] getParamsOfCommand(java.lang.String cmdName)
cmdName - the command.String[] array containing the parameters. Returns
null if the command is null or if the command has no parameters.
public LoginLevel getLoginLevel(java.lang.String loginLevel)
throws ConfigException
loginLevel - the name of the LoginLevel.LoginLevel object, if defined for the name.
public Task getTaskOfConfig(java.lang.String configName,
java.lang.String taskName)
throws ConfigException
configName - the name of the configuration.taskName - the name of the task.Task if it is one among the ones defined in the
xml file.
public java.lang.String runTask(java.lang.String taskName,
java.lang.String configName,
TaskData data)
throws ConfigException
DataInterface.getConfigCmdData(String, String)
and DataInterface.getConfigScriptData(String, String) methods of the
DataInterface for the command and script respectively.
The execution of the task is again determined by the 'dataRequired' and 'mandatory' properties of the task respectively which is similar as in the case of runConfiguration.
This API will switch to the login level of the task before executing it. The LoginLevel will be switched only if its, one of the levels defined in the xml, if not it throws an exception. It also exits from the loginlevel after executing the task.
taskName - the name of the task to be executed.configName - the name of the configuration to which the task
belongs.data - the TaskData object from which data is taken
for the command.runConfiguration(String, TaskData[]),
getTaskCmd(String, String, TaskData, Object),
getResultOfTask(String, String, String)
public java.lang.String runTask(java.lang.String taskName,
java.lang.String configName,
TaskData data,
java.lang.Object id)
throws ConfigException
It takes data for the task from the third argument.
If data is null, it tries
to take the data from DataInterface of the configuration.
It invokes the DataInterface.getConfigCmdData(String, String)
and DataInterface.getConfigScriptData(String, String) methods of the
DataInterface for the command and script respectively.
The execution of the task is again determined by the 'dataRequired' and 'mandatory' properties of the task respectively which is similar as in the case of runConfiguration.
This API will switch to the login level of the task before executing it. The LoginLevel will be switched only if its, one of the levels defined in the xml file, if not it throws an exception. It also exits from the loginlevel after executing the task.
taskName - the name of the task to be executed.configName - the name of the configuration to which the task
belongs.data - the TaskData object from which data is taken
for the command.id - the ID of the session, in which the task is to be executed.getTaskCmd(String, String, TaskData, Object),
getResultOfTask(String, String, String),
runConfiguration(String, TaskData[], Object)
public java.lang.String getTaskCmd(java.lang.String taskName,
java.lang.String configName,
TaskData data,
java.lang.Object id)
throws ConfigException
It takes data for the task from the third argument.
If data is null, it tries
to take the data from DataInterface of the configuration.
It invokes the DataInterface.getConfigCmdData(String, String)
and DataInterface.getConfigScriptData(String, String) methods of the
DataInterface for the command and script respectively.
taskName - the name of the taskconfigName - the name of the configuration to which the task
belongs.data - the TaskData object from which data is taken
for the command.id - the ID of the session, in which the task is to be executed.runTask(String, String, TaskData, Object),
getResultOfTask(String, String, String)
public java.lang.String getResultOfTask(java.lang.String taskName,
java.lang.String taskCmd,
java.lang.String configName)
throws ConfigException
getTaskCmd(String, String, TaskData, Object) and feeding the
output of the method as an input to this API.
In case a LoginLevel is specified for the execution of the task, the task is executed after changing the login level. Note that the specified login level is also exited after the execution of the command.
The execution of the task is again determined by the 'dataRequired' and 'mandatory' properties of the task respectively which is similar as in the case of runTask() API.
taskName - the name of the task to be executed.taskCmd - the command or script to be executed with the parameters.configName - the name of the configuration to which the task
belongs.getTaskCmd(String, String, TaskData, Object),
runTask(String, String, TaskData, Object)
|
AdventNet CLI 2.0 API Specification | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||