gorackhd

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2016 License: MIT Imports: 3 Imported by: 0

README

#gorackhd

Go bindings for RackHD

Description

gorackhd represents API bindings for Go that allow you to manage 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 that talks to the RackHD Redfish API.

Compatibility

gorackhd is created using go-swagger client generator.

Installation of the client

To install the client:

$ go get github.com/emccode/gorackhd

Generation of the client

The client relies on a swagger spec file that is taken from RackHD's 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/emccode/gorackhd
$ make

The Makefile utilizes glide to reference git commit 6b712512cbe1f of go-swagger that has been tested and known to be working. 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"

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

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

func main() {

    // create the transport
    transport := httptransport.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)
    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/emccode/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",
            },
        }},
    }

    resp, err := client.Nodes.PostNodes(&nodes.PostNodesParams{Identifiers: c})
    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/emccode/gorackhd/client/nodes"
    ...
)

Lookup the params that are required in a struct:

resp, err := client.Skus.GetSkusIdentifier(&nodes.GetNodesIdentifierParams{Identifier: "1234abcd1234abcd1234abcd"})
    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/emccode/gorackhd/client/nodes"
    ...
)

Lookup the params that are required in a struct:

resp, err := client.Nodes.DeleteNodesIdentifier(&nodes.DeleteNodesIdentifierParams{Identifier: "1234abcd1234abcd1234abcd"})
    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. 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 EMC {code} Community slack team and join the #rackhd channel. Lastly, for questions asked on Stackoverflow.com please tag them with EMC. The code and documentation are released with no warranties or SLAs and are intended to be supported through a community driven process.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL