provider/scaleway: update sdk (#9976)

the SDK updates includes an fix for the image cache, which might lead to wrong
images ids being returned on lookup...
This commit is contained in:
Raphael Randschau 2016-11-09 10:32:56 +01:00 committed by Paul Stack
parent 3258aa98e6
commit e5ff0f0cb2
4 changed files with 32 additions and 34 deletions

View File

@ -76,9 +76,7 @@ func resourceScalewayVolumeRead(d *schema.ResourceData, m interface{}) error {
return err
}
d.Set("name", volume.Name)
if size, ok := volume.Size.(float64); ok {
d.Set("size_in_gb", uint64(size)/gb)
}
d.Set("size_in_gb", uint64(volume.Size)/gb)
d.Set("type", volume.VolumeType)
d.Set("server", "")
if volume.Server != nil {

View File

@ -71,7 +71,7 @@ func resourceScalewayVolumeAttachmentCreate(d *schema.ResourceData, m interface{
// the API request requires most volume attributes to be unset to succeed
for k, v := range volumes {
v.Size = nil
v.Size = 0
v.CreationDate = ""
v.Organization = ""
v.ModificationDate = ""
@ -192,7 +192,7 @@ func resourceScalewayVolumeAttachmentDelete(d *schema.ResourceData, m interface{
// the API request requires most volume attributes to be unset to succeed
for k, v := range volumes {
v.Size = nil
v.Size = 0
v.CreationDate = ""
v.Organization = ""
v.ModificationDate = ""

View File

@ -147,7 +147,7 @@ type ScalewayVolume struct {
Identifier string `json:"id,omitempty"`
// Size is the allocated size of the volume
Size interface{} `json:"size,omitempty"`
Size uint64 `json:"size,omitempty"`
// CreationDate is the creation date of the volume
CreationDate string `json:"creation_date,omitempty"`
@ -939,7 +939,7 @@ func (s *ScalewayAPI) response(method, uri string, content io.Reader) (resp *htt
// GetResponsePaginate fetchs all resources and returns an http.Response object for the requested resource
func (s *ScalewayAPI) GetResponsePaginate(apiURL, resource string, values url.Values) (*http.Response, error) {
resp, err := s.response("HEAD", fmt.Sprintf("%s/%s", strings.TrimRight(apiURL, "/"), resource), nil)
resp, err := s.response("HEAD", fmt.Sprintf("%s/%s?%s", strings.TrimRight(apiURL, "/"), resource, values.Encode()), nil)
if err != nil {
return nil, err
}
@ -956,6 +956,9 @@ func (s *ScalewayAPI) GetResponsePaginate(apiURL, resource string, values url.Va
}
get := maxElem / perPage
if (float32(maxElem) / perPage) > float32(get) {
get++
}
if get <= 1 { // If there is 0 or 1 page of result, the response is not paginated
if len(values) == 0 {
@ -985,38 +988,31 @@ func (s *ScalewayAPI) GetResponsePaginate(apiURL, resource string, values url.Va
if err = g.Wait(); err != nil {
return nil, err
}
newBody := make(map[string][]interface{})
body := make(map[string][]interface{})
newBody := make(map[string][]json.RawMessage)
body := make(map[string][]json.RawMessage)
key := ""
for i := 0; i < get; i++ {
res := <-ch
if res.StatusCode != http.StatusOK {
return res, nil
}
content, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return nil, err
}
if err := json.Unmarshal(content, &body); err != nil {
return nil, err
}
if i == 0 {
resp = res
content, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return nil, err
}
if err := json.Unmarshal(content, &newBody); err != nil {
return nil, err
}
for k := range newBody {
for k := range body {
key = k
break
}
} else {
content, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return nil, err
}
if err := json.Unmarshal(content, &body); err != nil {
return nil, err
}
newBody[key] = append(newBody[key], body[key]...)
}
newBody[key] = append(newBody[key], body[key]...)
}
payload := new(bytes.Buffer)
if err := json.NewEncoder(payload).Encode(newBody); err != nil {
@ -1509,7 +1505,9 @@ func (s *ScalewayAPI) GetImages() (*[]MarketImage, error) {
}
}
}
resp, err := s.GetResponsePaginate(s.computeAPI, "images?organization="+s.Organization, url.Values{})
values := url.Values{}
values.Set("organization", s.Organization)
resp, err := s.GetResponsePaginate(s.computeAPI, "images", values)
if resp != nil {
defer resp.Body.Close()
}
@ -1525,8 +1523,8 @@ func (s *ScalewayAPI) GetImages() (*[]MarketImage, error) {
if err = json.Unmarshal(body, &OrgaImages); err != nil {
return nil, err
}
for _, orgaImage := range OrgaImages.Images {
s.Cache.InsertImage(orgaImage.Identifier, "", orgaImage.Arch, orgaImage.Organization, orgaImage.Name, "")
images.Images = append(images.Images, MarketImage{
Categories: []string{"MyImages"},
CreationDate: orgaImage.CreationDate,
@ -1545,7 +1543,8 @@ func (s *ScalewayAPI) GetImages() (*[]MarketImage, error) {
{
Arch: orgaImage.Arch,
ID: orgaImage.Identifier,
Zone: "",
// TODO: fecth images from ams1 and par1
Zone: s.Region,
},
},
},
@ -1553,6 +1552,7 @@ func (s *ScalewayAPI) GetImages() (*[]MarketImage, error) {
},
},
})
s.Cache.InsertImage(orgaImage.Identifier, s.Region, orgaImage.Arch, orgaImage.Organization, orgaImage.Name, "")
}
return &images.Images, nil
}

6
vendor/vendor.json vendored
View File

@ -1822,10 +1822,10 @@
"revisionTime": "2016-09-27T10:08:44Z"
},
{
"checksumSHA1": "YF6baE6Sl76/nVYo0JwJXCkJmGw=",
"checksumSHA1": "BfFS70stfaoDJYyCzky1Sr0D5UE=",
"path": "github.com/scaleway/scaleway-cli/pkg/api",
"revision": "88132ecdd39da62f7c73c5a8e1a383d7da5e0e09",
"revisionTime": "2016-10-27T15:40:24Z"
"revision": "790f00aee05c9264248f1090c062ac0513e5a191",
"revisionTime": "2016-11-07T15:30:35Z"
},
{
"checksumSHA1": "aU2+iXO1oHS4vBtAXXBgicA9YBY=",