Cloud-edge Collaboration API Development Example

This section describes how to add a cloud-edge collaboration API and provides guidance for secondary development.

File Description

The file path involved in the development example is {project_dir}/src/app/add_extend_fusion_director_interface. The specific file directory structure is as follows:
├── build_extend_fusion_director_interface.sh         // Build script
├── new_constants.py                                  // Configuration file that defines the mapping between cloud-edge collaboration topics and manipulation functions
├── default_capability.json                           // Configuration file of capability items
├── fd_extend_interfaces.py                           // Configuration file of the extended cloud-edge collaboration API
└── msg_handlers.py                                   // Script for implementing the cloud-edge collaboration API
└── topic.py                                          // Script for defining cloud-edge collaboration topics

Procedure

  1. Enable the cloud-edge collaboration API adding function.

    Change the value of the _NeedAddExtendFusionDirectorInterface field in the project.conf file to yes (the default value is no).

  2. Define extended topics in topic.py.
    class NewTopic:
        # Write dflc lifecycle information.
        SUB_CONFIG_DFLC = "$hw/edge/v1/hardware/operate/config_dflc"
  3. Add a custom API to msg_handlers.py.
    class NewFDMessageHandler:
        @staticmethod
        def config_netmanager_dflc(payload):
            pass
    
        @staticmethod
        def handle_msg_config_dflc(msg):
            NewFDMessageHandler.config_netmanager_dflc(msg.content)
  4. Define the mapping between messages and the API in new_constants.py.
    from add_extend_fusion_director_interface.topic import NewTopic
    from add_extend_fusion_director_interface.msg_handlers import NewFDMessageHandler
    MSG_HANDLING_MAPPING = {
        NewTopic.SUB_CONFIG_DFLC: NewFDMessageHandler.handle_msg_config_dflc,
    }
  5. Add the path for storing the new mapping.

    Write the path for storing the mapping in the EXTEND_FD_TOPIC_HANDLER_MAPPING_PATH field in the fd_extend_interfaces.py configuration file.

    # Path of the mapping between the new cloud-edge collaboration topic and manipulation function
    EXTEND_FD_TOPIC_HANDLER_MAPPING_PATH = "add_extend_fusion_director_interface." \
                                           "new_constants.MSG_HANDLING_MAPPING"
  6. Add new capability items to the capability item configuration file default_capability.json so that corresponding messages can be delivered by FusionDirector. In addition, FusionDirector adaptation is required. Developers can copy the capability item configuration file /config/default_capability.json in om-sdk.tar.gz to the built project {project_dir}/src/app/add_extend_fusion_director_interface and add extended capability items. The following digital_warranty is an extended capability item.
    {
        "esp_enable": true,
        "product_capability": [
            "profile",
            "Assettag",
            "restart",
            "firmware_install",
            "info_collect",
            "rearm",
            "hostname_config",
            "ntp_server_config",
            "partition_config",
            "static_host_config",
            "name_server_config",
            "nfs_config",
            "net_manager_config",
            "password_config",
            "password_validity_config",
            "configuration_restore",
            "digital_warranty", 
            "cert_mgmt",
            "lte_config",
            "access_control",
            "session_timeout_config",
            "cert_alarm_time_config",
            "security_load_config"
        ]
    }
  7. Implement the compiled and packaged code in the build script build_extend_fusion_director_interface.sh.
    #!/bin/bash
    SCRIPT_NAME=$(basename "$0")
    CUR_DIR=$(dirname "$(readlink -f "$0")")
    TOP_DIR="${CUR_DIR}"/../../..
    OUTPUT_PACKAGE_DIR="${TOP_DIR}"/platform/omsdk
    function add_extend_fd_interfaces()
    {
        local redfish_server_dir="${OUTPUT_PACKAGE_DIR}"/software/RedfishServer
        [ ! -d "${redfish_server_dir}/add_extend_fusion_director_interface" ] && mkdir "${redfish_server_dir}"/add_extend_fusion_director_interface
        cp -rf "${CUR_DIR}"/*.py "${redfish_server_dir}"/add_extend_fusion_director_interface
        # The extended API configuration module must overwrite the field name in the d_extend_interfaces.py configuration file of the OM SDK with fixed values.
        cp -rf "${CUR_DIR}"/fd_extend_interfaces.py "${redfish_server_dir}"/
        # Pack the capability item configuration file.
        cp -rf "${CUR_DIR}"/default_capability.json "${OUTPUT_PACKAGE_DIR}"/config/default_capability.json
        cp -rf "${CUR_DIR}"/default_capability.json "${redfish_server_dir}"/config/
    }
    add_extend_fd_interfaces
  8. Implement the code for calling the compilation script of the new cloud-edge collaboration API in {project_dir}/build/build.sh.
    # Add the extended fusion director API.
    # For details about the implementation of build_extend_fusion_director_interface.sh, see the corresponding section.
    # TOP_DIR={project_dir}
    if [[ "${_NeedAddExtendFusionDirectorInterface}" == "yes" ]]; then
        if ! bash "${TOP_DIR}/src/app/add_extend_fusion_director_interface/build_extend_fusion_director_interface.sh";then
            return 1
        fi
    fi
The key fields in the configuration file are described as follows:
  • EXTEND_RESTFUL_REGISTER_FUNCTIONS_PATH in restful_extend_interfaces.py: path of the extended RESTful API registration function.
  • EXTEND_FD_TOPIC_HANDLER_MAPPING_PATH in fd_extend_interfaces.py: path of the extended cloud-edge collaboration API registration function.