profile_schema
更新时间:2024/12/19
在Gitcode上查看源码

功能简介

用于存放各组件配置导入导出和装备定制化数据定义schema文件,配置导入导出为用户提供了在不同设备之间实现配置克隆的能力,用户可在某一台设备导出配置文件后应用到其他设备中,实现配置快速部署;装备定制化提供生产装备阶段的配置定制能力,同时装备定制化复用配置导入导出处理流程,装备定制化数据项与配置导入导出数据项独立定义。在处理流程上,由oms组件作为配置导入导出的“代理”对接北向接口,oms接收到北向的用户请求后负责配置数据的基础性的校验、分发和汇总等,相关业务组件负责实际的配置导入导出处理。

关键特性

配置导入导出

总体介绍

  1. schema语法采用标准Json schema语法 + 自定义扩展语法方式实现数据项的描述和校验(​配置导入导出作为一种面向用户的接口,通过schema承载接口的数据模型​),每个schema文件承载一类相关数据的定义;
  2. 组件在配置导入导出时均需要通过schema校验,确保配置导入导出数据的正确性;
  3. 用户通过web/redfish/cli等北向接口进行配置导入导出;
  4. oms组件进行配置导入导出的请求分发;
  5. 其他业务组件负责实际的配置导入导出处理;
  • 导入时按照配置文件中的组件名称将对应组件的配置进行Json序列化,并调用bmc.kepler.MicroComponent.ConfigManage下的Import接口触发组件导入。
  • 导出时分别调用各个组件的Export接口,收集各个组件的导出数据,汇总后生成Json文件返回给用户。

注:导入导出时,​只有存在对应组件的schema文件时,oms才会触发该组件的导入导出​。

资源协作接口上对应信息如下:

bash
# 1、oms导入导出接口
~ ~ # busctl --user introspect bmc.kepler.oms /bmc/kepler/Managers/1/Configurations
NAME                                TYPE      SIGNATURE RESULT/VALUE                            FLAGS
bmc.kepler.Managers.Configurations  interface -         -                                       -
.Export                             method    a{ss}s    u                                       -
.Import                             method    a{ss}s    u                                       -

# 2、组件导入导出接口
~ ~ # busctl --user introspect bmc.kepler.xxx /bmc/kepler/xxx/MicroComponent
NAME                                   TYPE      SIGNATURE RESULT/VALUE    FLAGS
bmc.kepler.MicroComponent.ConfigManage interface -         -               -
.Export                                method    a{ss}     s               -
.Import                                method    a{ss}s    -               -
  • oms组件的bmc.kepler.Managers.Configurations接口下存在Import和Export方法分别负责对接北向用户接口的导入导出功能。
  • 组件的bmc.kepler.MicroComponent.ConfigManage接口下Import和Export方法分别负责对接oms的导入导出请求,组件的导入导出接口由框架在启动阶段自动挂载。

详细介绍

代码仓目录介绍

shell
.
├── CHANGELOG.md         # 记录本仓的变更信息
├── CMakeLists.txt       # 构建配置,定义schema的安装路径
├── README.md
├── conanfile.py
├── conaninfo.py
├── crates
├── mds
   └── service.json     # 定义本仓的版本号
├── permissions.ini
├── schema               # 主目录,存放组件的schema文件
   ├── bios.json          # 组件schema文件,以组件名进行命名,每个组件分别定义一个schema
   ├── iam.json
   └── storage.json
└── test
    └── unit

经过部署后,profile_schema代码仓所有组件的schema文件将被安装到BMC环境的只读目录(/opt/bmc/profile_schema)。进行配置导入时,oms组件负责加载schema并对用户导入的配置数据进行校验,并将校验通过的schema文件下发给对应组件进行导入。配置导出时不做schema校验。

