【博客427】通过redfish协议操控服务器
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                【博客427】通过redfish协议操控服务器
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                通過(guò)redfish協(xié)議操控服務(wù)器
開(kāi)源庫(kù)鏈接
https://github.com/stmcginnis/gofish
方式:通過(guò)gofish開(kāi)源庫(kù),底層使用redfish協(xié)議操控服務(wù)器
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)}} }總結(jié)
以上是生活随笔為你收集整理的【博客427】通过redfish协议操控服务器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: python打印九九乘法表代码
- 下一篇: SpringMVC运行原理
