diff --git a/api/baremetal/v1alpha1/baremetal_sdk.go b/api/baremetal/v1alpha1/baremetal_sdk.go index 1cee3ca63..d71bd3b97 100644 --- a/api/baremetal/v1alpha1/baremetal_sdk.go +++ b/api/baremetal/v1alpha1/baremetal_sdk.go @@ -37,7 +37,7 @@ var ( _ = namegenerator.GetRandomName ) -// API this API allows to manage your Bare metal server. +// API this API allows to manage your Bare metal server type API struct { client *scw.Client } diff --git a/api/instance/v1/instance_sdk.go b/api/instance/v1/instance_sdk.go index b6c7e58f2..c5227c562 100644 --- a/api/instance/v1/instance_sdk.go +++ b/api/instance/v1/instance_sdk.go @@ -1469,7 +1469,7 @@ type CreateServerRequest struct { // // Default value: local BootType BootType `json:"boot_type"` - // Bootscript the bootscript ID to use when `boot_type` is set to `bootscript`. + // Bootscript the bootscript ID to use when `boot_type` is set to `bootscript` Bootscript *string `json:"bootscript,omitempty"` // Organization the server organization ID Organization string `json:"organization,omitempty"` @@ -3872,7 +3872,7 @@ type CreateIPRequest struct { Server *string `json:"server,omitempty"` } -// CreateIP reseve an IP +// CreateIP reserve an IP func (s *API) CreateIP(req *CreateIPRequest, opts ...scw.RequestOption) (*CreateIPResponse, error) { var err error diff --git a/api/k8s/v1beta3/k8s_sdk.go b/api/k8s/v1beta3/k8s_sdk.go index d499910be..2fe43dc86 100644 --- a/api/k8s/v1beta3/k8s_sdk.go +++ b/api/k8s/v1beta3/k8s_sdk.go @@ -37,7 +37,7 @@ var ( _ = namegenerator.GetRandomName ) -// API this API allows you to manage your kapsule clusters. +// API this API allows you to manage your kapsule clusters type API struct { client *scw.Client } @@ -506,7 +506,7 @@ type Pool struct { MinSize uint32 `json:"min_size"` // MaxSize display upper limit for this pool MaxSize uint32 `json:"max_size"` - // PlacementGroupID iD of the placement group if any + // PlacementGroupID display ID of the placement group if any PlacementGroupID *string `json:"placement_group_id"` CreatedAt time.Time `json:"created_at"` diff --git a/api/lb/v1/lb_sdk.go b/api/lb/v1/lb_sdk.go index 68f0baeb6..b7efacdce 100644 --- a/api/lb/v1/lb_sdk.go +++ b/api/lb/v1/lb_sdk.go @@ -1085,7 +1085,7 @@ type Lb struct { // LbStats lb stats type LbStats struct { - // BackendServersStats list stats object of your loadbalancer (See the BackendServerStats object description) + // BackendServersStats list stats object of your loadbalancer BackendServersStats []*BackendServerStats `json:"backend_servers_stats"` } @@ -1105,7 +1105,15 @@ type LbType struct { type ListACLResponse struct { // ACLs list of Acl object (see Acl object description) ACLs []*ACL `json:"acls"` - // TotalCount result count + // TotalCount the total number of items + TotalCount uint32 `json:"total_count"` +} + +// ListBackendStatsResponse list backend stats response +type ListBackendStatsResponse struct { + // BackendServersStats list backend stats object of your loadbalancer + BackendServersStats []*BackendServerStats `json:"backend_servers_stats"` + // TotalCount the total number of items TotalCount uint32 `json:"total_count"` } @@ -1268,7 +1276,7 @@ type CreateLbRequest struct { Name string `json:"name"` // Description resource description Description string `json:"description"` - // IPID just like for compute instances, when you destroy a Load Balancer, you can keep its highly available IP address and reuse it for another Load Balancer later. + // IPID just like for compute instances, when you destroy a Load Balancer, you can keep its highly available IP address and reuse it for another Load Balancer later IPID *string `json:"ip_id"` // Tags list of keyword Tags []string `json:"tags"` @@ -1443,7 +1451,7 @@ type ListIPsRequest struct { Region scw.Region `json:"-"` // Page page number Page *int32 `json:"-"` - // PageSize set the maximum list size + // PageSize the number of items to return PageSize *uint32 `json:"-"` // IPAddress use this to search by IP address IPAddress *string `json:"-"` @@ -1598,7 +1606,7 @@ type ListBackendsRequest struct { OrderBy ListBackendsRequestOrderBy `json:"-"` // Page page number Page *int32 `json:"-"` - // PageSize set the maximum list sizes + // PageSize the number of items to returns PageSize *uint32 `json:"-"` } @@ -2235,7 +2243,7 @@ type ListFrontendsRequest struct { OrderBy ListFrontendsRequestOrderBy `json:"-"` // Page page number Page *int32 `json:"-"` - // PageSize set the maximum list sizes + // PageSize the number of items to returns PageSize *uint32 `json:"-"` } @@ -2578,6 +2586,76 @@ func (s *API) GetLbStats(req *GetLbStatsRequest, opts ...scw.RequestOption) (*Lb return &resp, nil } +type ListBackendStatsRequest struct { + Region scw.Region `json:"-"` + // LbID load Balancer ID + LbID string `json:"-"` + // Page page number + Page *int32 `json:"-"` + // PageSize the number of items to return + PageSize *uint32 `json:"-"` +} + +func (s *API) ListBackendStats(req *ListBackendStatsRequest, opts ...scw.RequestOption) (*ListBackendStatsResponse, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + defaultPageSize, exist := s.client.GetDefaultPageSize() + if (req.PageSize == nil || *req.PageSize == 0) && exist { + req.PageSize = &defaultPageSize + } + + query := url.Values{} + parameter.AddToQuery(query, "page", req.Page) + parameter.AddToQuery(query, "page_size", req.PageSize) + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.LbID) == "" { + return nil, errors.New("field LbID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/lb/v1/regions/" + fmt.Sprint(req.Region) + "/lbs/" + fmt.Sprint(req.LbID) + "/backend-stats", + Query: query, + Headers: http.Header{}, + } + + var resp ListBackendStatsResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// UnsafeGetTotalCount should not be used +// Internal usage only +func (r *ListBackendStatsResponse) UnsafeGetTotalCount() uint32 { + return r.TotalCount +} + +// UnsafeAppend should not be used +// Internal usage only +func (r *ListBackendStatsResponse) UnsafeAppend(res interface{}) (uint32, scw.SdkError) { + results, ok := res.(*ListBackendStatsResponse) + if !ok { + return 0, errors.New("%T type cannot be appended to type %T", res, r) + } + + r.BackendServersStats = append(r.BackendServersStats, results.BackendServersStats...) + r.TotalCount += uint32(len(results.BackendServersStats)) + return uint32(len(results.BackendServersStats)), nil +} + type ListACLsRequest struct { Region scw.Region `json:"-"` // FrontendID iD of your frontend @@ -2588,7 +2666,7 @@ type ListACLsRequest struct { OrderBy ListACLRequestOrderBy `json:"-"` // Page page number Page *int32 `json:"-"` - // PageSize set the maximum list size + // PageSize the number of items to return PageSize *uint32 `json:"-"` // Name filter acl per name Name *string `json:"-"` @@ -2896,7 +2974,7 @@ type ListCertificatesRequest struct { OrderBy ListCertificatesRequestOrderBy `json:"-"` // Page page number Page *int32 `json:"-"` - // PageSize set the maximum list size + // PageSize the number of items to return PageSize *uint32 `json:"-"` // Name use this to search by name Name *string `json:"-"` @@ -3088,7 +3166,7 @@ type ListLbTypesRequest struct { Region scw.Region `json:"-"` // Page page number Page *int32 `json:"-"` - // PageSize set the maximum list size + // PageSize the number of items to return PageSize *uint32 `json:"-"` } diff --git a/api/rdb/v1/rdb_sdk.go b/api/rdb/v1/rdb_sdk.go index 890b30042..b56d88e58 100644 --- a/api/rdb/v1/rdb_sdk.go +++ b/api/rdb/v1/rdb_sdk.go @@ -1253,7 +1253,7 @@ type RestoreDatabaseBackupRequest struct { Region scw.Region `json:"-"` // DatabaseBackupID backup of a logical database DatabaseBackupID string `json:"-"` - // DatabaseName defines the destination database in order to restore into a specified database, the default destination is set to the origin database of the backup. + // DatabaseName defines the destination database in order to restore into a specified database, the default destination is set to the origin database of the backup DatabaseName *string `json:"database_name"` // InstanceID defines the rdb instance where the backup has to be restored InstanceID string `json:"instance_id"` diff --git a/api/registry/v1/registry_sdk.go b/api/registry/v1/registry_sdk.go index 6245142dd..9eb75bb58 100644 --- a/api/registry/v1/registry_sdk.go +++ b/api/registry/v1/registry_sdk.go @@ -329,7 +329,9 @@ type Image struct { // // Default value: visibility_unknown Visibility ImageVisibility `json:"visibility"` - // Size image size in bytes, calculated from the size of image layers. One layer used in two tags of the same image is counted once but one layer used in two images is counted twice. + // Size image size in bytes, calculated from the size of image layers + // + // Image size in bytes, calculated from the size of image layers. One layer used in two tags of the same image is counted once but one layer used in two images is counted twice. Size uint64 `json:"size"` // CreatedAt creation date CreatedAt time.Time `json:"created_at"` diff --git a/api/test/v1/test_sdk.go b/api/test/v1/test_sdk.go index 239b465a9..6781f697c 100644 --- a/api/test/v1/test_sdk.go +++ b/api/test/v1/test_sdk.go @@ -37,7 +37,7 @@ var ( _ = namegenerator.GetRandomName ) -// API no Auth Service for end-to-end testing. +// API no Auth Service for end-to-end testing type API struct { client *scw.Client }