导出配置文件字段说明

  • GeneralInfo: [固定字段]通用信息

    • BMCVersion:[固定字段]BMC软件版本信息
    • ProductName:[固定字段]产品名称
    • ProductUniqueID:[固定字段]产品唯一识别ID
    • ProductSN:[固定字段]产品序列号
    • TimeStamp:[固定字段]时间戳信息
  • Components: [固定字段]全量配置信息

    • Description:[固定字段]组件描述信息
    • ConfigData:[固定字段]组件配置数据
    • Value: [固定字段]配置数据实例的属性取值
    • AttributeType: [固定字段]配置数据实例的属性类型 取值包括: 1)ExportOnly:仅支持导出; 2)ImportAndExport:支持导入和导出;
    • Import: [固定字段]该属性是否需要导入(即是否需要导入生效该属性) 说明:仅AttributeType为ImportAndExport可以配置该字段,true表示当前属性需要导入生效,false表示不需要导入生效。
json
{
    "GeneralInfo": {
        "BMCVersion""5.10.00.01",
        "ProductName": "openUBMC 1.0.0",
        "ProductUniqueID": "0x0207BE00",
        "ProductSN": "xxxxxxxx"
        "TimeStamp": "xxxx-xx-xx xx:xx:xx"
    },
    "Components": {
        "iam": {
            "Description": "Configurations of Identity and Access Management",
            "ConfigData": {
                "Accounts": [
                    {
                        "Id": {
                            "Value": 2,
                            "AttributeType": "ExportOnly",
                            "Import": false
                        },
                        "UserName": {
                            "Value": "******",
                            "AttributeType": "ImportAndExport",
                            "Import": false
                        },
                        "Privilege": {
                            "Value": "Administrator",
                            "AttributeType": "ImportAndExport",
                            "Import": false
                        },
                        "UserRoleId": {
                            "Value": "Administrator",
                            "AttributeType": "ImportAndExport",
                            "Import": true
                        },
                        "PermitRuleIds": {
                            "Value": 1,
                            "AttributeType": "ImportAndExport",
                            "Import": true
                        },
                        "LoginInterface": {
                            "Value": ["SSH", "SNMP", "Local", "Redfish", "SFTP", "Web", "IPMI"],
                            "AttributeType": "ExportOnly",
                            "Import": false
                        },
                        "IsUserEnable": {
                            "Value": true,
                            "AttributeType": "ExportOnly",
                            "Import": false
                        },
                        "IsUserLocked": {
                            "Value": false,
                            "AttributeType": "ExportOnly",
                            "Import": false
                        }
                    }
                ],
                "LDAPController": [
                ]
            }
        },
        "bios": {
            "Description": "Configurations of Bios",
            "ConfigData": {
                "BiosConfig": {
                    "BootTypeOrder0": {
                        "Value": "DVDROMDrive",
                        "AttributeType": "ImportAndExport",
                        "Import": true
                    },
                    "BootTypeOrder1": {
                        "Value": "PXE",
                        "AttributeType": "ImportAndExport",
                        "Import": true
                    },
                    "BootTypeOrder2": {
                        "Value": "HardDiskDrive",
                        "AttributeType": "ImportAndExport",
                        "Import": true
                    },
                    "BootTypeOrder3": {
                        "Value": "Others",
                        "AttributeType": "ImportAndExport",
                        "Import": true
                    },
                    "DDRDebugLevel": {
                        "Value": "Minimum",
                        "AttributeType": "ImportAndExport",
                        "Import": true
                    },
                    "DDRFreqLimit": {
                        "Value": "Auto",
                        "AttributeType": "ImportAndExport",
                        "Import": true
                    },
                    "DdrRefreshSupport": {
                        "Value": true,
                        "AttributeType": "ImportAndExport",
                        "Import": true
                    }
                }
            }
        }
    }
}

schema文件详细介绍

组件的schema文件承载一类相关数据的定义和校验规则,属于对外接口的一部分。

标准schema关键字:

  • type:[固定字段]Json schema 的数据类型
  • properties:[固定字段]Json schema 对象属性键值对

固定名称的属性:

  • Description:[固定字段]固定属性,组件描述字段
  • ConfigData:[固定字段]固定属性,组件配置数据字段

组件自定义数据集合名称:

  • Accounts(示例): [组件自定义]组件配置导入导出数据实例集合

