Skip to content

Commit 159e8a0

Browse files
committed
Added generic api.PatchServer method
1 parent 3553fc5 commit 159e8a0

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

api.go

+45
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,25 @@ type ScalewayServer struct {
380380
Organization string `json:"organization,omitempty"`
381381
}
382382

383+
// ScalewayServerPatchDefinition represents a Scaleway C1 server with nullable fields (for PATCH)
384+
type ScalewayServerPatchDefinition struct {
385+
Name *string `json:"name,omitempty"`
386+
CreationDate *string `json:"creation_date,omitempty"`
387+
ModificationDate *string `json:"modification_date,omitempty"`
388+
Image *ScalewayImage `json:"image,omitempty"`
389+
DynamicIPRequired *bool `json:"dynamic_ip_required,omitempty"`
390+
PublicAddress *ScalewayIPAddress `json:"public_ip,omitempty"`
391+
State *string `json:"state,omitempty"`
392+
StateDetail *string `json:"state_detail,omitempty"`
393+
PrivateIP *string `json:"private_ip,omitempty"`
394+
Bootscript *ScalewayBootscript `json:"bootscript,omitempty"`
395+
Hostname *string `json:"hostname,omitempty"`
396+
Volumes *map[string]ScalewayVolume `json:"volumes,omitempty"`
397+
SecurityGroup *ScalewaySecurityGroup `json:"security_group,omitempty"`
398+
Organization *string `json:"organization,omitempty"`
399+
//Tags *[]string `json:"tags",omitempty`
400+
}
401+
383402
// ScalewayServerPatchNameDefinition represents a Scaleway C1 server with only its name as field
384403
type ScalewayServerPatchNameDefinition struct {
385404
// Name is the user-defined name of the server
@@ -708,6 +727,32 @@ func (s *ScalewayAPI) PatchServerName(serverID string, definition ScalewayServer
708727
return error
709728
}
710729

730+
// PatchServer updates a server
731+
func (s *ScalewayAPI) PatchServer(serverID string, definition ScalewayServerPatchDefinition) error {
732+
resp, err := s.PatchResponse(fmt.Sprintf("servers/%s", serverID), definition)
733+
if err != nil {
734+
return err
735+
}
736+
737+
defer resp.Body.Close()
738+
decoder := json.NewDecoder(resp.Body)
739+
740+
// Succeed PATCH code
741+
if resp.StatusCode == 200 {
742+
return nil
743+
}
744+
745+
var error ScalewayAPIError
746+
err = decoder.Decode(&error)
747+
if err != nil {
748+
return err
749+
}
750+
751+
error.StatusCode = resp.StatusCode
752+
error.Debug()
753+
return error
754+
}
755+
711756
// PostSnapshot creates a new snapshot
712757
func (s *ScalewayAPI) PostSnapshot(volumeID string, name string) (string, error) {
713758
definition := ScalewaySnapshotDefinition{

0 commit comments

Comments
 (0)