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:

            - self.bluePrintRuntimeService.setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode): Set the value of the input in the current node template.

            - self.bluePrintRuntimeService.setWorkflowInputValue(workflowName: String, propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode): Set the value of the input in the a specific workflow.

            - self.bluePrintRuntimeService.getWorkflowInputValue(workflowName: String, propertyName: String): get a value of the input in the a specific workflow..

            - self.bluePrintRuntimeService.getInputValue(propertyName: String): get an input value for the current node template



- 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:



  • resolve_and_generate_message_from_template_prefix(artifact_prefix)  To get the resolved template using the template artifact prefix. Use get a template content from the current workflow.

  • retrieve_resolved_template_from_database(key, artifact_template) To get the resolved template using the template artifact prefix and resolution-key. Use retrieve a template content that was previously resolved.

  • set_execution_attribute_response_data(response_data) where response_data is a JsonNode. Set the attribute value of the current node_template.

  • get_node_template_attribute(node_template_name, attribute_key) Get the value into the node template attribute attribute_key.

  • get_input_value(key)  Get input value associated to the key of the current node template. (Not available now)

  •    

  • netconfclient: This class provides all netconf execution functions

Add the following to your artifact to have netconfclient library available:



  • NetconfClient(log, netconfComonent, netconf_connection) The class constructor that provide Netconf service. netconf_connection is a String that identify a device in a node template.

  • connect()  To establish the session with the device

  • disconnect() End session connection with the device

  • lock(config_target=CONFIG_TARGET_CANDIDATE) Lock Netconf device

  • get_config(filter_content="", config_target=CONFIG_TARGET_RUNNING) Get running configs. filter_content is an XML filter config.

  • edit_config(message_content, config_target=CONFIG_TARGET_CANDIDATE, edit_default_peration=CONFIG_DEFAULT_OPERATION_REPLACE)  Push a running config into the device

  • commit(confirmed=False, confirm_timeout=60, persist="", persist_id="")

  • invoke_rpc(rpc_content)

  • cancel_commit(persist_id="")

  • unlock(config_target=CONFIG_TARGET_CANDIDATE) Unlock Netconf device

  • validate(config_target=CONFIG_TARGET_CANDIDATE)

  • discard_change()

  • get(filter_content) Get operational commands.



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:



  • resolve_and_generate_message_from_template_prefix(artifact_prefix)  To get the resolved template using the template artifact prefix. Use get a template content from the current workflow.

  • retrieve_resolved_template_from_database(key, artifact_template) To get the resolved template using the template artifact prefix and resolution-key. Use retrieve a template content that was previously resolved.

  • set_execution_attribute_response_data(response_data) where response_data is a JsonNode. Set the attribute value of the current node_template.

  • get_node_template_attribute(node_template_name, attribute_key) Get the value into the node template attribute attribute_key.

  • get_input_value(key)  Get input value associated to the key of the current node template.

  •     

  • restconf_client: This class provides all Restconf execution functions

Add the following to your artifact to have restconfclient library available:



  • RestconfClient(log, restconf_component) The class constructor that provide Restconf service.

  • web_client_service(identifier)  To establish a Restconf session

  • mount_device(web_client_service, nf_id, mount_payload, content_type="application/xml") Sending mount request to the device

  • configure_device_json_patch(web_client_service, nf_id, configlet_resource_path, configlet_to_apply) Apply a Json patch to configure a device.

  • configure_device_xml_patch(web_client_service, nf_id, configlet_resource_path, configlet_to_apply)  Apply a XML patch to configure a device

  • retrieve_device_configuration_subtree(web_client_service, nf_id, configlet_resource_path)

  • unmount_device(web_client_service, nf_id)

  • set_execution_attribute_response_data(response_data) Set an attribute value in the current node template



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:

SampleScriptingArtifact.kt