Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thecodeteam/gorackhd

Go bindings for the RackHD API
https://github.com/thecodeteam/gorackhd

Last synced: about 2 months ago
JSON representation

Go bindings for the RackHD API

Awesome Lists containing this project

README

        

#gorackhd

### Go bindings for RackHD

## Description
gorackhd represents API bindings for Go that allow you to manage [RackHD](https://github.com/RackHD/RackHD). The intended functions are a direct implementation of what's available within the RackHD Monorail API. To manage machines with IPMI, also use [gorackhd-redfish](https://github.com/codedellemc/gorackhd-redfish) that talks to the RackHD Redfish API.

## Compatibility
gorackhd is created using [go-swagger](https://github.com/go-swagger/go-swagger) client generator.

## Installation of the client
To install the client:
```
$ go get github.com/codedellemc/gorackhd
```

## Generation of the client

The client relies on a swagger spec file that is taken from RackHD's [on-http](https://github.com/RackHD/on-http) library and packaged at `/swagger-spec/monorail.yml`. As the swagger spec changes, this client will update as needed.

The client is found within the `/client` folder which is generated by go-swagger. To generate the client:
```
$ cd $GOPATH/src/github.com/codedellemc/gorackhd
$ make
```

The Makefile utilizes [glide](https://github.com/Masterminds/glide) to reference go-swagger `0.6.0` of [go-swagger](https://github.com/go-swagger/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 nodes. Take a look at `gorackhd_test.go` for more

```
package main

import (
"fmt"
"log"
"os"

rc "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"

apiclient "github.com/codedellemc/gorackhd/client"
"github.com/codedellemc/gorackhd/client/nodes"
)

func main() {

// create the transport
transport := rc.New("localhost:9090", "/api/1.1", []string{"http"})

// If not using the Vagrant image, set this environment variable to something other than localhost:9090
if os.Getenv("GORACKHD_ENDPOINT") != "" {
transport.Host = os.Getenv("GORACKHD_ENDPOINT")
}

// create the API client, with the transport
client := apiclient.New(transport, strfmt.Default)

//use any function to do REST operations
resp, err := client.Nodes.GetNodes(nil, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", resp.Payload)

}

```

### Use the client to create (POST) a new item
Import the library for what you are trying to post:
```
import (
...
"github.com/codedellemc/gorackhd/client/nodes"
...
)
```

Create the JSON struct
```
type ObmConfig struct {
Host string `json:"host"`
User string `json:"user"`
Password string `json:"password"`
}

type ObmSettings struct {
Service string `json:"service"`
Config *ObmConfig `json:"config"`
}

type Node struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
ObmSettings []*ObmSettings `json:"obmSettings"`
}
```

```
c := &Node{
ID: "1234abcd1234abcd1234abcd",
Name: "somename",
Type: "compute",
ObmSettings: []*ObmSettings{&ObmSettings{
Service: "ipmi-obm-service",
Config: &ObmConfig{
Host: "1.2.3.4",
User: "myuser",
Password: "mypass",
},
}},
}

params := nodes.NewPostNodesParams()
params = params.WithIdentifiers(c)
resp, err := client.Nodes.PostNodes(params, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", resp.Payload)
```

### Use the client to fetch (GET) individual items

Import the library for what you are trying to retrieve:
```
import (
...
"github.com/codedellemc/gorackhd/client/nodes"
...
)
```

Lookup the params that are required in a struct:
```
params := nodes.NewGetSkusIdentifierParams()
params = params.WithIdentifier("1234abcd1234abcd1234abcd")
resp, err := client.Skus.GetSkusIdentifier(params, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", resp.Payload)

```

### Use the client to remove (DELETE) individual items
Import the library for what you are trying to retrieve:
```
import (
...
"github.com/codedellemc/gorackhd/client/nodes"
...
)
```

Lookup the params that are required in a struct:
```
params := NewDeleteNodesIdentifierParams()
params = params.WithIdentifier("1234abcd1234abcd1234abcd")
resp, err := client.Nodes.DeleteNodesIdentifier(params, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", resp)
```

## Contribution
Create a fork of the project into your own repository.

Run the tests provided in `gorackhd_test.go` to verify GET/POST/DELETE still function:
```
env DEBUG=1 go test -run TestNodePostOperation -v
env DEBUG=1 go test -run TestNodeGetOperation -v
env DEBUG=1 go test -run TestNodeDeleteOperation -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 is freely distributed under the [MIT License](http://codedellemc.github.io/sampledocs/LICENSE "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](http://community.codedellemc.com/) 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.