Expand+script;GetPath,获取某Interface某属性为特定值的Path失败

问题描述

方法一:

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均失败,且无日志打印

资源树查询及命令执行结果:

~ ~ # busctl --user tree 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
NAME                                TYPE      SIGNATURE   RESULT/VALUE                    FLAGS
bmc.kepler.Object.Properties        interface -           -                               -
.GetAllWithContext                  method    a{ss}s      a{sv}                           -
.GetOptions                         method    a{ss}ss     a{ss}                           -
.GetPrivateProperties               method    a{ss}       s                               -
.GetPropertiesByNames               method    a{ss}sas    a{sv}a{sv}                      -
.GetPropertiesByOptions             method    a{ss}sa{ss} as                              -
.GetPropertyDetail                  method    a{ss}ss     s                               -
.GetWithContext                     method    a{ss}ss     v                               -
.SetWithContext                     method    a{ss}ssv    -                               -
.ClassName                          property  s           "Port"                          emits-change
.ObjectIdentifier                   property  (ysss)      0 "" "" ""                      emits-change
.ObjectName                         property  s           "/bmc/kepler/Switch/1/Ports/10" emits-change
.TraceSamplingRate                  property  d           0                               emits-change
bmc.kepler.Switch.Port              interface -           -                               -
.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
org.freedesktop.DBus.Introspectable interface -           -                               -
.Introspect                         method    -           s                               -
org.freedesktop.DBus.ObjectManager  interface -           -                               -
.GetManagedObjects                  method    -           a{oa{sa{sv}}}                   -
org.freedesktop.DBus.Peer           interface -           -                               -
.GetMachineId                       method    -           s                               -
.Ping                               method    -           -                               -
org.freedesktop.DBus.Properties     interface -           -                               -
.Get                                method    ss          v                               -
.GetAll                             method    s           a{sv}                           -
.Set                                method    ssv         -                               -
.PropertiesChanged                  signal    sa{sv}as    -                               -
1970-01-01 05:18:40.684211 lsw_main NOTICE: object_manage.lua(682): start to fetch hwdiscovery objects
1970-01-01 05:18:40.705554 lsw_main NOTICE: object_manage.lua(671): delay start, delay: 0ms
1970-01-01 05:18:40.706609 lsw_main NOTICE: object_manage.lua(720): fetch hwdiscovery objects completely, took 0 ms, uptime: 364 s
1970-01-01 05:18:40.726404 lsw_main NOTICE: object_manage.lua(316): start to add objects, path: /bmc/kepler/ObjectGroup/01010B, life cycle id: 1, count: 31, uptime: 364 s
1970-01-01 05:18:40.774190 lsw_main ERROR: PortAttrMgmt.lua(151): | 30      | SW4_10GE      | enable  | down  | full    | disable        | 10GE      | no_loop        |
1970-01-01 05:18:40.825507 lsw_main ERROR: PortAttrMgmt.lua(151): | 13      | BMC_4         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:40.866843 lsw_main ERROR: PortAttrMgmt.lua(151): | 16      | BMC_7         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:40.903763 lsw_main ERROR: PortAttrMgmt.lua(151): | 22      | CPORT_5       | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:40.944557 lsw_main ERROR: PortAttrMgmt.lua(151): | 5       | CAS_4         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:40.987539 lsw_main ERROR: PortAttrMgmt.lua(151): | 14      | BMC_5         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.029423 lsw_main ERROR: PortAttrMgmt.lua(151): | 29      | SW5_CPORT     | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.084321 lsw_main ERROR: PortAttrMgmt.lua(151): | 3       | CAS_2         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.121119 lsw_main ERROR: PortAttrMgmt.lua(151): | 6       | CAS_5         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.164112 lsw_main ERROR: PortAttrMgmt.lua(151): | 23      | CPORT_6       | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.209032 lsw_main ERROR: PortAttrMgmt.lua(151): | 17      | BMC_8         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.256731 lsw_main ERROR: PortAttrMgmt.lua(151): | 18      | CPORT_1       | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.312596 lsw_main ERROR: PortAttrMgmt.lua(151): | 4       | CAS_3         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.366624 lsw_main ERROR: PortAttrMgmt.lua(151): | 27      | SMM_OTHER     | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.405247 lsw_main ERROR: PortAttrMgmt.lua(151): | 7       | CAS_6         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.454580 lsw_main ERROR: PortAttrMgmt.lua(151): | 2       | CAS_1         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.504945 lsw_main ERROR: PortAttrMgmt.lua(151): | 19      | CPORT_2       | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.558430 lsw_main ERROR: PortAttrMgmt.lua(151): | 8       | CAS_7         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.623003 lsw_main ERROR: PortAttrMgmt.lua(151): | 25      | CPORT_8       | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.670955 lsw_main ERROR: PortAttrMgmt.lua(151): | 20      | CPORT_3       | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.722418 lsw_main ERROR: PortAttrMgmt.lua(151): | 11      | BMC_2         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.770537 lsw_main ERROR: PortAttrMgmt.lua(151): | 9       | CAS_8         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.824775 lsw_main ERROR: PortAttrMgmt.lua(151): | 26      | SMM_SELF      | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.888104 lsw_main ERROR: PortAttrMgmt.lua(151): | 21      | CPORT_4       | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:41.954227 lsw_main ERROR: PortAttrMgmt.lua(151): | 24      | CPORT_7       | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:42.001883 lsw_main ERROR: PortAttrMgmt.lua(151): | 31      | SW5_10GE      | enable  | down  | full    | disable        | 10GE      | no_loop        |
1970-01-01 05:18:42.047757 lsw_main ERROR: PortAttrMgmt.lua(151): | 10      | BMC_1         | disable | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:42.097467 lsw_main ERROR: PortAttrMgmt.lua(151): | 1       | MGMT          | enable  | down  | full    | enable         | GE        | no_loop        |
1970-01-01 05:18:42.148442 lsw_main ERROR: PortAttrMgmt.lua(151): | 12      | BMC_3         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:42.204179 lsw_main ERROR: PortAttrMgmt.lua(151): | 15      | BMC_6         | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:42.257623 lsw_main ERROR: PortAttrMgmt.lua(151): | 28      | SW4_CPORT     | enable  | down  | full    | disable        | GE        | no_loop        |
1970-01-01 05:18:42.269885 lsw_main NOTICE: object_manage.lua(336): add objects callback, path: /bmc/kepler/ObjectGroup/01010B, life cycle id: 1, count: 31, took 1540ms, uptime: 366 s
1970-01-01 05:18:42.270720 lsw_main NOTICE: lsw_cfg_mgmt.lua(69): [convert_csr_to_soft] convert_mac_csr_to_soft success!
1970-01-01 05:18:42.271332 lsw_main NOTICE: lsw_cfg_mgmt.lua(74): [convert_csr_to_soft] convert_acl_csr_to_soft success!
1970-01-01 05:18:42.271931 lsw_main NOTICE: lsw_main_app.lua(73): [register_object_mgmt] add object complete, position: 01010B
1970-01-01 05:18:42.272734 lsw_main NOTICE: object_manage.lua(346): add objects completely, path: /bmc/kepler/ObjectGroup/01010B, life cycle id: 1, took 10ms, uptime: 366 s

你这些东西我看不明白你实际什么问题,你调用了什么方法,哪里报错,哪里不符合预期,我都看不出来。如果是有日志没打印就看为啥没进入对应分支啊?