下载
中文
注册

云边协同接口开发示例

本章节将详细介绍如何新增云边协同接口,并指导用户进行二次开发。

文件说明

开发示例中涉及到的文件路径为{project_dir}/src/app/add_extend_fusion_director_interface”,具体的文件目录结构如下:
├── build_extend_fusion_director_interface.sh         // 构建脚本
├── new_constants.py                                  // 定义云边协同topic与处理函数映射关系的配置文件
├── default_capability.json                           // 能力项配置文件
├── fd_extend_interfaces.py                           // 扩展云边协同接口配置文件
└── msg_handlers.py                                   // 云边协同接口实现脚本
└── topic.py                                          // 云边协同topic定义脚本

操作步骤

  1. 打开新增云边协同接口功能开关。

    将project.conf的“_NeedAddExtendFusionDirectorInterface”字段取值改为“yes”(默认值为“no”)。

  2. 在topic.py中定义扩展的topic。
    class NewTopic:
        # dflc生命周期信息写入
        SUB_CONFIG_DFLC = "$hw/edge/v1/hardware/operate/config_dflc"
  3. 在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. 在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. 新增映射关系的存放路径。

    在配置文件fd_extend_interfaces.py中的“EXTEND_FD_TOPIC_HANDLER_MAPPING_PATH”字段中写入映射关系的存放路径。

    # 新增的云边协同Topic与处理函数映射关系路径
    EXTEND_FD_TOPIC_HANDLER_MAPPING_PATH = "add_extend_fusion_director_interface." \
                                           "new_constants.MSG_HANDLING_MAPPING"
  6. 在能力项配置文件default_capability.json中添加新增能力项,FusionDirector才能下发对应消息,且需要FusionDirector进行适配,开发者可将om-sdk.tar.gz中能力项配置文件“/config/default_capability.json”拷贝到自己构建的工程“{project_dir}/src/app/add_extend_fusion_director_interface”里,以此为基础增加扩展的能力项配置,下面digital_warranty就是扩展的能力项。
    {
        "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. 在构建脚本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
        # 扩展接口配置模块须覆盖OM SDK中的fd_extend_interfaces.py,配置文件中的字段名为固定值
        cp -rf "${CUR_DIR}"/fd_extend_interfaces.py "${redfish_server_dir}"/
        # 能力项配置文件打包
        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. {project_dir}/build/build.sh”中实现调用新增云边协同接口的编译脚本的代码。
    #  添加扩展 fusion director 接口
    # build_extend_fusion_director_interface.sh具体实现可参考对应章节实现
    # 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
配置文件里的关键字段说明如下。
  • restful_extend_interfaces.py中的EXTEND_RESTFUL_REGISTER_FUNCTIONS_PATH:用于扩展RESTful接口注册函数路径。
  • fd_extend_interfaces.py中的EXTEND_FD_TOPIC_HANDLER_MAPPING_PATH:用于扩展云边协同接口注册函数路径。