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.
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.
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
Complete the following steps to create Configlets using the Configlet Builder:
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
- Example 2: eAPI-based management interface Configlet Builder
- Example 3: SSH-based management interface Configlet Builder
- Example 4: MySQL-based management interface Configlet Builder
- Example 5: Device library based management interface Configlet Builder
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.
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.
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.
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.
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.
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
Complete these steps to manually create Configlets:
Validating a Configlet During Creation
CloudVision provides a facility to enter the Configlet code and validate it before saving the codes.