A go client library for the Redfish API
Go to file
James Gu 470a7752c6 Add iDrac reset api
Change-Id: Iec4e59341fd8a976b6aeda30d0671839643b04bf
2022-08-25 19:19:57 +00:00
api Add "Unknown" value to health state enum 2021-10-04 14:36:11 -04:00
client Add iDrac reset api 2022-08-25 19:19:57 +00:00
spec Add iDrac reset api 2022-08-25 19:19:57 +00:00
.gitignore Fix typo in .gitignore 2020-05-20 21:20:55 +00:00
.gitreview Update module to point to opendev 2020-01-10 18:52:54 +00:00
.zuul.yaml Add noop gating 2020-01-10 22:51:28 +04:00
api_generator.go Upgrade openapi generator to v5.1.0 2021-05-05 10:18:32 -04:00
go.mod Fixed a name typo in go.mod 2021-08-04 20:51:12 +00:00
go.sum Fixed a name typo in go.mod 2021-08-04 20:51:12 +00:00
LICENSE rename github org 2019-09-19 00:06:55 +03:00
Makefile Upgrade openapi generator to v5.1.0 2021-05-05 10:18:32 -04:00
README.md Update module to point to opendev 2020-01-10 18:52:54 +00:00

Go-Redfish - Golang client library for DMTF Redfish

Introduction

go-redfish is the golang client library to interact with Redfish Server. This library do not implement complete redfish standard but it is meant to provide parallel functionality as of sushy. go-redfish can be tested against sushy-emulator.

Usage

To use go-redfish library in go code, you just need to import the library as below.

import (
    "fmt"

    redfish "opendev.org/airship/go-redfish/client"
)

Then, get the client api object for the desired redfish server.

cfg := &redfish.Configuration{
    BasePath:      "http://localhost:8000",
    DefaultHeader: make(map[string]string),
    UserAgent:     "go-redfish/client",
  }

redfishApi := redfish.NewAPIClient(cfg).DefaultApi

Use redfishApi to interact with redfish server. This object contains get, set and list functions for different redfish resources. There are loose validations on the client side for the required paramaters of a certain API. In case of any error e.g. missing a required parameter; then server will generate the error. To see the available actions for API endpoints see Endpoint Reference and Model Definitions. See following examples for different operations.

Examples

  • List available ComputerSystems
sl, _, _ := redfishApi.ListSystems(context.Background())
  • List available Managers
sl, _, _ := redfishApi.ListManagers(context.Background())
  • Get Desired ComputerSystem Resource
system_id := "dd9fd064-263b-469c-91d4-d45f341fe2c5"
system, _, _ := redfishApi.GetSystem(context.Background(), system_id)
  • Reset ComputerSystem
system_id := "dd9fd064-263b-469c-91d4-d45f341fe2c5"
systemReq := redfish.ComputerSystem{ResetType: "ForceRestart"}
reset_resp, _, _ = redfishApi.ResetSystem(context.Background(), system_id, reset_type)
  • Insert VirtualMedia for manager
manager_id := "58893887-8974-2487-2389-841168418919"
insertReq := redfish.InsertMediaRequestBody{}
insertReq.Image = "http://releases.ubuntu.com/19.04/ubuntu-19.04-live-server-amd64.iso"
insertReq.Inserted = true
redfishApi.InsertVirtualMedia(context.Background(), manager_id, "Cd", insertReq)
  • Set Boot Device For Next Boot
system_id := "dd9fd064-263b-469c-91d4-d45f341fe2c5"
systemReq := redfish.ComputerSystem{}
systemReq.Boot.BootSourceOverrideTarget = "Cd"
redfishApi.SetSystem(context.Background(), system_id, systemReq)
  • Get available system's boot options
system_id := "dd9fd064-263b-469c-91d4-d45f341fe2c5"
system, _, _ := redfishApi.GetSystem(context.Background(), system_id)
fmt.Printf("%#v", system.Boot.BootSourceOverrideTargetRedfishAllowableValues)

Sample Output:

[Pxe Cd Hdd]

Contributing

This library is created using openapi specification and code is generated using openapi go client generator. So it is very easy to extend the client using openapi spec. If you need any extra api resource or see any issues then create a pull request or raise an issue.