2017-02-07 21:33:23 +00:00
|
|
|
package lib
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2017-02-07 21:33:23 +00:00
|
|
|
// OS image on Vultr
|
|
|
|
type OS struct {
|
|
|
|
ID int `json:"OSID"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Arch string `json:"arch"`
|
|
|
|
Family string `json:"family"`
|
|
|
|
Windows bool `json:"windows"`
|
|
|
|
Surcharge string `json:"surcharge"`
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
type oses []OS
|
|
|
|
|
|
|
|
func (s oses) Len() int { return len(s) }
|
|
|
|
func (s oses) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
|
|
|
func (s oses) Less(i, j int) bool { return strings.ToLower(s[i].Name) < strings.ToLower(s[j].Name) }
|
|
|
|
|
2017-02-07 21:33:23 +00:00
|
|
|
// GetOS returns a list of all available operating systems on Vultr
|
|
|
|
func (c *Client) GetOS() ([]OS, error) {
|
|
|
|
var osMap map[string]OS
|
|
|
|
if err := c.get(`os/list`, &osMap); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var osList []OS
|
|
|
|
for _, os := range osMap {
|
|
|
|
osList = append(osList, os)
|
|
|
|
}
|
2017-04-11 15:10:46 +00:00
|
|
|
sort.Sort(oses(osList))
|
2017-02-07 21:33:23 +00:00
|
|
|
return osList, nil
|
|
|
|
}
|