日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[OpenBMC] 快速上手OpenBMC的Redfish

發(fā)布時間:2023/12/31 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [OpenBMC] 快速上手OpenBMC的Redfish 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

最近好像很多公司都在開始做OpenBMC,真的好夯,所以今天來聊聊OpenBMC的Redfish怎么快速上手, 如果對redfish沒有很熟的話,可以先看"認識Redfish"里面講解的概念

10分鐘認識下一代數(shù)據(jù)中心基礎(chǔ)設(shè)施管理標準 - 紅魚(Redfish)_yeiris的博客-CSDN博客這幾年BMC領(lǐng)域中最受矚目的兩件事情就是Redfish的出現(xiàn)和OpenBMC的崛起,所以今天我想用10分鐘來聊聊下一代數(shù)據(jù)中心基礎(chǔ)設(shè)施管理標準 - 紅魚(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中?

使用者權(quán)限 (privileges)

根據(jù)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 權(quán)限,所以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.(對象路徑的樹,如文件系統(tǒng))

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.(進行方法調(diào)用)
  • 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);}); }

回調(diào)函數(shù)(Callback function)

回調(diào)函數(shù)(callback function)是指能藉由參數(shù)(argument)通往另一個函數(shù)的函數(shù)。例如底下范例

//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 這個回調(diào)函數(shù),因此在Dbus 的回覆回傳時,就會執(zhí)行我們注冊的MessageHandler&& handler

前面有提到Redfish所有資料都是來自于Dbus,因此我們必須在Dbus回復回傳的時候,才能Response StatusCode,所以我們在Redfish中可以看到大量Callback function的用法

例如AccountService/Accounts的PATCH Method,在Dbus回覆之后,便執(zhí)行注冊的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需要依序呼叫的時候,就會發(fā)現(xiàn)有巢狀回調(diào)函數(shù)的出現(xiàn),這樣可以執(zhí)行完一個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,會發(fā)現(xiàn)其實也沒這么復雜

總結(jié)

以上是生活随笔為你收集整理的[OpenBMC] 快速上手OpenBMC的Redfish的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。