// 此模板仅供参考,如果不适用可以修改
问题描述
方法一:
List + Expand
List用于获取子资源树集合,Expand用于将可访问的URI原地替换为该URI对应的响应体。用于获取指定父路径下特性属性如PortName等于ReqBody的某个属性值的子路径对象,再通过子路径对象获取对象另一个属性,如PortId
{
"Uri": "/cli/v1/lswm/portenable",
"Interfaces": [
{
"Type": "Patch",
"Description": "Set lswm port enable",
"Usage": "ipmcset -t lswm -d portenable -v <PortName> <enable|disable> [PersistType]",
"Example": [
"ipmcset -t lswm -d portenable -v BMC_1 enable",
"ipmcset -t lswm -d portenable -v CAS_1 disable 1"
],
"Confirm": {
"Condition": true,
"Description": "WARNING: The operation may have many adverse effects.\nDo you want to continue?[Y/N]:"
},
"ReqBody": {
"Type": "object",
"Required": true,
"Properties": {
"PortName": {
"Required": true,
"Type": "string",
"Description": "Port name, such as: BMC_1 MGMT CAS_1"
},
"Enable": {
"Required": true,
"Type": "string",
"Validator": [
{
"Type": "Enum",
"Formula": [
"disable",
"enable"
]
}
],
"Description": "disable | enable"
},
"PersistType": {
"Required": false,
"Type": "integer",
"Validator": [
{
"Type": "Enum",
"Formula":[
0,
1
]
}
],
"Description": "Persist type"
}
}
},
"RspBody": {
"Result": "${Statements/Result()}"
},
"Statements": {
"GetPathParams": {
"Input": "${ProcessingFlow[1]/Destination/PortsList}",
"Steps": [
{
"Type": "Expand"
},
{
"Type": "Script",
"Formula": "get_path_params.lua"
}
]
},
"Result": {
"Input": "${ReqBody/PersistType}",
"Steps": [
{
"Type": "Script",
"Formula": "if Input ~= nil then return ProcessingFlow[2].Destination.Result else return ProcessingFlow[3].Destination.Result end"
}
]
}
},
"ProcessingFlow": [
{
"Type": "List",
"Path": "/bmc/kepler/Switch/1/Ports",
"Destination": {
"Members": "PortsList"
}
},
{
"Type": "Method",
"Path": "/bmc/kepler/Switch/1/Ports/${Statements/GetPathParams()}",
"Interface": "bmc.kepler.Switch.Port",
"Name": "SetPortEnable",
"Params": [
"${ReqBody/PortName}",
"${ReqBody/Enable}",
"${ReqBody/PersistType}"
],
"Destination": {
"Result": "Result"
},
"CallIf": {
"${ReqBody/PersistType}": "#WITH"
}
},
{
"Type": "Method",
"Path": "/bmc/kepler/Switch/1/Ports/${Statements/GetPathParams()}",
"Interface": "bmc.kepler.Switch.Port",
"Name": "SetPortEnable",
"Params": [
"${ReqBody/PortName}",
"${ReqBody/Enable}",
0
],
"Destination": {
"Result": "Result"
},
"CallIf": {
"${ReqBody/PersistType}": "#WITHOUT"
}
}
],
"Echoes": [
"ipmcset/lswm_portenable",
""
]
}
]
},
get_path_params.lua脚本内容:
local log = require 'mc.logging'
local port_id = 0xffff
local port_name = ReqBody.PortName
log:error('%s----------------------------------------lsw', ReqBody.PortName)
for _, port_obj in pairs(Input) do
log:error('%s------------------lsw----------------------%s', port_obj.PortName, tostring(port_obj.LogicPortId))
if string.upper(port_obj.PortName) == string.upper(port_name) then
port_id = tonumber(port_obj.LogicPortId)
log:error('Get lsw Port%s successfully-----------------', tostring(port_id))
end
end
log:error('Get lsw Port%s successfully', tostring(port_id))
return port_id
方法二
通过PortName设法获取到Path,MDB提供公共方法GetPath,用于获取执行Interface并且某些属性为特定值的资源树Path,配置如下:
{
"Uri": "/cli/v1/lswm/portenable",
"Interfaces": [
{
"Type": "Patch",
"Description": "Set lswm port enable",
"Usage": "ipmcset -t lswm -d portenable -v <PortName> <enable|disable> [PersistType]",
"Example": [
"ipmcset -t lswm -d portenable -v BMC_1 enable",
"ipmcset -t lswm -d portenable -v CAS_1 disable 1"
],
"Confirm": {
"Condition": true,
"Description": "WARNING: The operation may have many adverse effects.\nDo you want to continue?[Y/N]:"
},
"ReqBody": {
"Type": "object",
"Required": true,
"Properties": {
"PortName": {
"Required": true,
"Type": "string",
"Description": "Port name, such as: BMC_1 MGMT CAS_1"
},
"Enable": {
"Required": true,
"Type": "string",
"Validator": [
{
"Type": "Enum",
"Formula": [
"disable",
"enable"
]
}
],
"Description": "disable | enable"
},
"PersistType": {
"Required": false,
"Type": "integer",
"Validator": [
{
"Type": "Enum",
"Formula":[
0,
1
]
}
],
"Description": "Persist type"
}
}
},
"RspBody": {
"Result": "${Statements/Result()}"
},
"Statements": {
"Result": {
"Input": "${ReqBody/PersistType}",
"Steps": [
{
"Type": "Script",
"Formula": "if Input ~= nil then return ProcessingFlow[2].Destination.Result else return ProcessingFlow[3].Destination.Result end"
}
]
}
},
"ProcessingFlow": [
{
"Type": "Method",
"Path": "/bmc/kepler/MdbService",
"Interface": "bmc.kepler.Mdb",
"Name": "GetPath",
"Params": [
"bmc.kepler.Switch.Port",
{
"PortName": "${ReqBody/PortName}"
}
],
"Destination": {
"Path": "Path"
}
},
{
"Type": "Method",
"Path": "${ProcessingFlow[1]/Destination/Path}",
"Interface": "bmc.kepler.Switch.Port",
"Name": "SetPortEnable",
"Params": [
"${ReqBody/PortName}",
"${ReqBody/Enable}",
"${ReqBody/PersistType}"
],
"Destination": {
"Result": "Result"
},
"CallIf": {
"${ProcessingFlow[1]/Destination/Path}": "#WITH",
"${ReqBody/PersistType}": "#WITH"
}
},
{
"Type": "Method",
"Path": "${ProcessingFlow[1]/Destination/Path}",
"Interface": "bmc.kepler.Switch.Port",
"Name": "SetPortEnable",
"Params": [
"${ReqBody/PortName}",
"${ReqBody/Enable}",
0
],
"Destination": {
"Result": "Result"
},
"CallIf": {
"${ProcessingFlow[1]/Destination/Path}": "#WITH",
"${ReqBody/PersistType}": "#WITHOUT"
}
}
],
"Echoes": [
"ipmcset/lswm_portenable",
""
]
}
]
},
但是执行对应IPMC均失败,且无日志打印
资源树查询及命令执行结果:
Service bmc.kepler.lsw_main:
└─/bmc
└─/bmc/kepler
├─/bmc/kepler/Debug
│ └─/bmc/kepler/Debug/LswMainDebug
├─/bmc/kepler/IpmiCmds
│ └─/bmc/kepler/IpmiCmds/30
│ └─/bmc/kepler/IpmiCmds/30/93
│ └─/bmc/kepler/IpmiCmds/30/93/SetOtherSmmPortEnable
├─/bmc/kepler/Switch
│ └─/bmc/kepler/Switch/1
│ └─/bmc/kepler/Switch/1/Ports
│ ├─/bmc/kepler/Switch/1/Ports/1
│ ├─/bmc/kepler/Switch/1/Ports/10
│ ├─/bmc/kepler/Switch/1/Ports/11
│ ├─/bmc/kepler/Switch/1/Ports/12
│ ├─/bmc/kepler/Switch/1/Ports/13
│ ├─/bmc/kepler/Switch/1/Ports/14
│ ├─/bmc/kepler/Switch/1/Ports/15
│ ├─/bmc/kepler/Switch/1/Ports/16
│ ├─/bmc/kepler/Switch/1/Ports/17
│ ├─/bmc/kepler/Switch/1/Ports/18
│ ├─/bmc/kepler/Switch/1/Ports/19
│ ├─/bmc/kepler/Switch/1/Ports/2
│ ├─/bmc/kepler/Switch/1/Ports/20
│ ├─/bmc/kepler/Switch/1/Ports/21
│ ├─/bmc/kepler/Switch/1/Ports/22
│ ├─/bmc/kepler/Switch/1/Ports/23
│ ├─/bmc/kepler/Switch/1/Ports/24
│ ├─/bmc/kepler/Switch/1/Ports/25
│ ├─/bmc/kepler/Switch/1/Ports/26
│ ├─/bmc/kepler/Switch/1/Ports/27
│ ├─/bmc/kepler/Switch/1/Ports/28
│ ├─/bmc/kepler/Switch/1/Ports/29
│ ├─/bmc/kepler/Switch/1/Ports/3
│ ├─/bmc/kepler/Switch/1/Ports/30
│ ├─/bmc/kepler/Switch/1/Ports/31
│ ├─/bmc/kepler/Switch/1/Ports/4
│ ├─/bmc/kepler/Switch/1/Ports/5
│ ├─/bmc/kepler/Switch/1/Ports/6
│ ├─/bmc/kepler/Switch/1/Ports/7
│ ├─/bmc/kepler/Switch/1/Ports/8
│ └─/bmc/kepler/Switch/1/Ports/9
└─/bmc/kepler/lsw_main
└─/bmc/kepler/lsw_main/MicroComponent
└─/bmc/kepler/lsw_main/MicroComponent/Debug
~ ~ # busctl --user introspect bmc.kepler.lsw_main /bmc/kepler/Switch/1/Ports/10 bmc.kepler.Switch.Port
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
.SetPortAutonegEnable method a{ss}ss s -
.SetPortEnable method a{ss}ssu s -
.SetPortLoopMode method a{ss}ss s -
.SetPortSpeed method a{ss}ss s -
.LogicPortId property u 10 emits-change
.PortName property s "BMC_1" emits-change
~ ~ # ipmcset -t lswm -d portenable -v BMC_1 enable 1
WARNING: The operation may have many adverse effects.
Do you want to continue?[Y/N]:Y
userdata: NULL