diff --git a/vendor/github.com/nicolai86/scaleway-sdk/api/api.go b/vendor/github.com/nicolai86/scaleway-sdk/api/api.go index a46c374d2..82ddd25ad 100644 --- a/vendor/github.com/nicolai86/scaleway-sdk/api/api.go +++ b/vendor/github.com/nicolai86/scaleway-sdk/api/api.go @@ -23,13 +23,17 @@ import ( "golang.org/x/sync/errgroup" ) +// https://cp-par1.scaleway.com/products/servers +// https://cp-ams1.scaleway.com/products/servers // Default values var ( - AccountAPI = "https://account.scaleway.com/" - MetadataAPI = "http://169.254.42.42/" - MarketplaceAPI = "https://api-marketplace.scaleway.com" - ComputeAPIPar1 = "https://cp-par1.scaleway.com/" - ComputeAPIAms1 = "https://cp-ams1.scaleway.com" + AccountAPI = "https://account.scaleway.com/" + MetadataAPI = "http://169.254.42.42/" + MarketplaceAPI = "https://api-marketplace.scaleway.com" + ComputeAPIPar1 = "https://cp-par1.scaleway.com/" + ComputeAPIAms1 = "https://cp-ams1.scaleway.com/" + AvailabilityAPIPar1 = "https://availability.scaleway.com/" + AvailabilityAPIAms1 = "https://availability-ams1.scaleway.com/" URLPublicDNS = ".pub.cloud.scaleway.com" URLPrivateDNS = ".priv.cloud.scaleway.com" @@ -45,12 +49,6 @@ func init() { if url := os.Getenv("SCW_MARKETPLACE_API"); url != "" { MarketplaceAPI = url } - if url := os.Getenv("SCW_COMPUTE_PAR1_API"); url != "" { - ComputeAPIPar1 = url - } - if url := os.Getenv("SCW_COMPUTE_AMS1_API"); url != "" { - ComputeAPIAms1 = url - } } const ( @@ -75,8 +73,9 @@ type ScalewayAPI struct { userAgent string - client HTTPClient - computeAPI string + client HTTPClient + computeAPI string + availabilityAPI string Region string } @@ -130,8 +129,10 @@ func New(organization, token, region string, options ...func(*ScalewayAPI)) (*Sc switch region { case "par1", "": s.computeAPI = ComputeAPIPar1 + s.availabilityAPI = AvailabilityAPIPar1 case "ams1": s.computeAPI = ComputeAPIAms1 + s.availabilityAPI = AvailabilityAPIAms1 default: return nil, fmt.Errorf("%s isn't a valid region", region) } @@ -139,6 +140,9 @@ func New(organization, token, region string, options ...func(*ScalewayAPI)) (*Sc if url := os.Getenv("SCW_COMPUTE_API"); url != "" { s.computeAPI = url } + if url := os.Getenv("SCW_AVAILABILITY_API"); url != "" { + s.availabilityAPI = url + } return s, nil } diff --git a/vendor/github.com/nicolai86/scaleway-sdk/api/availability.go b/vendor/github.com/nicolai86/scaleway-sdk/api/availability.go new file mode 100644 index 000000000..fe5e23ac1 --- /dev/null +++ b/vendor/github.com/nicolai86/scaleway-sdk/api/availability.go @@ -0,0 +1,37 @@ +package api + +import ( + "encoding/json" + "fmt" + "io/ioutil" +) + +type ServerAvailabilities map[string]interface{} + +func (a ServerAvailabilities) CommercialTypes() []string { + types := []string{} + for k, v := range a { + if _, ok := v.(bool); !ok { + continue + } + types = append(types, k) + } + return types +} + +func (s *ScalewayAPI) GetServerAvailabilities() (ServerAvailabilities, error) { + resp, err := s.response("GET", fmt.Sprintf("%s/availability.json", s.availabilityAPI), nil) + if err != nil { + return nil, err + } + defer resp.Body.Close() + bs, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + content := ServerAvailabilities{} + if err := json.Unmarshal(bs, &content); err != nil { + return nil, err + } + return content, nil +} diff --git a/vendor/github.com/nicolai86/scaleway-sdk/api/volume.go b/vendor/github.com/nicolai86/scaleway-sdk/api/volume.go index aa1a0ffcd..e7b1adc9f 100644 --- a/vendor/github.com/nicolai86/scaleway-sdk/api/volume.go +++ b/vendor/github.com/nicolai86/scaleway-sdk/api/volume.go @@ -40,17 +40,10 @@ type ScalewayVolume struct { ExportURI string `json:"export_uri,omitempty"` } -// ScalewayOneVolume represents the response of a GET /volumes/UUID API call -type ScalewayOneVolume struct { +type volumeResponse struct { Volume ScalewayVolume `json:"volume,omitempty"` } -// ScalewayVolumes represents a group of Scaleway volumes -type ScalewayVolumes struct { - // Volumes holds scaleway volumes of the response - Volumes []ScalewayVolume `json:"volumes,omitempty"` -} - // ScalewayVolumeDefinition represents a Scaleway volume definition type ScalewayVolumeDefinition struct { // Name is the user-defined name of the volume @@ -99,7 +92,7 @@ func (s *ScalewayAPI) PostVolume(definition ScalewayVolumeDefinition) (string, e if err != nil { return "", err } - var volume ScalewayOneVolume + var volume volumeResponse if err = json.Unmarshal(body, &volume); err != nil { return "", err @@ -133,6 +126,10 @@ func (s *ScalewayAPI) DeleteVolume(volumeID string) error { return nil } +type volumesResponse struct { + Volumes []ScalewayVolume `json:"volumes,omitempty"` +} + // GetVolumes gets the list of volumes from the ScalewayAPI func (s *ScalewayAPI) GetVolumes() (*[]ScalewayVolume, error) { query := url.Values{} @@ -148,7 +145,7 @@ func (s *ScalewayAPI) GetVolumes() (*[]ScalewayVolume, error) { return nil, err } - var volumes ScalewayVolumes + var volumes volumesResponse if err = json.Unmarshal(body, &volumes); err != nil { return nil, err @@ -168,7 +165,7 @@ func (s *ScalewayAPI) GetVolume(volumeID string) (*ScalewayVolume, error) { if err != nil { return nil, err } - var oneVolume ScalewayOneVolume + var oneVolume volumeResponse if err = json.Unmarshal(body, &oneVolume); err != nil { return nil, err diff --git a/vendor/vendor.json b/vendor/vendor.json index a4e769517..5cbdfbdf4 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -552,10 +552,10 @@ "revisionTime": "2016-10-03T17:45:16Z" }, { - "checksumSHA1": "XU7TT7viiC+Iw1odhQ7ZQuc6cL0=", + "checksumSHA1": "ROp7ZtwHdxYKpmwycOxbOOXNnzo=", "path": "github.com/nicolai86/scaleway-sdk/api", - "revision": "d6880deded5a32dee36aea78105a59b0574edd07", - "revisionTime": "2017-06-21T16:46:00Z" + "revision": "33df10cad9fff60467a3dcb992d5340c2b9a8046", + "revisionTime": "2017-09-17T18:57:50Z" }, { "checksumSHA1": "u5s2PZ7fzCOqQX7bVPf9IJ+qNLQ=",