forked from thecodeteam/gorackhd
/
gorackhd_test.go
118 lines (95 loc) · 3.05 KB
/
gorackhd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package gorackhd
import (
"encoding/json"
"fmt"
"log"
"os"
"testing"
//swagclient "github.com/go-swagger/go-swagger/client"
httptransport "github.com/go-swagger/go-swagger/httpkit/client"
"github.com/go-swagger/go-swagger/strfmt"
apiclient "github.com/emccode/gorackhd/client"
"github.com/emccode/gorackhd/client/nodes"
)
func TestNodeGetOperation(t *testing.T) {
// create the transport
transport := httptransport.New("localhost:9090", "/api/1.1", []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 := 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)
}
func TestNodePostOperation(t *testing.T) {
// create the transport
transport := httptransport.New("localhost:9090", "/api/1.1", []string{"http"})
// configure the host
if os.Getenv("GORACKHD_ENDPOINT") != "" {
transport.Host = os.Getenv("GORACKHD_ENDPOINT")
}
//fmt.Println(fmt.Sprintf("%+v", transport))
// create the API client, with the transport
client := apiclient.New(transport, strfmt.Default)
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",
},
}},
}
b, err := json.Marshal(c)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(b))
resp, err := client.Nodes.PostNodes(&nodes.PostNodesParams{Identifiers: c})
if err != nil {
log.Fatal(err)
}
t.Logf("%+v", resp.Payload)
}
func TestNodeDeleteOperation(t *testing.T) {
// create the transport
transport := httptransport.New("localhost:9090", "/api/1.1", []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 := apiclient.New(transport, strfmt.Default)
//use any function to do REST operations
resp, err := client.Nodes.DeleteNodesIdentifier(&nodes.DeleteNodesIdentifierParams{Identifier: "1234abcd1234abcd1234abcd"})
//resp, err := client.Skus.GetSkusIdentifier(&skus.GetSkusIdentifierParams{Identifier: "568e8b76c3354ff04bab27e0"})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", resp)
}
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"`
}