扩展的关键字:

  • AttributeType: [固定字段]配置数据实例对应属性的类型 说明: 1)ExportOnly:仅支持导出; 2)ImportAndExport:支持导入和导出;

  • HideValue:[固定字段]组件导出数据时,是否需要隐藏value。 说明: 1)为true时属性取值为"******”,表示对该属性值进行隐藏。 2)组件schema中不设置该值时,导出文件中默认不隐藏value。

  • Import: [固定字段]设置导出文件的Import字段默认值 说明:仅AttributeType为ImportAndExport可以配置该字段,true表示当前属性需要导入(不设置时默认为true),false表示不需要导入。

组件schema示例:

json
{
    "type": "object",
    "properties": {
        "Description": {
            "const": "Configurations of Identity and Access Management"
        },
        "ConfigData": {
            "type": "object",
            "properties": {
                "Accounts": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "Id": {
                                "type": "number",
                                "AttributeType": "ExportOnly"
                            },
                            "UserName": {
                                "type": "string",
                                "HideValue": true,
                                "AttributeType": "ImportAndExport"
                            },
                            "Privilege": {
                                "type": "string",
                                "Import": false,
                                "AttributeType": "ImportAndExport"
                            },             
                            "UserRoleId": {
                                "type": "string",
                                "AttributeType": "ImportAndExport"
                            },
                            "PermitRuleIds": {
                                "type": "number",
                                "AttributeType": "ImportAndExport"
                            },
                            "LoginInterface": {
                                "type": "array",
                                "items": {
                                    "type": "string",
                                    "enum": ["SSH", "SNMP", "Local", "Redfish", "SFTP", "Web", "IPMI"]
                                },
                                "AttributeType": "ExportOnly"
                            },
                            "IsUserEnable": {
                                "type": "boolean",
                                "AttributeType": "ExportOnly"
                            },
                            "IsUserLocked": {
                                "type": "boolean",
                                "AttributeType": "ExportOnly"
                            }
                        },
                        "required": ["Id", "UserName", "Privilege"]
                    }
                }
            }
        }
    }
}

支持的标准Json schema语法如下:

  • 数据类型:integer、number、string、boolean、array、object、null
  • 字符串长度:minLength、maxLength
  • 正则表达式(字符串) :pattern
  • 枚举值:enum
  • 常量值: const
  • 数组长度: minItems、maxItems
  • 属性数量: minProperties、 maxProperties
  • 必须属性: required
  • 额外属性: additionalProperties
  • 属性名称: propertyNames
  • 数字的范围: minimum、 maximum
  • 排他范围: exclusiveMinimum、 exclusiveMaximum
  • 唯一性: uniqueItems

组件实现自身的导入导出回调

组件需要实现的方法:

  • path: /bmc/kepler/{​组件名称​}/MicroComponent
  • interface: bmc.kepler.MicroComponent.ConfigManage
  • method:
    • Import: 入参(a{ss}ss):a{ss}为ctx,第一个string参数为待导入的组件配置数据(json序列化数据);第二个string参数为导入类型,取值包括:custom:(配置导入导出)、 configuration:(装备定制化数据项导入导出) 返回值:NA
    • Export: 入参(a{ss}s):a{ss}为ctx,string参数为导出类型,取值包括:custom:(配置导入导出)、 configuration:(装备定制化数据项导入导出) 返回值(s):s为组件导出的配置数据(json序列化数据)

实现回调函数:

lua
local config_mgmt = {}

-- 实现导入回调
function config_mgmt.import_cb(ctx, config_data, type)
    -- 组件配置导入实现, config_data为json形式的序列化数据,可以通过cjson.decode(config_data)得到lua table
    -- 结合type参数处理配置导入场景和装备定制项导入场景
end

-- 实现导出回调
function config_mgmt.export_cb(ctx, type)
    -- 组件配置导出实现
    -- 结合type参数处理配置导出场景和装备定制项导出场景
    -- 返回值为string类型,组件需要返回json序列化的config_data(通过cjson.encode对导出数据进行序列化)
end

return config_mgmt

注册回调函数:

lua
local mdb_config_manage = require 'mc.mdb.micro_component.config_manage'
local config_mgmt = require 'config_mgmt'

-- 注册import回调函数
mdb_config_manage.on_import(function(...)
    return config_mgmt.import_cb(...)
end)

-- 注册export回调函数
mdb_config_manage.on_export(function(...)
    return config_mgmt.export_cb(...)
end)

装备定制化

