最近好像很多公司都在开始做OpenBMC,真的好夯,所以今天来聊聊OpenBMC的Redfish怎么快速上手, 如果对redfish没有很熟的话,可以先看"认识Redfish"里面讲解的概念

10分钟认识下一代数据中心基础设施管理标准 - 红鱼(Redfish)_yeiris的博客-CSDN博客这几年BMC领域中最受瞩目的两件事情就是Redfish的出现和OpenBMC的崛起,所以今天我想用10分钟来聊聊下一代数据中心基础设施管理标准 - 红鱼(Redfish)红鱼的诞生Redfish 是在2015年由DMTF(Distributed Management Task Force) 这个组织开始着手建立的伺服器管理标准,官方的描述是A standard, Redfish is designed to deliver simple and secure management forhttps://blog.csdn.net/yeiris/article/details/122755165

Code 在哪里?

Redfish的Code 是放在bmcweb这一包里面

GitHub - openbmc/bmcweb: A do everything Redfish, KVM, GUI, and DBus webserver for OpenBMChttps://github.com/openbmc/bmcweb目前OpenBMC的Web打算采用前后端分离的方式,后端是Redfish,前端是webui-vue,所以我猜bmcweb这个名字是这样来的

如何开始? 该先看哪只程式码?

RedfishService

在src\webserver_main.cpp 中将RedfishServices加到router

RedfishServices (redfish-core\include\redfish.hpp)里面有很多sub router

這些subrouter定義的程式碼都在"redfish-core\lib\"資料夾底下,以requestAccountServiceRoutes為例,定義在account_service.hpp中

使用者权限 (privileges)

根据Redfish.md里面的描述,User Role有三种可以选择 Administrator, Operator 和 ReadOnly

这边还是以AccountService的redfish::privileges::getAccountService为范例,在redfish-core\include\registries\privilege_registry.hpp可看到

// AccountService
const static auto& getAccountService = privilegeSetLogin;

其中privilegeSetLogin 是Login 權限,所以Administrator, Operator 和 ReadOnly User都可以GET /redfish/v1/AccountService/

namespace redfish::privileges
{
// clang-format off
const std::array<Privileges, 1> privilegeSetLogin = {{{"Login"}
}};
const std::array<Privileges, 1> privilegeSetConfigureComponents = {{{"ConfigureComponents"}
}};
const std::array<Privileges, 1> privilegeSetConfigureUsers = {{{"ConfigureUsers"}
}};
const std::array<Privileges, 1> privilegeSetConfigureManager = {{{"ConfigureManager"}
}};
const std::array<Privileges, 2> privilegeSetConfigureManagerOrConfigureComponents = {{{"ConfigureManager"},{"ConfigureComponents"}
}};
const std::array<Privileges, 2> privilegeSetConfigureManagerOrConfigureSelf = {{{"ConfigureManager"},{"ConfigureSelf"}
}};
const std::array<Privileges, 3> privilegeSetConfigureManagerOrConfigureUsersOrConfigureSelf = {{{"ConfigureManager"},{"ConfigureUsers"},{"ConfigureSelf"}
}};
const std::array<Privileges, 2> privilegeSetLoginOrNoAuth = {{{"Login"},{}
}};

redfish-core\lib

这个资料夹中存放了所有support 的redfish resource的程式码,可以先看自己要研究的API,例如常見的ComputerServices

//redfish-core\lib\systems.hpp
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/").privileges(redfish::privileges::getComputerSystem).methods(boost::beast::http::verb::get)([](const crow::Request&,const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {}

资料操作皆来自Dbus

什么是Dbus

OpenBMC提供了介绍影片,我觉得讲得很完整 sdbusplus & phosphor-dbus-interface - YouTube

OpenBMC是由很多个daemon所组成的,像是ipmid, fwupd, fscd等,dbus可以想像成他们的共享资料夹,所以当我们要修改资料或是拿取资料的时候,就去dbus相对位置拿取就可以了,底下是我在维基看到的图片,从图片中可以感受到有了Dbus之后,Daemon间的沟通变得简单有条理

Dbus的组成有三个元素:

Service - A daemon attached to the dbus and providing objects.

root@romulus:~# busctl
xyz.openbmc_project.State.BMC

Object Paths – A tree, like a file system, of paths to objects.(对象路径的树,如文件系统)

root@romulus:~# busctl  tree xyz.openbmc_project.State.BMC
└─/xyz└─/xyz/openbmc_project└─/xyz/openbmc_project/state└─/xyz/openbmc_project/state/bmc0

Interface – The ‘class’ of an object. Objects support multiple inheritance.(对象的“class”。 对象支持多重继承)

