-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgorackhd_test.go
143 lines (115 loc) · 3.61 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package gorackhd
import (
"encoding/json"
"fmt"
"log"
"os"
"testing"
rc "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
apiclient "github.com/codedellemc/gorackhd/client"
"github.com/codedellemc/gorackhd/client/lookups"
"github.com/codedellemc/gorackhd/client/nodes"
)
func TestNodeGetOperation(t *testing.T) {
// create the transport
transport := rc.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, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", resp.Payload)
}
func TestNodeLookupOperation(t *testing.T) {
// create the transport
transport := rc.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)
nodeId := "56dde3441722c192796e3a38"
params := lookups.NewGetLookupsParams()
params = params.WithQ(&nodeId)
//use any function to do REST operations
resp, err := client.Lookups.GetLookups(params, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", resp.Payload)
}
func TestNodePostOperation(t *testing.T) {
// create the transport
transport := rc.New("localhost:9090", "/api/1.1", []string{"http"})
// configure the host
if os.Getenv("GORACKHD_ENDPOINT") != "" {
transport.Host = os.Getenv("GORACKHD_ENDPOINT")
}
// 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))
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)
}
func TestNodeDeleteOperation(t *testing.T) {
// create the transport
transport := rc.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)
params := nodes.NewDeleteNodesIdentifierParams()
params = params.WithIdentifier("1234abcd1234abcd1234abcd")
resp, err := client.Nodes.DeleteNodesIdentifier(params, nil)
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"`
}