Skip to content

Commit 3883856

Browse files
committed
feat: update generated APIs
1 parent de474a9 commit 3883856

File tree

31 files changed

+3691
-0
lines changed

31 files changed

+3691
-0
lines changed

api/applesilicon/v1alpha1/applesilicon_sdk.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ import (
1515
"time"
1616

1717
"github.com/scaleway/scaleway-sdk-go/errors"
18+
"github.com/scaleway/scaleway-sdk-go/internal/async"
1819
"github.com/scaleway/scaleway-sdk-go/marshaler"
1920
"github.com/scaleway/scaleway-sdk-go/namegenerator"
2021
"github.com/scaleway/scaleway-sdk-go/parameter"
2122
"github.com/scaleway/scaleway-sdk-go/scw"
2223
)
2324

25+
const (
26+
defaultApplesiliconRetryInterval = 15 * time.Second
27+
defaultApplesiliconTimeout = 1 * time.Hour
28+
)
29+
2430
// always import dependencies
2531
var (
2632
_ fmt.Stringer
@@ -1430,6 +1436,58 @@ func (s *API) GetServer(req *GetServerRequest, opts ...scw.RequestOption) (*Serv
14301436
return &resp, nil
14311437
}
14321438

1439+
// WaitForServerRequest is used by WaitForServer method.
1440+
type WaitForServerRequest struct {
1441+
GetServerRequest
1442+
Timeout *time.Duration
1443+
RetryInterval *time.Duration
1444+
}
1445+
1446+
// WaitForServer waits for the Server to reach a terminal state.
1447+
func (s *API) WaitForServer(req *WaitForServerRequest, opts ...scw.RequestOption) (*Server, error) {
1448+
timeout := defaultApplesiliconTimeout
1449+
if req.Timeout != nil {
1450+
timeout = *req.Timeout
1451+
}
1452+
1453+
retryInterval := defaultApplesiliconRetryInterval
1454+
if req.RetryInterval != nil {
1455+
retryInterval = *req.RetryInterval
1456+
}
1457+
transientStatuses := map[ServerStatus]struct{}{
1458+
ServerStatusStarting: {},
1459+
ServerStatusRebooting: {},
1460+
ServerStatusUpdating: {},
1461+
ServerStatusLocking: {},
1462+
ServerStatusUnlocking: {},
1463+
ServerStatusReinstalling: {},
1464+
ServerStatusBusy: {},
1465+
}
1466+
1467+
res, err := async.WaitSync(&async.WaitSyncConfig{
1468+
Get: func() (interface{}, bool, error) {
1469+
res, err := s.GetServer(&GetServerRequest{
1470+
Zone: req.Zone,
1471+
ServerID: req.ServerID,
1472+
}, opts...)
1473+
if err != nil {
1474+
return nil, false, err
1475+
}
1476+
1477+
_, isTransient := transientStatuses[res.Status]
1478+
1479+
return res, !isTransient, nil
1480+
},
1481+
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
1482+
Timeout: timeout,
1483+
})
1484+
if err != nil {
1485+
return nil, errors.Wrap(err, "waiting for Server failed")
1486+
}
1487+
1488+
return res.(*Server), nil
1489+
}
1490+
14331491
// UpdateServer: Update the parameters of an existing Apple silicon server, specified by its server ID.
14341492
func (s *API) UpdateServer(req *UpdateServerRequest, opts ...scw.RequestOption) (*Server, error) {
14351493
var err error
@@ -1681,6 +1739,54 @@ func (s *PrivateNetworkAPI) GetServerPrivateNetwork(req *PrivateNetworkAPIGetSer
16811739
return &resp, nil
16821740
}
16831741

1742+
// WaitForServerPrivateNetworkRequest is used by WaitForServerPrivateNetwork method.
1743+
type WaitForServerPrivateNetworkRequest struct {
1744+
PrivateNetworkAPIGetServerPrivateNetworkRequest
1745+
Timeout *time.Duration
1746+
RetryInterval *time.Duration
1747+
}
1748+
1749+
// WaitForServerPrivateNetwork waits for the ServerPrivateNetwork to reach a terminal state.
1750+
func (s *PrivateNetworkAPI) WaitForServerPrivateNetwork(req *WaitForServerPrivateNetworkRequest, opts ...scw.RequestOption) (*ServerPrivateNetwork, error) {
1751+
timeout := defaultApplesiliconTimeout
1752+
if req.Timeout != nil {
1753+
timeout = *req.Timeout
1754+
}
1755+
1756+
retryInterval := defaultApplesiliconRetryInterval
1757+
if req.RetryInterval != nil {
1758+
retryInterval = *req.RetryInterval
1759+
}
1760+
transientStatuses := map[ServerPrivateNetworkServerStatus]struct{}{
1761+
ServerPrivateNetworkServerStatusAttaching: {},
1762+
ServerPrivateNetworkServerStatusDetaching: {},
1763+
}
1764+
1765+
res, err := async.WaitSync(&async.WaitSyncConfig{
1766+
Get: func() (interface{}, bool, error) {
1767+
res, err := s.GetServerPrivateNetwork(&PrivateNetworkAPIGetServerPrivateNetworkRequest{
1768+
Zone: req.Zone,
1769+
ServerID: req.ServerID,
1770+
PrivateNetworkID: req.PrivateNetworkID,
1771+
}, opts...)
1772+
if err != nil {
1773+
return nil, false, err
1774+
}
1775+
1776+
_, isTransient := transientStatuses[res.Status]
1777+
1778+
return res, !isTransient, nil
1779+
},
1780+
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
1781+
Timeout: timeout,
1782+
})
1783+
if err != nil {
1784+
return nil, errors.Wrap(err, "waiting for ServerPrivateNetwork failed")
1785+
}
1786+
1787+
return res.(*ServerPrivateNetwork), nil
1788+
}
1789+
16841790
// AddServerPrivateNetwork: Add an Apple silicon server to a Private Network.
16851791
func (s *PrivateNetworkAPI) AddServerPrivateNetwork(req *PrivateNetworkAPIAddServerPrivateNetworkRequest, opts ...scw.RequestOption) (*ServerPrivateNetwork, error) {
16861792
var err error

api/baremetal/v1/baremetal_sdk.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ import (
1515
"time"
1616

1717
"github.com/scaleway/scaleway-sdk-go/errors"
18+
"github.com/scaleway/scaleway-sdk-go/internal/async"
1819
"github.com/scaleway/scaleway-sdk-go/marshaler"
1920
"github.com/scaleway/scaleway-sdk-go/namegenerator"
2021
"github.com/scaleway/scaleway-sdk-go/parameter"
2122
"github.com/scaleway/scaleway-sdk-go/scw"
2223
)
2324

25+
const (
26+
defaultBaremetalRetryInterval = 15 * time.Second
27+
defaultBaremetalTimeout = 2 * time.Hour
28+
)
29+
2430
// always import dependencies
2531
var (
2632
_ fmt.Stringer
@@ -2285,6 +2291,58 @@ func (s *API) GetServer(req *GetServerRequest, opts ...scw.RequestOption) (*Serv
22852291
return &resp, nil
22862292
}
22872293

2294+
// WaitForServerRequest is used by WaitForServer method.
2295+
type WaitForServerRequest struct {
2296+
GetServerRequest
2297+
Timeout *time.Duration
2298+
RetryInterval *time.Duration
2299+
}
2300+
2301+
// WaitForServer waits for the Server to reach a terminal state.
2302+
func (s *API) WaitForServer(req *WaitForServerRequest, opts ...scw.RequestOption) (*Server, error) {
2303+
timeout := defaultBaremetalTimeout
2304+
if req.Timeout != nil {
2305+
timeout = *req.Timeout
2306+
}
2307+
2308+
retryInterval := defaultBaremetalRetryInterval
2309+
if req.RetryInterval != nil {
2310+
retryInterval = *req.RetryInterval
2311+
}
2312+
transientStatuses := map[ServerStatus]struct{}{
2313+
ServerStatusDelivering: {},
2314+
ServerStatusStopping: {},
2315+
ServerStatusStarting: {},
2316+
ServerStatusDeleting: {},
2317+
ServerStatusOrdered: {},
2318+
ServerStatusResetting: {},
2319+
ServerStatusMigrating: {},
2320+
}
2321+
2322+
res, err := async.WaitSync(&async.WaitSyncConfig{
2323+
Get: func() (interface{}, bool, error) {
2324+
res, err := s.GetServer(&GetServerRequest{
2325+
Zone: req.Zone,
2326+
ServerID: req.ServerID,
2327+
}, opts...)
2328+
if err != nil {
2329+
return nil, false, err
2330+
}
2331+
2332+
_, isTransient := transientStatuses[res.Status]
2333+
2334+
return res, !isTransient, nil
2335+
},
2336+
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
2337+
Timeout: timeout,
2338+
})
2339+
if err != nil {
2340+
return nil, errors.Wrap(err, "waiting for Server failed")
2341+
}
2342+
2343+
return res.(*Server), nil
2344+
}
2345+
22882346
// CreateServer: Create a new Elastic Metal server. Once the server is created, proceed with the [installation of an OS](#post-3e949e).
22892347
func (s *API) CreateServer(req *CreateServerRequest, opts ...scw.RequestOption) (*Server, error) {
22902348
var err error

api/block/v1/block_sdk.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ import (
1515
"time"
1616

1717
"github.com/scaleway/scaleway-sdk-go/errors"
18+
"github.com/scaleway/scaleway-sdk-go/internal/async"
1819
"github.com/scaleway/scaleway-sdk-go/marshaler"
1920
"github.com/scaleway/scaleway-sdk-go/namegenerator"
2021
"github.com/scaleway/scaleway-sdk-go/parameter"
2122
"github.com/scaleway/scaleway-sdk-go/scw"
2223
)
2324

25+
const (
26+
defaultBlockRetryInterval = 15 * time.Second
27+
defaultBlockTimeout = 5 * time.Minute
28+
)
29+
2430
// always import dependencies
2531
var (
2632
_ fmt.Stringer
@@ -1053,6 +1059,56 @@ func (s *API) GetVolume(req *GetVolumeRequest, opts ...scw.RequestOption) (*Volu
10531059
return &resp, nil
10541060
}
10551061

1062+
// WaitForVolumeRequest is used by WaitForVolume method.
1063+
type WaitForVolumeRequest struct {
1064+
GetVolumeRequest
1065+
Timeout *time.Duration
1066+
RetryInterval *time.Duration
1067+
}
1068+
1069+
// WaitForVolume waits for the Volume to reach a terminal state.
1070+
func (s *API) WaitForVolume(req *WaitForVolumeRequest, opts ...scw.RequestOption) (*Volume, error) {
1071+
timeout := defaultBlockTimeout
1072+
if req.Timeout != nil {
1073+
timeout = *req.Timeout
1074+
}
1075+
1076+
retryInterval := defaultBlockRetryInterval
1077+
if req.RetryInterval != nil {
1078+
retryInterval = *req.RetryInterval
1079+
}
1080+
transientStatuses := map[VolumeStatus]struct{}{
1081+
VolumeStatusCreating: {},
1082+
VolumeStatusDeleting: {},
1083+
VolumeStatusResizing: {},
1084+
VolumeStatusSnapshotting: {},
1085+
VolumeStatusUpdating: {},
1086+
}
1087+
1088+
res, err := async.WaitSync(&async.WaitSyncConfig{
1089+
Get: func() (interface{}, bool, error) {
1090+
res, err := s.GetVolume(&GetVolumeRequest{
1091+
Zone: req.Zone,
1092+
VolumeID: req.VolumeID,
1093+
}, opts...)
1094+
if err != nil {
1095+
return nil, false, err
1096+
}
1097+
1098+
_, isTransient := transientStatuses[res.Status]
1099+
1100+
return res, !isTransient, nil
1101+
},
1102+
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
1103+
Timeout: timeout,
1104+
})
1105+
if err != nil {
1106+
return nil, errors.Wrap(err, "waiting for Volume failed")
1107+
}
1108+
1109+
return res.(*Volume), nil
1110+
}
1111+
10561112
// DeleteVolume: You must specify the `volume_id` of the volume you want to delete. The volume must not be in the `in_use` status.
10571113
func (s *API) DeleteVolume(req *DeleteVolumeRequest, opts ...scw.RequestOption) error {
10581114
var err error
@@ -1194,6 +1250,54 @@ func (s *API) GetSnapshot(req *GetSnapshotRequest, opts ...scw.RequestOption) (*
11941250
return &resp, nil
11951251
}
11961252

1253+
// WaitForSnapshotRequest is used by WaitForSnapshot method.
1254+
type WaitForSnapshotRequest struct {
1255+
GetSnapshotRequest
1256+
Timeout *time.Duration
1257+
RetryInterval *time.Duration
1258+
}
1259+
1260+
// WaitForSnapshot waits for the Snapshot to reach a terminal state.
1261+
func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest, opts ...scw.RequestOption) (*Snapshot, error) {
1262+
timeout := defaultBlockTimeout
1263+
if req.Timeout != nil {
1264+
timeout = *req.Timeout
1265+
}
1266+
1267+
retryInterval := defaultBlockRetryInterval
1268+
if req.RetryInterval != nil {
1269+
retryInterval = *req.RetryInterval
1270+
}
1271+
transientStatuses := map[SnapshotStatus]struct{}{
1272+
SnapshotStatusCreating: {},
1273+
SnapshotStatusDeleting: {},
1274+
SnapshotStatusExporting: {},
1275+
}
1276+
1277+
res, err := async.WaitSync(&async.WaitSyncConfig{
1278+
Get: func() (interface{}, bool, error) {
1279+
res, err := s.GetSnapshot(&GetSnapshotRequest{
1280+
Zone: req.Zone,
1281+
SnapshotID: req.SnapshotID,
1282+
}, opts...)
1283+
if err != nil {
1284+
return nil, false, err
1285+
}
1286+
1287+
_, isTransient := transientStatuses[res.Status]
1288+
1289+
return res, !isTransient, nil
1290+
},
1291+
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
1292+
Timeout: timeout,
1293+
})
1294+
if err != nil {
1295+
return nil, errors.Wrap(err, "waiting for Snapshot failed")
1296+
}
1297+
1298+
return res.(*Snapshot), nil
1299+
}
1300+
11971301
// CreateSnapshot: To create a snapshot, the volume must be in the `in_use` or the `available` status.
11981302
// If your volume is in a transient state, you need to wait until the end of the current operation.
11991303
func (s *API) CreateSnapshot(req *CreateSnapshotRequest, opts ...scw.RequestOption) (*Snapshot, error) {

0 commit comments

Comments
 (0)