装备定制化使用场景:

1) 客户下单后,在装备测试阶段根据客户提供的配置实现差异化定制,如服务器机型名称、BMC用户名等;

2) 客户服务器故障返厂退库,需要清除客户配置,执行定制化脚本(不带配置项),使BMC配置恢复默认;

openUBMC装备定制化分为两类:

1)不含敏感信息类定制化项:使用配置导入导出方式处理,在配置导入导出函数中实现装备定制化项导入和导出;

2)含敏感信息类定制化项:在定制化脚本中(manifest仓的build/manufacture/customize/function路径下增加脚本)通过IPMI命令实现敏感信息项定制;

定制化配置流程

由于装备定制化复用了配置导入导出处理流程,装备定制化项也需要在schema文件中进行声明,从而借由配置导入导出的能力实现定制化项的校验、分发和收集。

profile_schema的配置

主要流程:

1)在schema中增加CustomSettings字段声明定制化项,该字段与配置导入导出项保持统一层级;

2)配置定制化项的数据类型,数据类型主要是对应组件资源协作接口上的属性类型,用于设置资源协作接口属性;

3)配置装备定制项属性类型,固定为ImportAndExport;

4)配置装备定制项取值约束;

5)配置装备定制项默认取值(CustomDefault字段),整包构建后会生成承载默认值的default_settings.json文件,用于装备定制时的默认取值;

schema示例如下所示:

json
{
    "type": "object",
    "properties": {
        "Description": {
            "const": "Configurations of XXX"
        },
        "ConfigData": {
            "type": "object",
            "properties": {
                "XXX": { 	// 业务配置导入导出项声明
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "Attribute1": {
                                "type": "number",
                                "AttributeType": "ImportAndExport"
                            },
                            "Attribute2": {
                                "type": "string",
                                "AttributeType": "ImportAndExport",
                                "enum": ["NoAction", "Reset", "PowerOff"]
                            }
                        }
                    }
                },
                "CustomSettings": {  // 装备定制化项声明,固定名称,保持与业务导入导出项同一层级
                    "type": "object",
                    "properties": {
                        "BMCSet_XXXX1": {       // 装备定制项名称
                            "type": "number",   // 装备定制项数据类型,对应于ini中定制化项数据类型
                            "AttributeType": "ImportAndExport",  // 装备定制项属性类型,固定为ImportAndExport
                            "enum": [0, 1, 2],  // 装备定制项取值约束
                            "CustomDefault": 1  // 装备定制项默认取值,用于整包构建时生成默认的default_settings.json
                        },
                        "BMCSet_XXXX2": {
                            "type": "number",
                            "AttributeType": "ImportAndExport",
                            "enum": [0, 1, 2],
                            "CustomDefault": 1
                        }
                    }
                }
            }
        }
    }
}

组件仓开发

1)实现装备定制化项导入导出代码,可参考配置导入导出

lua
-- customize_config.lua
local customize_config = {}
 
-- 装备定制化项导入
function customize_config.custom_import(config)
    -- 结合定制化项实现配置导入
    ...
end
 
-- 装备定制化项导出,出参config为导出的定制化项,用于进行定制化校验(此时只做示例,实现也可以通过返回值灵活处理)
function customize_config.custom_export()
    -- 结合定制化项实现配置导出
    ...
end
 
return customize_config

3)将装备定制化流程对接到业务导入导出入口处

lua
-- 配置导入回调函数
function config_mgmt:import_cb(ctx, config_data, type)
    local cfg = cjson.decode(config_data)
    -- 装备定制化项导入
    if type == 'custom' and cfg.ConfigData.CustomSettings then  -- 判断是否存在CustomSettings,如果不存在则不执行装备导入
        customize_config.custom_import(cfg)
    end
 
    -- 配置导入
end
 
-- 配置导出回调函数
function config_mgmt:export_cb(ctx, type)
    -- 装备定制化项导出
    if type == 'custom' then
        local export_data = {}
        export_data.CustomSettings = customize_config.custom_export()
        return json.encode({ConfigData = export_data})
    end
 
    -- 业务配置导出
end

对外接口

资源协作接口

不涉及

IPMI接口

不涉及

配置介绍

不涉及