#gorackhd-redfish
Go bindings for RackHD Redfish API
Description
gorackhd-redfish represents API bindings for Go that allow you to manage the RackHD Redfish API. This specific API is different than the gorackhd bindings as these are related to IPMI functions for individual machines. The intended functions are a direct implementation of what's available within the RackHD Redfish API.
Compatibility
gorackhd-redfish is created using go-swagger client generator.
The client relies on a swagger spec file that is taken from RackHD's on-http library and packaged at /swagger-spec/redfish.yml
. As the swagger spec changes, this client will update as needed.
Installation & Creation of the Client
The client is found within the /client
folder which is generated by go-swagger. To generate/install the client:
$ go get github.com/codedellemc/gorackhd-redfish
$ cd $GOPATH/src/github.com/codedellemc/gorackhd-redfish
$ make
The Makefile utilizes glide to reference git commit 0.6.0
of go-swagger. The Makefile will generate a go-swagger directory in /vendor/github.com/
and then create the client.
Environment Variables
Name |
Description |
GORACKHD_ENDPOINT |
the API endpoint. localhost:9090 is used by default if not set |
Using the client
This sample script will retrieve (GET) all Roles. Take a look at redfish_test.go
for more
package main
import (
"fmt"
"log"
"os"
rc "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
apiclientRedfish "github.com/codedellemc/gorackhd-redfish/client"
"github.com/codedellemc/gorackhd-redfish/client/redfish_v1"
)
func main() {
// create the transport
transport := rc.New("localhost:9090", "/redfish/v1", []string{"http"})
// configure the host. include port with environment variable. For instance the vagrant image would be localhost:9090
if os.Getenv("GORACKHD_ENDPOINT") != "" {
transport.Host = os.Getenv("GORACKHD_ENDPOINT")
}
// create the API client, with the transport
client := apiclientRedfish.New(transport, strfmt.Default)
//use any function to do REST operations
resp, err := client.RedfishV1.GetRoles(nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", resp.Payload)
}
Use the client to POST
Import the redfish_v1
library for all the functions, then also import the models
for the pre-defined structs needed for payloads.:
import (
...
"github.com/codedellemc/gorackhd-redfish/client/redfish_v1"
"github.com/codedellemc/gorackhd-redfish/models"
...
)
Use the client to fetch (GET) individual items
Import the library for what you are trying to retrieve:
import (
...
"github.com/codedellemc/gorackhd-redfish/client/redfish_v1"
...
)
Create the params that are required:
params := redfish_v1.NewGetSystemParams()
params = params.WithIdentifier("57154fe9d67951e70958c213")
resp, err := client.RedfishV1.GetSystem(params)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", resp.Payload.PowerState)
Contribution
Create a fork of the project into your own repository.
Run the tests provided in redfish_test.go
to verify GET/POST still function (change the NodeID accordingly):
env DEBUG=1 go test -run TestRedfishGetRolesOperation -v
env DEBUG=1 go test -run TestRedfishGetPowerStatus -v
env DEBUG=1 go test -run TestRedfishShutdown -v
If tests do not pass, please create an issue so it can be addressed or fix and create a PR.
If all tests pass, make changes and create a pull request with a description on what was added or removed and details explaining the changes in lines of code. If approved, project owners will merge it.
Licensing
gorackhd-redfish is freely distributed under the MIT License. See LICENSE for details.
##Support
Please file bugs and issues on the Github issues page for this project. This is to help keep track and document everything related to this repo. For general discussions and further support you can join the {code} by Dell EMC Community slack team and join the #rackhd channel. The code and documentation are released with no warranties or SLAs and are intended to be supported through a community driven process.