### Installation Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Command to install the bmclib v2 library using go get. ```bash go get github.com/bmc-toolbox/bmclib/v2 ``` -------------------------------- ### Tracing Telemetry Example Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Shows how to set up the client to collect trace telemetry using `WithTracerProvider`. ```Go cl := bmclib.NewClient( host, user, pass, bmclib.WithLogger(log), bmclib.WithTracerProvider(otel.GetTracerProvider()), ) ``` -------------------------------- ### Query using Redfish endpoint Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Example of initializing a client and restricting drivers to only use the 'redfish' endpoint. ```go cl := bmclib.NewClient("192.168.1.1", "admin", "hunter2") cl.Registry.Drivers = cl.Registry.Using("redfish") ``` -------------------------------- ### Usage Example Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Connect to a BMC, retrieve inventory data, and print it as JSON. ```go import ( bmclib "github.com/bmc-toolbox/bmclib/v2" ) // setup logger l := logrus.New() l.Level = logrus.DebugLevel logger := logrusr.New(l) clientOpts := []bmclib.Option{bmclib.WithLogger(logger)} // init client client := bmclib.NewClient(*host, "admin", "hunter2", clientOpts...) // open BMC session err := client.Open(ctx) if err != nil { log.Fatal(err, "bmc login failed") } defer client.Close(ctx) // retrieve inventory data inventory, err := client.Inventory(ctx) if err != nil { l.Error(err) } b, err := json.MarshalIndent(inventory, "", " ") if err != nil { l.Error(err) } fmt.Println(string(b)) ``` -------------------------------- ### Query using Redfish and fallback to IPMI Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Example of initializing a client and setting drivers to use 'redfish' first, then fall back to 'ipmi'. ```go client := bmclib.NewClient("192.168.1.1", "admin", "hunter2") // overwrite registered drivers by appending Redfish, IPMI drivers in order drivers := append(registrar.Drivers{}, bmcClient.Registry.Using("redfish")...) drivers = append(drivers, bmcClient.Registry.Using("ipmi")...) client.Registry.Drivers = driver ``` -------------------------------- ### Permanent Filtering Example Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Example of permanently modifying the order of BMC providers in the registry. ```go cl := bmclib.NewClient(host, user, pass) // This will modify the order for all subsequent BMC calls cl.Registry.Drivers = cl.Registry.PreferDriver("gofish") if err := cl.Open(ctx); err != nil { return(err) } ``` -------------------------------- ### One-time Filtering Example Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Demonstrates how to modify the provider order for a single BMC call using `PreferProvider`. ```Go cl := bmclib.NewClient(host, user, pass) // This will modify the order for only this BMC call if err := cl.PreferProvider("gofish").Open(ctx); err != nil { return(err) } ``` -------------------------------- ### Filter drivers by compatibility Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Example of initializing a client and filtering drivers to only use compatible ones before performing a BMC action. ```go client := bmclib.NewClient("192.168.1.1", "admin", "hunter2") client.Registry.Drivers = cl.Registry.FilterForCompatible(ctx) ``` -------------------------------- ### Install Parameters Source: https://github.com/bmc-toolbox/bmclib/blob/main/providers/supermicro/docs/x12.md The JSON payload for installing BMC firmware. ```json {"Targets":["/redfish/v1/Managers/1"],"@Redfish.OperationApplyTime":"OnStartUpdateRequest","Oem":{"Supermicro":{"BMC":{"PreserveCfg":true,"PreserveSdr":true,"PreserveSsl":true}}}} ``` -------------------------------- ### Ignore specific Redfish versions Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Example of initializing a client with an option to ignore BMCs running a specific Redfish version. ```go opt := bmclib.WithRedfishVersionsNotCompatible([]string{"1.5.0"}) client := bmclib.NewClient("192.168.1.1", "admin", "hunter2", opt...) cl.Registry.Drivers = cl.Registry.FilterForCompatible(ctx) ``` -------------------------------- ### Default timeout Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Demonstrates the default timeout behavior when no explicit timeouts are configured. ```go cl := bmclib.NewClient(host, user, pass, bmclib.WithLogger(log)) ctx := context.Background() if err = cl.Open(ctx); err != nil { return(err) } def cl.Close(ctx) state, err := cl.GetPowerState(ctx) ``` -------------------------------- ### Import Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Go import statement for the bmclib v2 library. ```go import ( bmclib "github.com/bmc-toolbox/bmclib/v2" ) ``` -------------------------------- ### BIOS Firmware Update Steps Source: https://github.com/bmc-toolbox/bmclib/blob/main/providers/asrockrack/firmware_update.md A sequence of API calls to update the BIOS firmware, including uploading the image and initiating the upgrade. ```bash POST api/asrr/maintenance/BIOS/firmware multipart payload: ------WebKitFormBoundaryBet48KCtZK4gBlQz Content-Disposition: form-data; name="fwimage"; filename="E6D4INL2.07B" Content-Type: application/octet-stream ------WebKitFormBoundaryBet48KCtZK4gBlQz-- POST api/asrr/maintenance/BIOS/configuration payload {"action":"2"} POST api/asrr/maintenance/BIOS/upgrade payload {action: 3} GET api/asrr/maintenance/BIOS/flash-progress ``` -------------------------------- ### Total max timeout and a per provider; per interaction timeout Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Configures both a total maximum timeout and a per-provider timeout for BMC interactions. ```go cl := bmclib.NewClient(host, user, pass, bmclib.WithLogger(log), bmclib.WithPerProviderTimeout(15*time.Second)) ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) def cancel() if err = cl.Open(ctx); err != nil { return(err) } def cl.Close(ctx) state, err := cl.GetPowerState(ctx) ``` -------------------------------- ### Power Cycle using SMC XML API Source: https://github.com/bmc-toolbox/bmclib/blob/main/providers/supermicro/docs/x11.md Go function to perform a power cycle on an X11 Supermicro server using the SMC XML API. ```go // powerCycle using SMC XML API func (c *x11) powerCycle(ctx context.Context) (bool, error) { payload := []byte(`op=POWER_INFO.XML&r=(1,3)&_=`) headers := map[string]string{ "Content-type": "application/x-www-form-urlencoded; charset=UTF-8", } body, status, err := c.serviceClient.query(ctx, "cgi/ipmi.cgi", http.MethodPost, bytes.NewBuffer(payload), headers, 0) if err != nil { return false, err } if status != http.StatusOK { return false, unexpectedResponseErr(payload, body, status) } return true, nil } ``` -------------------------------- ### BMC Firmware Update Steps Source: https://github.com/bmc-toolbox/bmclib/blob/main/providers/asrockrack/firmware_update.md A sequence of API calls to update the BMC firmware, including uploading the image, verification, and initiating the upgrade. ```bash PUT /api/maintenance/flash POST /api/maintenance/firmware Content-Type: multipart/form-data ------WebKitFormBoundaryESKCgdjyLnqUPHBK Content-Disposition: form-data; name="fwimage"; filename="E3C246D4I-NL_L0.01.00.ima" Content-Type: application/octet-stream ------WebKitFormBoundaryESKCgdjyLnqUPHBK-- GET /api/maintenance/firmware/verification GET /api/maintenance/reset PUT /api/maintenance/firmware payload {"preserve_config":1,"preserve_network":0,"preserve_user":0,"flash_status":1} GET https://10.230.148.171/api/maintenance/firmware/flash-progress ``` -------------------------------- ### Total max timeout only Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Configures a total maximum timeout for all BMC interactions. ```go cl := bmclib.NewClient(host, user, pass, bmclib.WithLogger(log)) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) def cancel() if err = cl.Open(ctx); err != nil { return(err) } def cl.Close(ctx) state, err := cl.GetPowerState(ctx) ``` -------------------------------- ### Per provider; per interaction timeout. No total max timeout Source: https://github.com/bmc-toolbox/bmclib/blob/main/README.md Configures only a per-provider timeout for BMC interactions, without a total maximum timeout. ```go cl := bmclib.NewClient(host, user, pass, bmclib.WithLogger(log), bmclib.WithPerProviderTimeout(15*time.Second)) ctx := context.Background() if err = cl.Open(ctx); err != nil { return(err) } def cl.Close(ctx) state, err := cl.GetPowerState(ctx) ``` -------------------------------- ### Initiate BMC Firmware Upgrade Source: https://github.com/bmc-toolbox/bmclib/blob/main/providers/supermicro/docs/x12.md This cURL command initiates the BMC firmware upgrade process. ```bash curl 'https://10.251.153.157/cgi/upgrade_process.cgi' \ -H 'Accept: */*' \ -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \ -H 'CSRF_TOKEN: +5/2t9ZcRuEzRg6MbTU2/j5Ils1VM2zf7uVImW/wVMI' \ -H 'Connection: keep-alive' \ -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \ -H 'Cookie: SID=qK4ZDz2cNet9nor' \ -H 'Origin: https://10.251.153.157' \ -H 'Referer: https://10.251.153.157/cgi/url_redirect.cgi?url_name=topmenu' \ -H 'Sec-Fetch-Dest: empty' \ -H 'Sec-Fetch-Mode: cors' \ -H 'Sec-Fetch-Site: same-origin' \ -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36' \ -H 'X-Requested-With: XMLHttpRequest' \ -H 'sec-ch-ua: "Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'sec-ch-ua-platform: "macOS"' \ --data-raw 'fwtype=255' \ --compressed \ --insecure ``` -------------------------------- ### Upload BMC Firmware Source: https://github.com/bmc-toolbox/bmclib/blob/main/providers/supermicro/docs/x12.md This cURL command uploads the BMC firmware to the update service. ```bash curl 'https://10.251.153.157/redfish/v1/UpdateService/upload' \ -H 'Accept: */*' \ -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \ -H 'CSRF_TOKEN: p9lTd1+h0qsz/inooljtRbrja+1/z6nBRLuAKV6JJkM' \ -H 'Connection: keep-alive' \ -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundarytykIB3S8fDkno3cP' \ -H 'Cookie: SID=1rnGhJ9HoMI6JpP' \ -H 'Origin: https://10.251.153.157' \ -H 'Referer: https://10.251.153.157/cgi/url_redirect.cgi?url_name=topmenu' \ -H 'Sec-Fetch-Dest: empty' \ -H 'Sec-Fetch-Mode: cors' \ -H 'Sec-Fetch-Site: same-origin' \ -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36' \ -H 'X-Auth-Token: o5jk3881vldnk3hdkn20wu5kg8brl18r' \ -H 'X-Requested-With: XMLHttpRequest' \ -H 'sec-ch-ua: "Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'sec-ch-ua-platform: "macOS"' \ --data-raw $'------WebKitFormBoundarytykIB3S8fDkno3cP\r\nContent-Disposition: form-data; name="UpdateParameters"\r\n\r\n{"Targets":["/redfish/v1/Managers/1"],"@Redfish.OperationApplyTime":"OnStartUpdateRequest","Oem":{"Supermicro":{"BMC":{"PreserveCfg":true,"PreserveSdr":true,"PreserveSsl":true}}}}\r\n------WebKitFormBoundarytykIB3S8fDkno3cP\r\nContent-Disposition: form-data; name="UpdateFile"; filename="BMC_X12AST2600-F201MS_20220627_1.13.04_STDsp.bin"\r\nContent-Type: application/macbinary\r\n\r\n\r\n------WebKitFormBoundarytykIB3S8fDkno3cP--\r\n' \ --compressed ``` -------------------------------- ### BMC Verify Task Details Source: https://github.com/bmc-toolbox/bmclib/blob/main/providers/supermicro/docs/x12.md The JSON response for a completed BMC Verify task. ```json {"@odata.type":"#Task.v1_4_3.Task","@odata.id":"/redfish/v1/TaskService/Tasks/1","Id":"1","Name":"BMC Verify","TaskState":"Completed","StartTime":"2023-10-06T07:53:25+00:00","EndTime":"2023-10-06T07:53:31+00:00","PercentComplete":100,"HidePayload":true,"TaskMonitor":"/redfish/v1/TaskMonitor/fa37JncCHryDsbzayy4cBWDxS22Jjzh","TaskStatus":"OK","Messages":[{"MessageId":"","RelatedProperties":[""],"Message":"","MessageArgs":[""],"Severity":""}],"Oem":{}} ``` -------------------------------- ### BMC Update Task Status (Running - Post Upgrade) Source: https://github.com/bmc-toolbox/bmclib/blob/main/providers/supermicro/docs/x12.md The JSON response indicating a BMC Update task is running after initiating the upgrade. ```json { "@odata.type": "#Task.v1_4_3.Task", "@odata.id": "/redfish/v1/TaskService/Tasks/2", "Id": "2", "Name": "BMC Update", "TaskState": "Running", "StartTime": "2023-10-13T13:27:51+00:00", "PercentComplete": 5, "HidePayload": true, "TaskMonitor": "/redfish/v1/TaskMonitor/MaiRrV41mtzxlYvKWrO72tK0LK0e1zL", "TaskStatus": "OK", "Messages": [ { "MessageId": "", "RelatedProperties": [ "" ], "Message": "", "MessageArgs": [ "" ], "Severity": "" } ], "Oem": {} } ``` -------------------------------- ### Check BMC Verify Task Status Source: https://github.com/bmc-toolbox/bmclib/blob/main/providers/supermicro/docs/x12.md This cURL command checks the status of a BMC Verify task. ```bash ❯ curl 'https://10.251.153.157/redfish/v1/TaskService/Tasks/1' \ -H 'Accept: application/json, text/javascript, */*; q=0.01' \ -H 'CSRF_TOKEN: 10QMfkMegOzCe/WZZARLcs0cpxdDif8tSJcg5ZEnqVw' \ -H 'Connection: keep-alive' \ -H 'Content-Type: application/json' \ -H 'Cookie: SID=1rnGhJ9HoMI6JpP' \ -H 'X-Auth-Token: o5jk3881vldnk3hdkn20wu5kg8brl18r' \ --compressed \ --insecure ``` -------------------------------- ### BMC Update Task Status (Running) Source: https://github.com/bmc-toolbox/bmclib/blob/main/providers/supermicro/docs/x12.md The JSON response indicating a BMC Update task is running. ```json { "@odata.type": "#Task.v1_4_3.Task", "@odata.id": "/redfish/v1/TaskService/Tasks/2", "Id": "2", "Name": "BMC Update", "TaskState": "Running", "StartTime": "2023-10-09T05:42:25+00:00", "PercentComplete": 2, "HidePayload": true, "TaskMonitor": "/redfish/v1/TaskMonitor/MaiRrV41mtzxlYvKWrO72tK0LK0e1zL", "TaskStatus": "OK", "Messages": [ { "MessageId": "", "RelatedProperties": [ "" ], "Message": "", "MessageArgs": [ "" ], "Severity": "" } ], "Oem": {} } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.