Skip to content

Commit 0e3d0c5

Browse files
committed
feat: update generated APIs
1 parent ed9354a commit 0e3d0c5

File tree

27 files changed

+3136
-1
lines changed

27 files changed

+3136
-1
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

0 commit comments

Comments
 (0)