Creating Configlets

CloudVision Portal (CVP) enables you to create Configlets using two different methods. You can create Configlets using the CVP Configlet Builder feature, or you can create them manually. You should use the method that is best suited to your intended use of the Configlet.

Note: The Configlet Builder feature is designed to help you create Configlets dynamically based on variables.

For more information, see:

About the Configlet Builder Feature

The Configlet Builder feature enables you to programatically create device configurations (Configlets) for devices that have relatively dynamic configuration requirements. This helps to prevent you from having to manually code Configlets.

The Configlet Builder feature is essentially a set of user interface (UI) widgets and a python script, that when used together, programatically generate Configlets for a device. The python script is embedded into a python interpreter, which is the component that generates Configlets. The UI widgets are essential if you want to use the feature to generate Configlets with user input.

Note: Using UI widgets associated with a Configlet Builder are optional. If the UI widgets are used, the generated Configlets require user input to be created.

The Configlet Builder can be used to create Configlets for both devices or containers, in the same way that static Configlets can be used with devices or containers. Configlets that are created using the Configlet Builder are executed (including the generation of Configlets) at the point when the Configlet Builder is applied to a device or container, or when a device is added to a container that contains a Configlet Builder.

Creating Configlets Using the Configlet Builder

The Configlet Builder enables you to create Configlets (device configurations). The following Configlet Builder example configures the management interface based on input from the use of UI widgets.

Complete the following steps to create Configlets using the Configlet Builder:

  1. Create a Configlet Builder from the Configlet page.
    Figure 1. Creating a Configlet Builder
  2. (Optional) Define the UI widgets to be associated with the Configlet Builder.
    Figure 2. Configlet UI Widgets

    The widget types are:

    • Text Box – Use for single line text entries (for example, descriptions, host name).
    • Text Area – Use for multiple lines of text (for example, MOTD, or login banner).
    • Drop Down – Use to select a value from a menu as defined in the Value Field.
    • Tick Box – Use to select a value from a tick list as defined in the Value Field.
    • Radio Button – Use to select one option from a set of options as defined in Value Field.
    • IP Address – Use to specify an IP address (this is a Dotted Decimal Address field).
    • Password – Use to specify a single line of text (characters are hidden as they are entered).
  3. Write a Python script that reads the inputs you entered in the previous step and then generates the Configlet.
    Note: The figures listed in this table show examples of the steps involved in writing a script, including an example of use of standard Python syntax to build components of the Configlet.
    Figure Example of Description
    Example (Showing Import of CVP-Specific Internal Libraries) Importing CVP-specific internal libraries into the script The CVP-specific internal libraries are used by the script to access form fields and CVP variables.
    Example (Showing Specification of Field IDs Defined in the Form Builder) Specification of field IDs defined in the Form Builder You must specify the IDs of fields you defined in the Form Builder in Step 2. The fields you specify are included in the Configlet content generated by the script.
    Example (Showing Use Of Standard Python Script Syntax) Use of standard Python syntax The Configlet Builder supports the use of standard Python syntax to build parts of the Configlet. You can also make calls to external files and database.
    Example (Showing Print Output) Print output (Configlet content) The script automatically produces print output from the CVP internal libraries you imported and the fields you have defined in the script. The print output is the content of the Configlet.

    Figure 3. Example (Showing Import of CVP-Specific Internal Libraries)
    Figure 4. Example (Showing Specification of Field IDs Defined in the Form Builder)
    Figure 5. Example (Showing Use Of Standard Python Script Syntax)
    Figure 6. Example (Showing Print Output)
    Note: Complete steps 4 and 5 to test the script to make sure it can generate Configlet content.
  4. Fill in the Form Design fields.
    Figure 7. Filling in the Design Fields
  5. Click Generate.

    The Configlet content is generated and shows in the Built Configlet pane.

    Note: If it is necessary to select a device to generate the Configlet, then select a device from the list of devices under Form Design.
    Figure 8. Selecting a Device from the List of Devices Under Form Design
    Figure 9. Example (Generating Configlet Content)
  6. Validate the generated Configlet on the device by clicking the Tick icon at the upper-right of the page.
    The Validate Device dialog appears.
  7. In the Validate Device pop-up dialog, click Validate.
    Figure 10. Example Script (Validating Device)
    If the device cannot be validated, the error (or errors) are listed in the Validate Device dialog.
  8. (If needed) Correct any errors and repeat step 7 to validate the device.
    The Validate Device dialog shows a message to indicate a successful validation.
    Figure 11. Example Script (Re-Validating Device after Correction)
  9. To apply the new Configlet to the container, do the following:
    1. Go the Network Provisioning page.
    2. Right-click the container and choose Manage > Configlet.
    Figure 12. Select the Container to Apply the New Configlet

    The list of available Configlets appears on the Configlet page.

  10. Select the Configlet to apply to the device by clicking the checkbox next to the name of the Configlet.
    Figure 13. Select Configlet on Configlet Page
  11. To add devices to the container, do the following:
    1. Go the Network Provisioning page.
    2. Right-click the container and choose Device > Add.
    Figure 14. Adding Devices to the Container
  12. Do one of the following:
    • Click Yes to apply the Configlet you selected to all of the devices in the hierarchy.
    • Click No if you do not want to apply the Configlet you selected to all of the devices in the hierarchy.
    Figure 15. Message Indicating Selection of Hierarchical Container

    The Configlet page appears showing the Configlet you selected to apply to the container.

  13. To assign the Configlet Builder to the container you selected, select (click) the Configlet Builder.
    Figure 16. Selecting the Configlet to Assign to the Container
    The page loads a form.
    Figure 17. Form Loaded on Page after you Select the Configlet Builder
  14. Complete (fill in) the form and then click Generate.
    The Configlet Builder creates the new, device-specific Configlet, and the Configlet is shown in the Built Configlet pane.
    Figure 18. Configlet Page Showing New, Device-Specific Configlet

