@@ -150,6 +150,22 @@ type ScalewayVolumeDefinition struct {
150150 Organization string `json:"organization"`
151151}
152152
153+ // ScalewayVolumePutDefinition represents a Scaleway C1 volume with nullable fields (for PUT)
154+ type ScalewayVolumePutDefinition struct {
155+ Identifier * string `json:"id,omitempty"`
156+ Size * uint64 `json:"size,omitempty"`
157+ CreationDate * string `json:"creation_date,omitempty"`
158+ ModificationDate * string `json:"modification_date,omitempty"`
159+ Organization * string `json:"organization,omitempty"`
160+ Name * string `json:"name,omitempty"`
161+ Server struct {
162+ Identifier * string `json:"id,omitempty"`
163+ Name * string `json:"name,omitempty"`
164+ } `json:"server,omitempty"`
165+ VolumeType * string `json:"volume_type,omitempty"`
166+ ExportURI * string `json:"export_uri,omitempty"`
167+ }
168+
153169// ScalewayImage represents a Scaleway Image
154170type ScalewayImage struct {
155171 // Identifier is a unique identifier for the image
@@ -544,6 +560,25 @@ func (s *ScalewayAPI) PatchResponse(resource string, data interface{}) (*http.Re
544560 return client .Do (req )
545561}
546562
563+ // PutResponse returns an http.Response object for the updated resource
564+ func (s * ScalewayAPI ) PutResponse (resource string , data interface {}) (* http.Response , error ) {
565+ uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIEndPoint , "/" ), resource )
566+ client := & http.Client {}
567+ payload := new (bytes.Buffer )
568+ encoder := json .NewEncoder (payload )
569+ if err := encoder .Encode (data ); err != nil {
570+ return nil , err
571+ }
572+ log .Debugf ("PUT %s payload=%s" , uri , strings .TrimSpace (fmt .Sprintf ("%s" , payload )))
573+ req , err := http .NewRequest ("PUT" , uri , payload )
574+ if err != nil {
575+ return nil , err
576+ }
577+ req .Header .Set ("X-Auth-Token" , s .Token )
578+ req .Header .Set ("Content-Type" , "application/json" )
579+ return client .Do (req )
580+ }
581+
547582// DeleteResponse returns an http.Response object for the deleted resource
548583func (s * ScalewayAPI ) DeleteResponse (resource string ) (* http.Response , error ) {
549584 uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIEndPoint , "/" ), resource )
@@ -851,6 +886,32 @@ func (s *ScalewayAPI) PostVolume(definition ScalewayVolumeDefinition) (string, e
851886 return "" , error
852887}
853888
889+ // PutVolume updates a volume
890+ func (s * ScalewayAPI ) PutVolume (volumeID string , definition ScalewayVolumePutDefinition ) error {
891+ resp , err := s .PutResponse (fmt .Sprintf ("volumes/%s" , volumeID ), definition )
892+ if err != nil {
893+ return err
894+ }
895+
896+ defer resp .Body .Close ()
897+ decoder := json .NewDecoder (resp .Body )
898+
899+ // Succeed PUT code
900+ if resp .StatusCode == 200 {
901+ return nil
902+ }
903+
904+ var error ScalewayAPIError
905+ err = decoder .Decode (& error )
906+ if err != nil {
907+ return err
908+ }
909+
910+ error .StatusCode = resp .StatusCode
911+ error .Debug ()
912+ return error
913+ }
914+
854915// ResolveServer attempts the find a matching Identifier for the input string
855916func (s * ScalewayAPI ) ResolveServer (needle string ) ([]string , error ) {
856917 servers := s .Cache .LookUpServers (needle , true )
0 commit comments