Skip to content

Commit 46c6b97

Browse files
authored
feat(instance): add compatible types endpoint and end_of_service flag in ServerType (scaleway#2432)
1 parent 32bb2d9 commit 46c6b97

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

api/instance/v1/instance_sdk.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,9 @@ type ServerType struct {
19951995

19961996
// BlockBandwidth: the maximum bandwidth allocated to block storage access (in bytes per second).
19971997
BlockBandwidth *uint64 `json:"block_bandwidth"`
1998+
1999+
// EndOfService: true if this Instance type has reached end of service.
2000+
EndOfService bool `json:"end_of_service"`
19982001
}
19992002

20002003
// VolumeType: volume type.
@@ -2720,6 +2723,15 @@ type GetSecurityGroupRuleResponse struct {
27202723
Rule *SecurityGroupRule `json:"rule"`
27212724
}
27222725

2726+
// GetServerCompatibleTypesRequest: get server compatible types request.
2727+
type GetServerCompatibleTypesRequest struct {
2728+
// Zone: zone to target. If none is passed will use default zone from the config.
2729+
Zone scw.Zone `json:"-"`
2730+
2731+
// ServerID: UUID of the Instance you want to get.
2732+
ServerID string `json:"-"`
2733+
}
2734+
27232735
// GetServerRequest: get server request.
27242736
type GetServerRequest struct {
27252737
// Zone: zone to target. If none is passed will use default zone from the config.
@@ -3475,6 +3487,12 @@ type ServerActionResponse struct {
34753487
Task *Task `json:"task"`
34763488
}
34773489

3490+
// ServerCompatibleTypes: server compatible types.
3491+
type ServerCompatibleTypes struct {
3492+
// CompatibleTypes: instance compatible types.
3493+
CompatibleTypes []string `json:"compatible_types"`
3494+
}
3495+
34783496
// SetImageRequest: set image request.
34793497
type SetImageRequest struct {
34803498
// Zone: zone to target. If none is passed will use default zone from the config.
@@ -4612,6 +4630,42 @@ func (s *API) DeleteServerUserData(req *DeleteServerUserDataRequest, opts ...scw
46124630
return nil
46134631
}
46144632

4633+
// GetServerCompatibleTypes: Get compatible commercial types that can be used to update the Instance. The compatibility of an Instance offer is based on:
4634+
// * the CPU architecture
4635+
// * the OS type
4636+
// * the required l_ssd storage size
4637+
// * the required scratch storage size
4638+
// If the specified Instance offer is flagged as end of service, the best compatible offer is the first returned.
4639+
func (s *API) GetServerCompatibleTypes(req *GetServerCompatibleTypesRequest, opts ...scw.RequestOption) (*ServerCompatibleTypes, error) {
4640+
var err error
4641+
4642+
if req.Zone == "" {
4643+
defaultZone, _ := s.client.GetDefaultZone()
4644+
req.Zone = defaultZone
4645+
}
4646+
4647+
if fmt.Sprint(req.Zone) == "" {
4648+
return nil, errors.New("field Zone cannot be empty in request")
4649+
}
4650+
4651+
if fmt.Sprint(req.ServerID) == "" {
4652+
return nil, errors.New("field ServerID cannot be empty in request")
4653+
}
4654+
4655+
scwReq := &scw.ScalewayRequest{
4656+
Method: "GET",
4657+
Path: "/instance/v1/zones/" + fmt.Sprint(req.Zone) + "/servers/" + fmt.Sprint(req.ServerID) + "/compatible-types",
4658+
}
4659+
4660+
var resp ServerCompatibleTypes
4661+
4662+
err = s.client.Do(scwReq, &resp, opts...)
4663+
if err != nil {
4664+
return nil, err
4665+
}
4666+
return &resp, nil
4667+
}
4668+
46154669
// AttachServerVolume:
46164670
func (s *API) AttachServerVolume(req *AttachServerVolumeRequest, opts ...scw.RequestOption) (*AttachServerVolumeResponse, error) {
46174671
var err error

0 commit comments

Comments
 (0)