Using the Provided Configlet Builder Examples

CloudVision Portal (CVP) provides some Configlet Builder examples to help you get started using this feature.

You can load the examples to your CVP instance using the following commands:

  • Log into the primary node's Linux shell as root user.
  • Change directory to /cvpi/tools and import the example Configlets using the cvptool.
    ./cvptool.py --host <host> --user <user> --password <pass> --objects Configlets --action restore --tarFile examples.tar.

The provided examples include:

Example 1: Form-based management interface Configlet Builder

This example uses the form to input the management interface configuration, and generates a new Configlet to preserve the configuration.

Figure 19. Example 1

Example 2: eAPI-based management interface Configlet Builder

This example uses eAPI to read the management interface configuration that the device received from the DHCP server during the ZTP boot, and generates a new Configlet to preserve the configuration.

Note: No UI widgets are associated with the Configlet Builder in this example.
Figure 20. Example 2

Example 3: SSH-based management interface Configlet Builder

This example uses SSH to read the management interface configuration that the device received from the DHCP server during the ZTP boot, and generates a new Configlet to preserve the configuration.

Figure 21. Example 3

Example 4: MySQL-based management interface Configlet Builder

In this example, the Configlet Builder uses the device’s MAC address to lookup up its Management IP address, netmask, default route, and host name, which are stored on external MySQL server, and generates a new Configlet to preserve the configuration.

Note: No UI widgets are associated with the Configlet Builder in this example.
Figure 22. Example 4

Example 5: Device library based management interface Configlet Builder

This example uses Device library to read the management interface configuration that the device received from the DHCP server during the ZTP boot, and generates a new Configlet to preserve the configuration.

Figure 23. Example 5

Python Execution Environment

The CloudVision Portal (CVP) python execution is supported by several CVP-specific libraries. These libraries provide access to the various CVP services and device state.

CVP Form

This library provides access to the user interface (UI) widgets that can be associated with a Configlet Builder (see the provided examples for usage details).

The supported methods are:

from cvplibrary import Form
obj =Form.getFieldById( ‘id' );
print obj.getValue()

obj.getFieldById( ‘id' ); - Used to get the UI widget by id
obj.getValue() - To get the value
obj.getFieldID() - To get the unique id
obj.isMandatory() - Gets whether the field is mandatory or not
obj.getHelpText() - To get the help text
obj.getDependsOn() - To get the depends on
obj.getType() - To get the type (TextBox, Dropdown,etc)
obj.getDataValidation() - To get the Data validation

CVP Global Variables and Supported Methods

This library give access to the current execution context for Configlet Builders (see the provided examples for usage details).

The supplied global variables are:

from cvplibrary import CVPGlobalVariables, GlobalVariableNames
CVPGlobalVariables.getValue(GlobalVariableNames.CVP_USERNAME)

Supported GlobalVariableNames:
 CVP_USERNAME - Username of the current user
 CVP_PASSWORD - Password of the current user
 CVP_IP - IP address of the current device
 CVP_MAC - MAC of the current device
 CVP_SERIAL - Serial number of the current device
 CVP_SESSION_ID - Session id of current cvp user
 ZTP_STATE - ZTP state of the device (true/false)
 ZTP_USERNAME - Default username to login to ztp enabled device
 ZTP_PASSWORD - Password to login to ztp enabled device
 CVP_ALL_LABELS - Labels associated to current device
 CVP_CUSTOM_LABELS - Custom labels associated to current device
 CVP_SYSTEM_LABELS - System/Auto generated labels associated to current device

CVP Rest Client

This library allows a Configlet Builder to access any CVP API endpoint. The following is an example:

from cvplibrary import RestClient
url='http://localhost/cvpservice/inventory/devices';
method= 'GET';
client= RestClient(url,method);
if client.connect():
print client.getResponse()

If no certificates are installed on the server, then add the following lines to ignore ssl warnings:

import ssl
ssl._create_default_https_context = ssl._create_unverified_contex

Creating Configlets Manually

CloudVision Portal (CVP) enables you to create Configlet manually. This method should be used to create Configlets that are relatively static.
Note: If you need to create Configlets that require less user input, you may want to use the Configlet Builder feature.

Complete these steps to manually create Configlets:

  1. Select the “+” icon in the grid.
  2. The Create Configlet page appears.
    Figure 24. Create Configlet Page
  3. Click Save to save the Configlet.
  4. This will list the Configlet in the Configlet Management grid.
    When the task is complete, refer to Validating a Configlet During Creation.

Validating a Configlet During Creation

CloudVision provides a facility to enter the Configlet code and validate it before saving the codes.

  1. Enter the Configlet codes in the field provided.
  2. On the right pane, there is a drop-down menu listing all the switches in CloudVision.
  3. Search for the device to be validated.
    Figure 25. Validate-Search Device
  4. Select the switch to validate.
    Figure 26. Select Device
  5. Select Validate.

    On successful validation, the message Successfully Validated is displayed.

    Figure 27. Validate-Success

    When an error occurs, the message error will be displayed.

    Figure 28. Validation Error