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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【博客427】通过redfish协议操控服务器

發布時間:2023/12/31 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【博客427】通过redfish协议操控服务器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

通過redfish協議操控服務器

開源庫鏈接

https://github.com/stmcginnis/gofish

方式:通過gofish開源庫,底層使用redfish協議操控服務器

example1:

Change Login

// // SPDX-License-Identifier: BSD-3-Clause // package mainimport ("github.com/stmcginnis/gofish" )func main() {// Create a new instance of gofish client, ignoring self-signed certsusername := "my-username"config := gofish.ClientConfig{Endpoint: "https://bmc-ip",Username: username,Password: "my-password",Insecure: true,}c, err := gofish.Connect(config)if err != nil {panic(err)}defer c.Logout()// Retrieve the service rootservice := c.Service// Query the AccountService using the session tokenaccountService, err := service.AccountService()if err != nil {panic(err)}// Get list of accountsaccounts, err := accountService.Accounts()if err != nil {panic(err)}// Iterate over accounts to find the current userfor _, account := range accounts {if account.UserName == username {account.UserName = "new-username"// New password must follow the rules set in AccountService :// MinPasswordLength and MaxPasswordLengthaccount.Password = "new-password"err := account.Update()if err != nil {panic(err)}}} }

example2:

Query Chassis

// // SPDX-License-Identifier: BSD-3-Clause // package mainimport ("fmt""github.com/stmcginnis/gofish" )func main() {// Create a new instance of gofish client, ignoring self-signed certsconfig := gofish.ClientConfig{Endpoint: "https://bmc-ip",Username: "my-username",Password: "my-password",Insecure: true,}c, err := gofish.Connect(config)if err != nil {panic(err)}defer c.Logout()// Retrieve the service rootservice := c.Service// Query the chassis data using the session tokenchassis, err := service.Chassis()if err != nil {panic(err)}for _, chass := range chassis {fmt.Printf("Chassis: %#v\n\n", chass)} }

example3:

Query Session

// // SPDX-License-Identifier: BSD-3-Clause // package mainimport ("fmt""github.com/stmcginnis/gofish" )func main() {// Create a new instance of gofish client, ignoring self-signed certsconfig := gofish.ClientConfig{Endpoint: "https://bmc-ip",Username: "my-username",Password: "my-password",Insecure: true,}c, err := gofish.Connect(config)if err != nil {panic(err)}defer c.Logout()// Retrieve the service rootservice := c.Service// Query the active sessions using the session tokensessions, err := service.Sessions()if err != nil {panic(err)}fmt.Printf("%+v\n", sessions)for _, session := range sessions {fmt.Printf("Sessions: %#v\n\n", session)} }

example4:

Reboot

// // SPDX-License-Identifier: BSD-3-Clause // package mainimport ("fmt""github.com/stmcginnis/gofish""github.com/stmcginnis/gofish/redfish" )func main() {// Create a new instance of gofish client, ignoring self-signed certsconfig := gofish.ClientConfig{Endpoint: "https://bmc-ip",Username: "my-username",Password: "my-password",Insecure: true,}c, err := gofish.Connect(config)if err != nil {panic(err)}defer c.Logout()// Attached the client to service rootservice := c.Service// Query the computer systemsss, err := service.Systems()if err != nil {panic(err)}// Creates a boot override to pxe oncebootOverride := redfish.Boot{BootSourceOverrideTarget: redfish.PxeBootSourceOverrideTarget,BootSourceOverrideEnabled: redfish.OnceBootSourceOverrideEnabled,}for _, system := range ss {fmt.Printf("System: %#v\n\n", system)err := system.SetBoot(bootOverride)if err != nil {panic(err)}err = system.Reset(redfish.ForceRestartResetType)if err != nil {panic(err)}} }

總結

以上是生活随笔為你收集整理的【博客427】通过redfish协议操控服务器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。