435c0d9fc8
This PR switches the Nomad repository from using govendor to Go modules for managing dependencies. Aspects of the Nomad workflow remain pretty much the same. The usual Makefile targets should continue to work as they always did. The API submodule simply defers to the parent Nomad version on the repository, keeping the semantics of API versioning that currently exists.
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
)
|
|
|
|
type InstanceTypeAvailability string
|
|
|
|
var (
|
|
InstanceTypeAvailable InstanceTypeAvailability = "available"
|
|
InstanceTypeScarce InstanceTypeAvailability = "scarce"
|
|
InstanceTypeShortage InstanceTypeAvailability = "shortage"
|
|
)
|
|
|
|
type ServerAvailability struct {
|
|
Availability InstanceTypeAvailability `json:"availability"`
|
|
}
|
|
|
|
type ServerAvailabilities map[string]ServerAvailability
|
|
|
|
func (a ServerAvailabilities) CommercialTypes() []string {
|
|
types := []string{}
|
|
for k, _ := range a {
|
|
types = append(types, k)
|
|
}
|
|
return types
|
|
}
|
|
|
|
type availabilityResponse struct {
|
|
Servers ServerAvailabilities
|
|
}
|
|
|
|
func (s *API) GetServerAvailabilities() (ServerAvailabilities, error) {
|
|
resp, err := s.response("GET", fmt.Sprintf("%s/products/servers/availability", s.computeAPI), nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
bs, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
content := availabilityResponse{}
|
|
if err := json.Unmarshal(bs, &content); err != nil {
|
|
return nil, err
|
|
}
|
|
return content.Servers, nil
|
|
}
|