Table Of Contents
AXP CLI API
Overview
Java
Java Signatures
Class and Methods
Java Example
C/C++
C/C++ Signatures
Class and Methods
IosServiceAPI_t
C/C++ Example
Perl
Perl Signatures
Perl Example
Python
Python Signatures
Class and Methods
Python Example
Bash
Bash Signatures
Bash Examples
AXP CLI API
The Cisco AXP CLI API is explained in the following sections:
•
Overview
•
Java
•
C/C++
•
Perl
•
Python
•
Bash
Overview
Use the AXP CLI API to issue commands on the Cisco AXP service module. Supported languages are: Java, C/C++, Python, Perl, and Bash.
Multiple configuration commands can be passed at one time by using a comma delimiter. This applies to both exec and configuration commands.
For example, multiple commands can be invoked as follows.
iosapi --mode exec "show clock, show clock"
Note
Commands that require interaction from the user cannot be executed programmatically using the
AXP CLI API.
Java
•
Java Signatures
•
Java Example
Java Signatures
•
Class and Methods
Class and Methods
Table 20 Java AXP CLI API Class and Methods
Class/Method
|
public class AppreMessage {
public void setRequest(String request);
public String getResponse();
public String getRequest()
public void setRequest(String request)
public String getResponse()
public void setResponse(String response)
|
Table 21 shows returned integer values; for example, from calls to exec( ).
Error Status Code and Error String
Table 21 AXP CLI API Return Status Codes
Error Status Code
|
Value
|
Description
|
AppreAPI.OK
|
0
|
Request successfully processed.
|
AppreAPI.FAIL
|
1
|
Request aborted because of an error. If a response string is returned (Java/C), it contains a description of the error.
|
AppreAPI.FILE
|
2
|
Request processed. If a response string is returned (Java/C), it contains the filename and path, and is written to a file.
|
The error string contains the following: "Application [name] Start Failed: [reason]"
Java Example
import com.cisco.aesop.apphosting.appreapi.*;
public static void main (String[] args){
CommonServiceImpl apiCall = new CommonServiceImpl();
AppreMessage msg = new AppreMessage();
msg.setRequest("show run");
status = apiCall.exec(msg)
status = apiCall.config(msg)
C/C++
•
C/C++ Signatures
•
C/C++ Example
C/C++ Signatures
•
Class and Methods
•
IosServiceAPI_t
Class and Methods
AppreMessage_t is a struct containing the request and response string.
typedef struct AppreMessage_t{
Note
The caller is responsible for allocating and freeing memory space occupied by the response string.
IosServiceAPI_t
typedef struct IosServiceAPI_t {
extern int getIosApi(const char *serviceName, IosServiceAPI_t* iosapi);
void set_timeout (int sec)
Table 22 shows returned integer values ; for example, from calls to exec( ).
Error Status Code and Error String
Table 22 Java AXP CLI Return Status Codes
Status Code
|
Value
|
Description
|
APPRE_OK
|
0
|
Request successfully processed.
|
APPRE_FAIL
|
1
|
Request aborted because of an error. If a response string is returned (Java/C), it contains a description of the error.
|
APPRE_FILE
|
2
|
Request processed. If a response string is returned (Java/C), it contains the filename and path, and is written to a file.
|
The error string contains the following data: "Application [name] Start Failed: [reason]"
C/C++ Example
Note
The calling program is responsible for freeing allocated memory. If the calling program sets the char* to NULL, the system allocates the required memory, but the calling program is responsible for freeing the memory.
int main(int argc, char** argv){
status = appreapi_conf(&msg);
status = appreapi_exec(&msg);
Perl
•
Perl Signatures
•
Perl Example
Perl Signatures
sub set_timeout (timeout)
Perl Example
$api = new AppreAPI::AppreAPI();
($val, $res) = $api->exec($req);
($val, $res) = $api->config($req);
Python
•
Python Signatures
•
Python Example
Python Signatures
•
Class and Methods
Class and Methods
sub config (self, request)
Python Example
The request string is input and the status code value is output.
status, response = api.exec(request)
status, response = api.config(request)
Bash
•
Bash Signatures
•
Bash Examples
Bash Signatures
For Bash, commands can be passed as a command list or in a file.
appreapi [--mode name] cmdlist [--timeout <second>]
appreapi [--mode name] --file filename [--timeout <second>]
mode: specifies whether command is an exec or config mode command
cmdlist:
•
config mode: string containing one command
•
exec mode: string containing multiple commands separated by commas
Note
Commas are used to separate commands in the AXP CLI API. (See the Bash example config command below.) However, for the IOS CLI API, semi-colons are used to separate commands.
filename: full path of the file containing list of commands
timeout: connection timeout [in seconds]—not the response timeout
Bash Examples
exec command
bash-3.2# appreapi --mode exec "show clock"
03:09:15.186 GMT Fri Oct 30 2009
exec command (unsuccessful as the command has invalid syntax)
bash-3.2# appreapi --mode exec "show abc"
Could not understand: abcbash-3.2#
config command
bash-3.2# appreapi --mode config "netconf max-sessions 5, no netconf max-sessions"
config command (unsuccessful as the config command can only have a value for username of "sysadmin", not "abc")
bash-3.2# appreapi --mode config "username abc password 0 abc"
Could not understand: abcbash-3.2#