1.6.0-delta

This commit is contained in:
2023-09-24 12:11:31 +03:00
parent df8b045e77
commit 9f5e76aee4
31 changed files with 924 additions and 58 deletions

View File

@@ -2,12 +2,16 @@ package lb
import (
"context"
"encoding/json"
"errors"
"net/http"
"strings"
"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,39 +24,81 @@ 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: true
Start bool `url:"start" json:"start" validate:"required"`
// Required: false
Start bool `url:"start" json:"start"`
// Text description of this load balancer
// Required: false
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 (l LB) Create(ctx context.Context, req CreateRequest) (string, error) {
func (l LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
return 0, validators.ValidationError(validationError)
}
}
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 := "/cloudapi/lb/create"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
return 0, err
}
result := strings.ReplaceAll(string(res), "\"", "")
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -20,18 +20,18 @@ type FrontendBindRequest struct {
// Name of the binding to update
// Required: true
BindingName string `url:"bindingName" json:"bindingName"`
BindingName string `url:"bindingName" json:"bindingName" validate:"required"`
// If specified must be within the IP range of either Ext Net or ViNS,
// where this load balancer is connected - new IP address to use for this binding.
// If omitted, current IP address is retained
// Required: false
BindingAddress string `url:"bindingAddress,omitempty" json:"bindingAddress,omitempty"`
// Required: true
BindingAddress string `url:"bindingAddress" json:"bindingAddress" validate:"required"`
// New port number to use for this binding.
// If omitted, current port number is retained
// Required: false
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
// Required: true
BindingPort uint64 `url:"bindingPort" json:"bindingPort" validate:"required"`
}
// FrontendBind bind frontend from specified load balancer instance

View File

@@ -25,13 +25,13 @@ type FrontendBindUpdateRequest struct {
// If specified must be within the IP range of either Ext Net or ViNS,
// where this load balancer is connected - new IP address to use for this binding.
// If omitted, current IP address is retained
// Required: false
BindingAddress string `url:"bindingAddress,omitempty" json:"bindingAddress,omitempty"`
// Required: true
BindingAddress string `url:"bindingAddress" json:"bindingAddress" validate:"required"`
// New port number to use for this binding.
// If omitted, current port number is retained
// Required: false
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
// Required: true
BindingPort uint64 `url:"bindingPort" json:"bindingPort" validate:"required"`
}
// FrontendBindUpdate updates binding for the specified load balancer frontend

View File

@@ -0,0 +1,40 @@
package lb
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for make Load Balancer Highly available
type HighlyAvailableRequest struct {
// ID of the LB instance
// Required: true
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
}
// Make Load Balancer Highly available
func (l LB) HighlyAvailable(ctx context.Context, req HighlyAvailableRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/makeHighlyAvailable"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -6,7 +6,10 @@ type RecordLB struct {
HAMode bool `json:"HAmode"`
// Access Control List
ACL interface{} `json:"acl"`
ACL []interface{} `json:"acl"`
// BackendHAIP
BackendHAIP string `json:"backendHAIP"`
// List of load balancer backends
Backends ListBackends `json:"backends"`
@@ -32,6 +35,9 @@ type RecordLB struct {
// External network ID
ExtNetID uint64 `json:"extnetId"`
// FrontendHAIP
FrontendHAIP string `json:"frontendHAIP"`
// List of load balancer frontends
Frontends ListFrontends `json:"frontends"`
@@ -53,6 +59,9 @@ type RecordLB struct {
// Name
Name string `json:"name"`
// Part K8s
PartK8s bool `json:"partK8s"`
// Primary node
PrimaryNode RecordNode `json:"primaryNode"`
@@ -68,6 +77,9 @@ type RecordLB struct {
// Status
Status string `json:"status"`
// Sysctl Params
SysctlParams []interface{} `json:"sysctlParams"`
// Tech status
TechStatus string `json:"techStatus"`

View File

@@ -0,0 +1,72 @@
package lb
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update sysct params for lb
type UpdateSysctParamsRequest struct {
// ID of the LB instance
// Required: true
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Custom sysctl values for Load Balancer instance. Applied on boot
// Required: true
SysctlParams Params `url:"-" json:"sysctlParams" validate:"required,dive"`
}
type wrapperUpdateSysctParamsRequest struct {
UpdateSysctParamsRequest
Params []string `url:"sysctlParams" validate:"required"`
}
// Create method will create a new load balancer instance
func (l LB) UpdateSysctParams(ctx context.Context, req UpdateSysctParamsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
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 false, err
}
params = append(params, string(b))
}
} else {
params = []string{}
}
reqWrapped := wrapperUpdateSysctParamsRequest{
UpdateSysctParamsRequest: req,
Params: params,
}
url := "/cloudapi/lb/updateSysctParams"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}