provider/scaleway: use building DetachIP func

This commit is contained in:
Raphael Randschau 2016-10-10 20:02:10 +02:00
parent 85b982f26d
commit a5d105da36
No known key found for this signature in database
GPG Key ID: ECFD707E1275A182
2 changed files with 1 additions and 30 deletions

View File

@ -1,9 +1,7 @@
package scaleway
import (
"fmt"
"log"
"net/http"
"time"
"github.com/scaleway/scaleway-cli/pkg/api"
@ -19,33 +17,6 @@ func String(val string) *string {
return &val
}
// DetachIP detaches an IP from a server
func DetachIP(s *api.ScalewayAPI, ipID string) error {
var update struct {
Address string `json:"address"`
ID string `json:"id"`
Organization string `json:"organization"`
}
ip, err := s.GetIP(ipID)
if err != nil {
return err
}
update.Address = ip.IP.Address
update.ID = ip.IP.ID
update.Organization = ip.IP.Organization
resp, err := s.PutResponse(api.ComputeAPI, fmt.Sprintf("ips/%s", ipID), update)
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return err
}
resp.Body.Close()
return nil
}
// NOTE copied from github.com/scaleway/scaleway-cli/pkg/api/helpers.go
// the helpers.go file pulls in quite a lot dependencies, and they're just convenience wrappers anyway

View File

@ -70,7 +70,7 @@ func resourceScalewayIPUpdate(d *schema.ResourceData, m interface{}) error {
}
} else {
log.Printf("[DEBUG] Detaching IP %q\n", d.Id())
return DetachIP(scaleway, d.Id())
return scaleway.DetachIP(d.Id())
}
}