2018-04-30 15:47:39 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
2019-12-02 20:37:43 +00:00
|
|
|
// Bootscript represents a Bootscript
|
|
|
|
type Bootscript struct {
|
2018-04-30 15:47:39 +00:00
|
|
|
Bootcmdargs string `json:"bootcmdargs,omitempty"`
|
|
|
|
Dtb string `json:"dtb,omitempty"`
|
|
|
|
Initrd string `json:"initrd,omitempty"`
|
|
|
|
Kernel string `json:"kernel,omitempty"`
|
|
|
|
|
|
|
|
// Arch is the architecture target of the bootscript
|
|
|
|
Arch string `json:"architecture,omitempty"`
|
|
|
|
|
|
|
|
// Identifier is a unique identifier for the bootscript
|
|
|
|
Identifier string `json:"id,omitempty"`
|
|
|
|
|
|
|
|
// Organization is the owner of the bootscript
|
|
|
|
Organization string `json:"organization,omitempty"`
|
|
|
|
|
|
|
|
// Name is a user-defined name for the bootscript
|
|
|
|
Title string `json:"title,omitempty"`
|
|
|
|
|
|
|
|
// Public is true for public bootscripts and false for user bootscripts
|
|
|
|
Public bool `json:"public,omitempty"`
|
|
|
|
|
|
|
|
Default bool `json:"default,omitempty"`
|
|
|
|
}
|
|
|
|
|
2019-12-02 20:37:43 +00:00
|
|
|
type getBootscriptResponse struct {
|
|
|
|
Bootscript Bootscript `json:"bootscript,omitempty"`
|
2018-04-30 15:47:39 +00:00
|
|
|
}
|
|
|
|
|
2019-12-02 20:37:43 +00:00
|
|
|
type getBootscriptsResponse struct {
|
|
|
|
Bootscripts []Bootscript `json:"bootscripts,omitempty"`
|
2018-04-30 15:47:39 +00:00
|
|
|
}
|
|
|
|
|
2019-12-02 20:37:43 +00:00
|
|
|
// GetBootscripts gets the list of bootscripts from the API
|
|
|
|
func (s *API) GetBootscripts() ([]Bootscript, error) {
|
2018-04-30 15:47:39 +00:00
|
|
|
query := url.Values{}
|
|
|
|
|
|
|
|
resp, err := s.GetResponsePaginate(s.computeAPI, "bootscripts", query)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := s.handleHTTPError([]int{http.StatusOK}, resp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-12-02 20:37:43 +00:00
|
|
|
var bootscripts getBootscriptsResponse
|
2018-04-30 15:47:39 +00:00
|
|
|
|
|
|
|
if err = json.Unmarshal(body, &bootscripts); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-12-02 20:37:43 +00:00
|
|
|
return bootscripts.Bootscripts, nil
|
2018-04-30 15:47:39 +00:00
|
|
|
}
|
|
|
|
|
2019-12-02 20:37:43 +00:00
|
|
|
// GetBootscript gets a bootscript from the API
|
|
|
|
func (s *API) GetBootscript(bootscriptID string) (*Bootscript, error) {
|
2018-04-30 15:47:39 +00:00
|
|
|
resp, err := s.GetResponsePaginate(s.computeAPI, "bootscripts/"+bootscriptID, url.Values{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := s.handleHTTPError([]int{http.StatusOK}, resp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-12-02 20:37:43 +00:00
|
|
|
var oneBootscript getBootscriptResponse
|
2018-04-30 15:47:39 +00:00
|
|
|
|
|
|
|
if err = json.Unmarshal(body, &oneBootscript); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// FIXME region, arch, owner, title
|
|
|
|
return &oneBootscript.Bootscript, nil
|
|
|
|
}
|