1fe6da2ad6
Refs https://github.com/hashicorp/go-discover/pull/128 * deps: add replace directive for gocheck Transitive dep, source at https://launchpad.net/gocheck indicates project moved. This also avoids a dependency on bzr when fetching modules. Refs https://github.com/hashicorp/consul/pull/6818 * deps: make update-vendor * test: update retry-join expected names from go-discover
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package linodego
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// 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"`
|
|
KVM bool `json:"kvm"`
|
|
XEN bool `json:"xen"`
|
|
PVOPS bool `json:"pvops"`
|
|
}
|
|
|
|
// LinodeKernelsPagedResponse represents a Linode kernels API response for listing
|
|
type LinodeKernelsPagedResponse struct {
|
|
*PageOptions
|
|
Data []LinodeKernel `json:"data"`
|
|
}
|
|
|
|
// ListKernels lists linode kernels
|
|
func (c *Client) ListKernels(ctx context.Context, opts *ListOptions) ([]LinodeKernel, error) {
|
|
response := LinodeKernelsPagedResponse{}
|
|
err := c.listHelper(ctx, &response, opts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return response.Data, nil
|
|
}
|
|
|
|
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...)
|
|
}
|
|
|
|
// GetKernel gets the kernel with the provided ID
|
|
func (c *Client) GetKernel(ctx context.Context, 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(ctx).
|
|
SetResult(&LinodeKernel{}).
|
|
Get(e)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return r.Result().(*LinodeKernel), nil
|
|
}
|