CDS Library Developer User guide
CDS offers scripting for resource resolution and for Component execution. In both cases, the CDS user needs to make use of existing library in the scripting class or component. Scripting in CDS could be :
Python based:
User provides a python script artifact to execute in two different ways Jython or in a remote python environment defined in CDS as a Component Node Type: Component-remote-executor and Component-netconf-executor.
Kotlin based: That allows CDS user to prepare a customized Kotlin script to execute in CDS runtime environment to resolve a resources.
To implement a such type of script, CDS provides wrapper function for each type of component or function. This documentation describes all the needed library available to the CDS user to design a script artifact.
1) Python Library :
This library is available under cds/components/scripts/python
When defining a script to perform resource resolution or NETCONF, RESTCONF and SSH commands, the user has many functions that he can use do a specific action in CDS such as connect to a Netconf device, get resolved artifacts, push a config is a device etc.
The following list all functions available during each type of execution.
a) Library for Resource Resolution
blueprint_constants: contains all constants related to Python Library
Add to your artifact (python script):
from blueprint_constants import *
blueprint_constants file
PROPERTY_BLUEPRINT_PROCESS_ID= "blueprint-process-id"
PROPERTY_BLUEPRINT_BASE_PATH= "blueprint-basePath"
PROPERTY_BLUEPRINT_RUNTIME= "blueprint-runtime"
PROPERTY_BLUEPRINT_INPUTS_DATA= "blueprint-inputs-data"
PROPERTY_BLUEPRINT_CONTEXT= "blueprint-context"
PROPERTY_BLUEPRINT_NAME= "template_name"
PROPERTY_BLUEPRINT_VERSION= "template_version"
PROPERTY_BLUEPRINT_USER_SYSTEM= "System"
PROPERTY_BLUEPRINT_STATUS_SUCCESS= "success"
PROPERTY_BLUEPRINT_STATUS_FAILURE= "failure"
METADATA_USER_GROUPS = "user-groups"
METADATA_TEMPLATE_NAME = "template_name"
METADATA_TEMPLATE_VERSION = "template_version"
METADATA_TEMPLATE_AUTHOR = "template_author"
METADATA_TEMPLATE_TAGS = "template_tags"
METADATA_WORKFLOW_NAME = "workflow_name"
PAYLOAD_DATA = "payload-data"
PROPERTY_CURRENT_STEP = "current-step"
PROPERTY_CURRENT_NODE_TEMPLATE = "current-node-template"
PROPERTY_CURRENT_INTERFACE = "current-interface"
PROPERTY_CURRENT_OPERATION = "current-operation"
PROPERTY_CURRENT_IMPLEMENTATION = "current-implementation"
PROPERTY_EXECUTION_REQUEST = "execution-request"
abstract_ra_processor: This class provides all Runtime ResourceAssignmentProcessor. The current class helps the user to execute a resource resolution
Add to your artifact:
from abstract_ra_processor import AbstractRAProcessor
abstract_ra_processor file
abstract_ra_processor provides an interface with functions to implement in your python script:
- process(self, resource_assignment): This function is the entry point of the python class. Implement all your business logic here in this class.
- recover(self, runtime_exception, resource_assignment): This function is called when the business logic process fails. It could be helpful to properly terminate resources or contexts.
- set_resource_data_value(self, resource_assignment, value): use to set value of your resource resolution variable.
blueprint_runtime_service: This class provides all CDS Run-time environment. Given this class, your python script can call some run-time execution functions.
Add to your artifact:
blueprint_runtime_service file
This section shows an example of python script Class that can be added as artifact in CDS.
ResolvProperties.py - Sample capability resource resolution artifact
b) Library for Component executions
To design an artifact as a component executor, we should define a Class that inherit AbstractScriptComponentFunction and override function to run actions.
Define Artifacts:
Define a Python Artifact
Define a Kotlin Artifact
Implement your Artifact:
An artifact need to implement at least 2 functions in order to be valid:
Implement component process
Implement component recover
Functions available in Artifact script
The main library available while running a Component in CDS is the BlueprintRuntimeService. This provides to the user the Blueprint running context and run-time execution functions.The following shows functions available for all the different Components execution from a python script:
- NETCONF Component
netconf_constant: contains all constants related to Python Netconf Library
Add to your artifact (python script):
netconf_constant file
common: This class provides all common function in Run-time execution.
Add to your artifact:
netconfclient: This class provides all netconf execution functions
Add the following to your artifact to have netconfclient library available:
NetconfExecutor.py - Sample Netconf executor component Script with python artifact
- RESTCONF Component
restconf_constant: contains all constants related to Python Restconf Library
Add to your artifact (python script):
restconf_constant file
common: This class provides all common function in Run-time execution. (Not available now)
Add to your artifact:
restconf_client: This class provides all Restconf execution functions
Add the following to your artifact to have restconfclient library available:
RestconfExecutor.py - Sample Restconf component Script with python artifact
- CLI Component
CliExecutor.py - Sample Cli component Script with python artifact
2) Scripting functions Library
Developer can decide to go with Kotlin scripting instead of Python. In this case, it will create a Kotlin script class file in the CBA and the class should inherit AbstractScriptComponentFunction. See the example below: