Skip to content

Commit cf90ebe

Browse files
committed
feat: update generated APIs
1 parent dbbe692 commit cf90ebe

File tree

29 files changed

+3291
-7
lines changed

29 files changed

+3291
-7
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/cockpit/v1/cockpit_sdk.go

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,51 @@ func (enum *ListPlansRequestOrderBy) UnmarshalJSON(data []byte) error {
381381
return nil
382382
}
383383

384+
type ListProductsRequestOrderBy string
385+
386+
const (
387+
ListProductsRequestOrderByCreatedAtAsc = ListProductsRequestOrderBy("created_at_asc")
388+
ListProductsRequestOrderByCreatedAtDesc = ListProductsRequestOrderBy("created_at_desc")
389+
ListProductsRequestOrderByDisplayNameAsc = ListProductsRequestOrderBy("display_name_asc")
390+
ListProductsRequestOrderByDisplayNameDesc = ListProductsRequestOrderBy("display_name_desc")
391+
ListProductsRequestOrderByFamilyNameAsc = ListProductsRequestOrderBy("family_name_asc")
392+
ListProductsRequestOrderByFamilyNameDesc = ListProductsRequestOrderBy("family_name_desc")
393+
)
394+
395+
func (enum ListProductsRequestOrderBy) String() string {
396+
if enum == "" {
397+
// return default value if empty
398+
return string(ListProductsRequestOrderByCreatedAtAsc)
399+
}
400+
return string(enum)
401+
}
402+
403+
func (enum ListProductsRequestOrderBy) Values() []ListProductsRequestOrderBy {
404+
return []ListProductsRequestOrderBy{
405+
"created_at_asc",
406+
"created_at_desc",
407+
"display_name_asc",
408+
"display_name_desc",
409+
"family_name_asc",
410+
"family_name_desc",
411+
}
412+
}
413+
414+
func (enum ListProductsRequestOrderBy) MarshalJSON() ([]byte, error) {
415+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
416+
}
417+
418+
func (enum *ListProductsRequestOrderBy) UnmarshalJSON(data []byte) error {
419+
tmp := ""
420+
421+
if err := json.Unmarshal(data, &tmp); err != nil {
422+
return err
423+
}
424+
425+
*enum = ListProductsRequestOrderBy(ListProductsRequestOrderBy(tmp).String())
426+
return nil
427+
}
428+
384429
type ListTokensRequestOrderBy string
385430

386431
const (
@@ -757,6 +802,17 @@ type Plan struct {
757802
MonthlyPrice uint32 `json:"monthly_price"`
758803
}
759804

805+
// Product: product.
806+
type Product struct {
807+
Name string `json:"name"`
808+
809+
DisplayName string `json:"display_name"`
810+
811+
FamilyName string `json:"family_name"`
812+
813+
ResourceTypes []string `json:"resource_types"`
814+
}
815+
760816
// Token: Token.
761817
type Token struct {
762818
// ID: ID of the token.
@@ -1162,6 +1218,32 @@ func (r *ListPlansResponse) UnsafeAppend(res any) (uint64, error) {
11621218
return uint64(len(results.Plans)), nil
11631219
}
11641220

1221+
// ListProductsResponse: list products response.
1222+
type ListProductsResponse struct {
1223+
ProductsList []*Product `json:"products_list"`
1224+
1225+
TotalCount uint64 `json:"total_count"`
1226+
}
1227+
1228+
// UnsafeGetTotalCount should not be used
1229+
// Internal usage only
1230+
func (r *ListProductsResponse) UnsafeGetTotalCount() uint64 {
1231+
return r.TotalCount
1232+
}
1233+
1234+
// UnsafeAppend should not be used
1235+
// Internal usage only
1236+
func (r *ListProductsResponse) UnsafeAppend(res any) (uint64, error) {
1237+
results, ok := res.(*ListProductsResponse)
1238+
if !ok {
1239+
return 0, errors.New("%T type cannot be appended to type %T", res, r)
1240+
}
1241+
1242+
r.ProductsList = append(r.ProductsList, results.ProductsList...)
1243+
r.TotalCount += uint64(len(results.ProductsList))
1244+
return uint64(len(results.ProductsList)), nil
1245+
}
1246+
11651247
// ListTokensResponse: Response returned when listing tokens.
11661248
type ListTokensResponse struct {
11671249
// TotalCount: total count of tokens matching the request.
@@ -1429,6 +1511,22 @@ type RegionalAPIListDataSourcesRequest struct {
14291511
Types []DataSourceType `json:"-"`
14301512
}
14311513

1514+
// RegionalAPIListProductsRequest: List all Scaleway products that send metrics and/or logs to Cockpit.
1515+
type RegionalAPIListProductsRequest struct {
1516+
// Region: region to target. If none is passed will use default region from the config.
1517+
Region scw.Region `json:"-"`
1518+
1519+
// Page: page number to return from the paginated results.
1520+
Page *int32 `json:"-"`
1521+
1522+
// PageSize: number of products to return per page.
1523+
PageSize *uint32 `json:"-"`
1524+
1525+
// OrderBy: sort order for products in the response.
1526+
// Default value: created_at_asc
1527+
OrderBy ListProductsRequestOrderBy `json:"-"`
1528+
}
1529+
14321530
// RegionalAPIListTokensRequest: List tokens.
14331531
type RegionalAPIListTokensRequest struct {
14341532
// Region: region to target. If none is passed will use default region from the config.
@@ -2257,6 +2355,44 @@ func (s *RegionalAPI) DeleteToken(req *RegionalAPIDeleteTokenRequest, opts ...sc
22572355
return nil
22582356
}
22592357

2358+
// ListProducts: List all Scaleway products that send metrics and/or logs to Cockpit.
2359+
func (s *RegionalAPI) ListProducts(req *RegionalAPIListProductsRequest, opts ...scw.RequestOption) (*ListProductsResponse, error) {
2360+
var err error
2361+
2362+
if req.Region == "" {
2363+
defaultRegion, _ := s.client.GetDefaultRegion()
2364+
req.Region = defaultRegion
2365+
}
2366+
2367+
defaultPageSize, exist := s.client.GetDefaultPageSize()
2368+
if (req.PageSize == nil || *req.PageSize == 0) && exist {
2369+
req.PageSize = &defaultPageSize
2370+
}
2371+
2372+
query := url.Values{}
2373+
parameter.AddToQuery(query, "page", req.Page)
2374+
parameter.AddToQuery(query, "page_size", req.PageSize)
2375+
parameter.AddToQuery(query, "order_by", req.OrderBy)
2376+
2377+
if fmt.Sprint(req.Region) == "" {
2378+
return nil, errors.New("field Region cannot be empty in request")
2379+
}
2380+
2381+
scwReq := &scw.ScalewayRequest{
2382+
Method: "GET",
2383+
Path: "/cockpit/v1/regions/" + fmt.Sprint(req.Region) + "/products",
2384+
Query: query,
2385+
}
2386+
2387+
var resp ListProductsResponse
2388+
2389+
err = s.client.Do(scwReq, &resp, opts...)
2390+
if err != nil {
2391+
return nil, err
2392+
}
2393+
return &resp, nil
2394+
}
2395+
22602396
// GetAlertManager: Retrieve information about the Alert manager which is unique per Project and region. By default the Alert manager is disabled.
22612397
// The output returned displays a URL to access the Alert manager, and whether the Alert manager and managed alerts are enabled.
22622398
func (s *RegionalAPI) GetAlertManager(req *RegionalAPIGetAlertManagerRequest, opts ...scw.RequestOption) (*AlertManager, error) {

0 commit comments

Comments
 (0)