Goal

This tutorial shows how the Application CLI Extension service enables a onePK application to add commands to the network element's command-line-based management interface (CLI), which can then be used to configure the application from the network element. In addition, it describes how to install listener callbacks into the onePK application and how to respond to show command requests.

Tutorial Code

The code used in this tutorial is available in the ApplicationManagementTutorial.py file located under <SDK Location>/python/tutorials/applmgmt.

The XML containing the custom CLI is available located under <SDK Location>/python/tutorials/applmgmt/cli_ext_tutorial_app.xml.

Requirements/Prerequisites

These steps assume

Steps In Detail

Once you have installed the XSD file into the network element CLI tree, you can write your application to retrieve application configuration data and handle configuration and EXEC events.

Creating an Application Instance

First you should begin by creating an ApplicationCLI instance.

'''
 Note that the application name has to match the name in xml file.
 In this case, in cli_ext_tutorial_app.xml, its name 'cli_tutorial_app'.
'''    
if not tutorial.connect(tutorial.app_name):
    sys.exit(2)
    

Listening for Custom Configuration Commands

Then create an ApplicationConfigCLIListener to listen for the example custom commands that you added to the device. This listener triggers each time a custom configuration command is executed on the onePK-enabled device.

class ExampleConfigListener(ApplicationConfigCliListener):
        
    def handle_event(self, cli_data, client_data):
            
        cli_data_name = cli_data.data_name
        cli_data_value = cli_data.data_value
        print "\ndataName = " + cli_data_name + ", dataValue = " + cli_data_value + ", clientData = " + client_data

Listening for Custom Exec Commands

Next create another listener that listens to EXEC commands on the onePK-enabled device. Once again, this listener triggers each time a custom EXEC command is executed on the device.

class ExampleExecListener(ApplicationExecCliListener):
        
    def handle_event(self, cli_data, client_data):
            
        cli_data_name = cli_data.data_name
        print "\ndataName = " + cli_data_name + ", clientData = " + client_data
        return "PythonClient data"

Retrieving Configuration Information

You can retrieve your current configuration information of the connected device by using the following API:

# Retrieve config value for App config data 'app-category' 

application_cli = ApplicationCli(tutorial.get_network_element(),
                                 tutorial.version,
                                 tutorial.instance,
                                 tutorial.domain )
config_data = application_cli.get_config('app_category_cmd')

Register Custom Command Listeners

You can then register the example listeners that you have created to your onePK-enabled device.

#  Add execListener and configListener 
application_cli.set_exec_listener(ExampleExecListener(), "Show data changed")
application_cli.set_config_listener(ExampleConfigListener(), "Config data changed")

Result

Congratulations! Now you should be able to create custom commands and listen for them on the network element.

Try out this tutorial code by compiling and running it. You can find the code located at: <SDK Location>/python/tutorials/applmgmt/ApplicationManagementTutorial.py.