-
Notifications
You must be signed in to change notification settings - Fork 82
/
kernels.go
82 lines (64 loc) · 1.95 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package linodego
import (
"context"
"encoding/json"
"time"
"github.com/linode/linodego/internal/parseabletime"
)
// LinodeKernel represents a Linode Instance kernel object
type LinodeKernel struct {
ID string `json:"id"`
Label string `json:"label"`
Version string `json:"version"`
Architecture string `json:"architecture"`
Deprecated bool `json:"deprecated"`
KVM bool `json:"kvm"`
XEN bool `json:"xen"`
PVOPS bool `json:"pvops"`
Built *time.Time `json:"-"`
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (i *LinodeKernel) UnmarshalJSON(b []byte) error {
type Mask LinodeKernel
p := struct {
*Mask
Built *parseabletime.ParseableTime `json:"built"`
}{
Mask: (*Mask)(i),
}
if err := json.Unmarshal(b, &p); err != nil {
return err
}
i.Built = (*time.Time)(p.Built)
return nil
}
// ListKernels lists linode kernels. This endpoint is cached by default.
func (c *Client) ListKernels(ctx context.Context, opts *ListOptions) ([]LinodeKernel, error) {
endpoint, err := generateListCacheURL("linode/kernels", opts)
if err != nil {
return nil, err
}
if result := c.getCachedResponse(endpoint); result != nil {
return result.([]LinodeKernel), nil
}
response, err := getPaginatedResults[LinodeKernel](ctx, c, "linode/kernels", opts)
if err != nil {
return nil, err
}
c.addCachedResponse(endpoint, response, nil)
return response, nil
}
// GetKernel gets the kernel with the provided ID. This endpoint is cached by default.
func (c *Client) GetKernel(ctx context.Context, kernelID string) (*LinodeKernel, error) {
e := formatAPIPath("linode/kernels/%s", kernelID)
if result := c.getCachedResponse(e); result != nil {
result := result.(LinodeKernel)
return &result, nil
}
response, err := doGETRequest[LinodeKernel](ctx, c, e)
if err != nil {
return nil, err
}
c.addCachedResponse(e, response, nil)
return response, nil
}