Files
decort-golang-sdk/pkg/cloudapi/lb/backend_server_add.go

96 lines
3.5 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package lb
import (
"context"
"net/http"
"strconv"
2023-03-24 17:09:30 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-10-03 16:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// BackendServerAddRequest struct to add server definition to the backend
2022-10-03 16:56:47 +03:00
type BackendServerAddRequest struct {
2022-12-22 17:56:47 +03:00
// ID of the load balancer instance to BackendServerAdd
// Required: true
2023-03-24 17:09:30 +03:00
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
2022-12-22 17:56:47 +03:00
// Must match one of the existing backens - name of the backend to add servers to
// Required: true
2023-03-24 17:09:30 +03:00
BackendName string `url:"backendName" json:"backendName" validate:"required"`
2022-12-22 17:56:47 +03:00
// Must be unique among all servers defined for this backend - name of the server definition to add
// Required: true
2023-03-24 17:09:30 +03:00
ServerName string `url:"serverName" json:"serverName" validate:"required"`
2022-12-22 17:56:47 +03:00
// IP address of the server
// Required: true
2023-03-24 17:09:30 +03:00
Address string `url:"address" json:"address" validate:"required"`
2022-12-22 17:56:47 +03:00
// Port number on the server
// Required: true
2023-03-24 17:09:30 +03:00
Port uint64 `url:"port" json:"port" validate:"required"`
2022-12-22 17:56:47 +03:00
// Set to disabled if this server should be used regardless of its state
// Required: false
2023-03-01 19:05:53 +03:00
Check string `url:"check,omitempty" json:"check,omitempty"`
2022-12-22 17:56:47 +03:00
// Interval in milliseconds between two consecutive availability checks of the server that is considered available
// Required: false
2023-03-01 19:05:53 +03:00
Inter uint64 `url:"inter,omitempty" json:"inter,omitempty"`
2022-12-22 17:56:47 +03:00
// Interval in milliseconds between two consecutive checks to restore
// the availability of a server that is currently considered unavailable
// Required: false
2023-03-01 19:05:53 +03:00
DownInter uint64 `url:"downinter,omitempty" json:"downinter,omitempty"`
2022-12-22 17:56:47 +03:00
// Number of checks that the server must pass in order to get
// the available status and be included in the balancing scheme again
// Required: false
2023-03-01 19:05:53 +03:00
Rise uint64 `url:"rise,omitempty" json:"rise,omitempty"`
2022-12-22 17:56:47 +03:00
// Number of consecutive failed availability checks,
// after which the previously considered available server receives the status of unavailable and
// is temporarily excluded from the balancing scheme
// Required: false
2023-03-01 19:05:53 +03:00
Fall uint64 `url:"fall,omitempty" json:"fall,omitempty"`
2022-12-22 17:56:47 +03:00
// Interval in milliseconds from the moment the server receives the available status,
// after which the number of actually allowed connections to this server will be returned to 100% of the set limit
// Required: false
2023-03-01 19:05:53 +03:00
SlowStart uint64 `url:"slowstart,omitempty" json:"slowstart,omitempty"`
2022-12-22 17:56:47 +03:00
// Limit of simultaneous connections to the server. When this limit is reached, the server is temporarily excluded from the balancing scheme
// Required: false
2023-03-01 19:05:53 +03:00
MaxConn uint64 `url:"maxconn,omitempty" json:"maxconn,omitempty"`
2022-12-22 17:56:47 +03:00
// Limit of connections waiting in the queue. When this limit is reached, all subsequent connections will be forwarded to other servers
// Required: false
2023-03-01 19:05:53 +03:00
MaxQueue uint64 `url:"maxqueue,omitempty" json:"maxqueue,omitempty"`
2022-12-22 17:56:47 +03:00
// Server weight for use in weight balancing algorithms
// Required: false
2023-03-01 19:05:53 +03:00
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
2022-10-03 16:56:47 +03:00
}
2022-12-22 17:56:47 +03:00
// BackendServerAdd adds server definition to the backend on the specified load balancer
2022-10-03 16:56:47 +03:00
func (l LB) BackendServerAdd(ctx context.Context, req BackendServerAddRequest) (bool, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-10-03 16:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return false, validators.ValidationErrors(validators.GetErrors(err))
2022-10-03 16:56:47 +03:00
}
url := "/cloudapi/lb/backendServerAdd"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}