v1.6.0-zeta

This commit is contained in:
2023-09-25 19:11:33 +03:00
parent 3e55195831
commit 78a4152471
33 changed files with 1166 additions and 39 deletions

View File

@@ -2,12 +2,16 @@ package lb
import (
"context"
"encoding/json"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type Params []string
// Request struct for create load balancer
type CreateRequest struct {
// ID of the resource group where this load balancer instance will be located
@@ -20,12 +24,20 @@ type CreateRequest struct {
Name string `url:"name" json:"name" validate:"required"`
// External network to connect this load balancer to
// Required: true
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
// Required: false
ExtNetID uint64 `url:"extnetId" json:"extnetId"`
// Internal network (VINS) to connect this load balancer to
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// Required: false
VINSID uint64 `url:"vinsId" json:"vinsId"`
// Custom sysctl values for Load Balancer instance. Applied on boot
// Required: false
SysctlParams Params `url:"-" json:"sysctlParams,omitempty" validate:"omitempty,dive"`
// Use Highly Available schema for LB deploy
// Required: false
HighlyAvailable bool `url:"highlyAvailable,omitempty" json:"highlyAvailable,omitempty"`
// Start now Load balancer
// Required: false
@@ -36,6 +48,11 @@ type CreateRequest struct {
Description string `url:"desc,omitempty" json:"desc,omitempty"`
}
type wrapperCreateRequest struct {
CreateRequest
Params []string `url:"sysctlParams,omitempty"`
}
// Create method will create a new load balancer instance
func (lb LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
@@ -45,9 +62,35 @@ func (lb LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
}
}
if req.ExtNetID == 0 && req.VINSID == 0 {
return 0, errors.New("vinsId and extNetId cannot be both in the value 0")
}
var params []string
if len(req.SysctlParams) != 0 {
params = make([]string, 0, len(req.SysctlParams))
for r := range req.SysctlParams {
b, err := json.Marshal(req.SysctlParams[r])
if err != nil {
return 0, err
}
params = append(params, string(b))
}
} else {
params = []string{}
}
reqWrapped := wrapperCreateRequest{
CreateRequest: req,
Params: params,
}
url := "/cloudbroker/lb/create"
res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}