What is the CLI Service API?

The CLI service API allows your application to interact with the underlying CLI server on the host. Your application code can issue EXEC mode commands or configuration mode CLI commands to dynamically query and modify the AXP module configuration. Multiple CLI commands of the same type, exec or configuration, can be submitted as long as they are separated by the comma delimiter.

What package must my application depend upon to use this api?

No package dependency is needed. This functionality is built into the AXP Guest OS.

Do I need to configure the ISR or AXP Module for this API to work?

No additional configuration is required.

Please provide a source code example of this API.

CliServiceTest.java
import com.cisco.aesop.apphosting.appreapi.*;
import java.io.*;

/**
*Sample CliServiceTest class to query and configure the service module with *netconf over beep protocol. In a production level program,the *System.out.println commands should be replaced by logging.
*Be sure to replace the [router-ip] [port] strings in the configureSM *method with your router IP and the matching port number you set up on the *router for netconf communication.
*/
public class CliServiceTest{

/**
*Constructor
*/
public CliServiceTest(){}

/**
* Checks if netconf is already configured on the Service Module
* @return true if netconf configured, otherwise false.
* @throws Exception
*/
public boolean isNetconfConfiguredOnSM() throws Exception{
final String cmd = "show run | include netconf";
boolean result = false;
CommonServiceImpl apiCall = new CommonServiceImpl();
AppreMessage msg = new AppreMessage();

System.out.println("Entering isNetconfConfiguredOnSM");
msg.setRequest(cmd);
if(apiCall.exec(msg) != AppreAPI.FAIL){
String response = msg.getResponse();
if(response.length()>0 && response.indexOf("netconf")!=-1){
result = true;
}
}
else{
throw new Exception("Command failed " + cmd);
}
return result;
}


/**
* Copies the running configuration to the startup configuration
* on the Service Module.
* @throws Exception
*/
public boolean saveConfigurationOnSM() throws Exception{
final String cmd = "copy run start";
boolean result = false;
CommonServiceImpl apiCall = new CommonServiceImpl();
AppreMessage msg = new AppreMessage();

System.out.println("Entering saveConfigurationOnSM");
msg.setRequest(cmd);
if(apiCall.exec(msg) != AppreAPI.FAIL){
result = true;
}
else{
throw new Exception("Command failed " + cmd);
}
return result;
}


/**
* Configures netconf over beep on the service module
* @throws Exception
*/
public boolean configureSM() throws Exception {
final String cmd = "netconf beep initiator [router-ip] [port],netconf max-sessions 16";
boolean result = false;
CommonServiceImpl apiCall = new CommonServiceImpl();
AppreMessage msg = new AppreMessage();

System.out.println("Entering configureSM");
msg.setRequest(cmd);
if(apiCall.config(msg) != AppreAPI.FAIL){
result = true;
}
else{
throw new Exception("Command failed " + cmd);
}
return result;
}


public static void main(String[] args){
try{
System.out.println("Starting application.");
CliServiceTest IOS = new CliServiceTest();
if(!IOS.isNetconfConfiguredOnSM()){
if(IOS.configureSM()){
IOS.saveConfigurationOnSM();
System.out.println("Configured service module.");
}
}
else{
System.out.println("Service module has already been configured.");
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
finally{
System.out.println("Application done.");
}
}

How do I compile the source code example?

To compile this java source code you'll need the jar file appreapi.jar. This jar file is provided in the AXP sdk.  So to compile this code you command line would like something like:

javac -classpath appreapi.jar CliServiceTest.java

Do I need to include the appreapi.jar file in my package?

No. The jar file is included in the AXP Guest OS of your application and resides in the directory /usr/lib/java.

Where are the library files located in the sdk and Guest OS for other language support such as C, C++ and Python?

The files for support of these languages in the sdk are located in the directory axp-sdk.<version>. In the AXP module Guest OS, you'll find files supporting these languages in the /lib directory and child directories below it.

0 Attachments
4735 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments