-
Notifications
You must be signed in to change notification settings - Fork 83
/
kernels.go
63 lines (54 loc) · 1.4 KB
/
kernels.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
package golinode
import (
"fmt"
"github.com/go-resty/resty"
)
// LinodeKernel represents a linode kernel object
type LinodeKernel struct {
ID string
Label string
Version string
KVM bool
XEN bool
Architecture string
PVOPS bool
}
// LinodeKernelsPagedResponse represents a linode kernels API response for listing
type LinodeKernelsPagedResponse struct {
*PagedResponse
Data []*LinodeKernel
}
// ListKernels lists linode kernels
func (c *Client) ListKernels(opts *ListOptions) ([]*LinodeKernel, error) {
response := LinodeKernelsPagedResponse{}
err := c.ListHelper(response, opts)
return response.Data, err
}
func (LinodeKernelsPagedResponse) Endpoint(c *Client) string {
endpoint, err := c.Kernels.Endpoint()
if err != nil {
panic(err)
}
return endpoint
}
func (resp *LinodeKernelsPagedResponse) AppendData(r *LinodeKernelsPagedResponse) {
(*resp).Data = append(resp.Data, r.Data...)
}
func (LinodeKernelsPagedResponse) SetResult(r *resty.Request) {
r.SetResult(LinodeKernelsPagedResponse{})
}
// GetKernel gets the kernel with the provided ID
func (c *Client) GetKernel(kernelID string) (*LinodeKernel, error) {
e, err := c.Kernels.Endpoint()
if err != nil {
return nil, err
}
e = fmt.Sprintf("%s/%s", e, kernelID)
r, err := c.R().
SetResult(&LinodeKernel{}).
Get(e)
if err != nil {
return nil, err
}
return r.Result().(*LinodeKernel), nil
}