  • Property – Store values. Some can be written to (存储值。有些可以改写)
  • Method – Make method calls.(进行方法调用)
  • Signal – Inform other process about an event. (将事件通知其他进程)
root@romulus:~# busctl introspect xyz.openbmc_project.State.BMC /xyz/openbmc_project/state/bmc0
NAME                                TYPE            SIGNATURE       RESULT/VALUE                                 FLAGS
xyz.openbmc_project.State.BMC       interface       -               -                                            -
.CurrentBMCState                    property        s               "xyz.openbmc_project.State.BMC.BMCState…     emits-change writable
.LastRebootTime                     property        t               1619401752000                                emits-change writable
.RequestedBMCTransition             property        s               "xyz.openbmc_project.State.BMC.Transiti…     emits-change writable

所以如果Redfish 想要取得BMC的LastRebootTime,那他就要下get-property指令

get-property SERVICE   OBJECT   INTERFACE   PROPERTY...

// 这个指令是下在bmc console 中的
busctl get-property xyz.openbmc_project.State.BMC /xyz/openbmc_project/state/bmc0 xyz.openbmc_project.State.BMC LastRebootTime

那在程式码实作就是如下,可以看到他在get-property 的function中分别带入service, object ,interface和property

//redfish-core\lib\managers.hpp
inline voidmanagerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{BMCWEB_LOG_DEBUG << "Getting Manager Last Reset Time";sdbusplus::asio::getProperty<uint64_t>(*crow::connections::systemBus, "xyz.openbmc_project.State.BMC","/xyz/openbmc_project/state/bmc0", "xyz.openbmc_project.State.BMC","LastRebootTime",[aResp](const boost::system::error_code ec,const uint64_t lastResetTime) {if (ec){BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;return;}// LastRebootTime is epoch time, in milliseconds// https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19uint64_t lastResetTimeStamp = lastResetTime / 1000;// Convert to ISO 8601 standardaResp->res.jsonValue["LastResetTime"] =crow::utility::getDateTimeUint(lastResetTimeStamp);});
}

回调函数(Callback function)

回调函数(callback function)是指能藉由参数(argument)通往另一个函数的函数。例如底下范例

//sdbusplus/include/sdbusplus/asio/connection.hpp
void async_method_call(MessageHandler&& handler, const std::string& service,const std::string& objpath,const std::string& interf, const std::string& method,const InputArgs&... a)

在 async_method_call 中,先注册了MessageHandler&& handler 这个回调函数,因此在Dbus 的回覆回传时,就会执行我们注册的MessageHandler&& handler

前面有提到Redfish所有资料都是来自于Dbus,因此我们必须在Dbus回复回传的时候,才能Response StatusCode,所以我们在Redfish中可以看到大量Callback function的用法

例如AccountService/Accounts的PATCH Method,在Dbus回覆之后,便执行注册的callback function

//redfish-core\lib\account_service.hpp
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/").privileges({{"ConfigureUsers"}, {"ConfigureSelf"}}).methods(boost::beast::http::verb::patch)([](const crow::Request& req,const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,const std::string& username) -> void {//verify value, 先省略掉crow::connections::systemBus->async_method_call(//callback function start[asyncResp, username, password(std::move(password)),roleId(std::move(roleId)), enabled,newUser{std::string(*newUserName)},locked](const boost::system::error_code ec,sdbusplus::message::message& m) {if (ec){userErrorMessageHandler(m.get_error(), asyncResp,newUser, username);return;}updateUserProperties(asyncResp, newUser, password,enabled, roleId, locked);} //callback function end,"xyz.openbmc_project.User.Manager","/xyz/openbmc_project/user","xyz.openbmc_project.User.Manager", "RenameUser", username,*newUserName);});

那如果有很多Dbus method需要依序呼叫的时候,就会发现有巢状回调函数的出现,这样可以执行完一个method后再call 下一个mthod

crow::connections::systemBus->async_method_call([asyncResp](const boost::system::error_code ec,sdbusplus::message::message& m) {if (ec){return;}crow::connections::systemBus->async_method_call([asyncResp](const boost::system::error_code ec,sdbusplus::message::message& m) {if (ec){return;}crow::connections::systemBus->async_method_call([asyncResp](const boost::system::error_code ec,sdbusplus::message::message& m) {if (ec){return;}updateUserProperties(asyncResp, newUser, password,enabled, roleId, locked);},"Service 3","object path3","Interface", "method", value, value');},"Service 2","object path2","Interface", "method", value, value');},"Service 1","object path","Interface", "method", value, value');

如果掌握以上几点再去看bmcweb的code,会发现其实也没这么复杂

[OpenBMC] 快速上手OpenBMC的Redfish相关推荐

  1. 【快速上手mac必备】常用优质mac软件推荐(音视频、办公、软件开发、辅助工具、系统管理、云存储)

    本文章的主要内容是我作为一名大四学生.准程序员.up主这三种身份来给大家推荐一下 mac 上好用的软件以及工具.本人也是从去年9月份开始从windows阵营转移到了mac阵营,刚开始使用的时候,也曾主 ...

  2. 【转】Vue.js 2.0 快速上手精华梳理

    Vue.js 2.0 快速上手精华梳理 Sandy 发掘代码技巧:公众号:daimajiqiao 自从Vue2.0发布后,Vue就成了前端领域的热门话题,github也突破了三万的star,那么对于新 ...

  3. 『转载』Debussy快速上手(Verdi相似)

    『转载』Debussy快速上手(Verdi相似) Debussy 是NOVAS Software, Inc(思源科技)发展的HDL Debug & Analysis tool,这套软体主要不是 ...

  4. [转载]ESFramework 4.0 快速上手(15) -- 客户端登录验证

    ESFramework 4.0 快速上手(15) -- 客户端登录验证 在之前版本的Rapid引擎中,是没有提供客户端登陆验证的机制的,如果要验证用户的帐号密码信息,我们只有自己手动通过自定义信息来实 ...

  5. WijmoJS 2019V1正式发布:全新的在线 Demo 系统,助您快速上手,开发无忧

    2019独角兽企业重金招聘Python工程师标准>>> 下载WijmoJS 2019 v1 WijmoJS是为企业应用程序开发而推出的一系列包含HTML5和JavaScript的开发 ...

  6. react 快速上手开发_React中测试驱动开发的快速指南

    react 快速上手开发 by Michał Baranowski 通过MichałBaranowski React中测试驱动开发的快速指南 (A quick guide to test-driven ...

  7. 《Android App开发入门:使用Android Studio 2.X开发环境》——1-3 Android Studio 快速上手...

    1-3 Android Studio 快速上手

  8. Keras快速上手:基于Python的深度学习

    Keras快速上手:基于Python的深度学习 谢梁,鲁颖,劳虹岚 著 ISBN:9787121318726 包装:平装 开本:16开 正文语种:中文 出版社: 电子工业出版社 出版时间:2017-0 ...

  9. 快速上手关键词抽取的算法

    前言 在自然语言处理领域,我们有一种类型的问题是如何在一堆文本中提取出核心词/句子.而无论是对于长文本还是短文本,往往几个关键词就可以代表整个文本的主题思想.同时,在很多推荐系统中,由于无法直接就整体 ...

  10. Python学习六大路线,教你快速上手

    最近几年随着互联网的发展学习Python人越来越多,Python的初学者总希望能够得到一份Python学习路线图,小编经过多方面汇总,总结出比较全套Python学习路线,快速上手.对于一个零基础的想学 ...

最新文章

  1. tortoiseGit clone大代码,报错 fatal: Not a git repository (or any of the parent directories): .git 问题
  2. 一个浙江商人立下的22条军规(转载)
  3. 重新整理Cellset转Datatable
  4. python3 bytes和bytearray总结
  5. 转载 C++实现的委托机制
  6. 有监督学习和无监督学习举例_监督学习入门学习笔记
  7. C++Vector使用方法
  8. 面向对象三节课,对象与权限修饰符,作业0918
  9. opensource项目_Opensource.com的写作主题从A到Z
  10. 登陆界面HTML验证码生成
  11. HTML4+CSS2 模仿一个英雄联盟官网页面
  12. 多模态预训练CLIP模型的强大为例
  13. “手机到底是如何实现定位的?工作原理是什么?”
  14. 免费开源的图像处理软件GIMP下载安装(Windows)
  15. 上位机通信标准-OPC
  16. win10升级助手_Win7直接升级Win10,小编三种方法告诉你如何做到,建议收藏哦!
  17. 好系统教你Win7系统开机启动慢怎么解决?
  18. bash文件无法运行,提示没有那个文件或目录的解决方法
  19. 搜索不到投屏设备怎么办_电视投屏搜索不到设备解决方案
  20. 《资治通鉴》—— 三家分晋

热门文章

  1. 酷派无线升级服务器设置在哪里,酷派手机CDA自助升级线刷工具安装教程
  2. 简明python教程 答案1
  3. 中国主要水系、河流、湖泊数据矢量数据(shp格式)下载地址
  4. 大数据项目实战二之电信大数据项目
  5. Android代码中模拟点击事件
  6. 算法第四版 课后习题答案
  7. GooFlow修改元素color(背景/字体/连线)
  8. 螺旋模型(Spiral Model)
  9. 2019最新盘点:适合中小型企业的财务系统软件
  10. 高斯克吕格投影,将经纬度转换为投影坐标