v9.0.0
This commit is contained in:
90
pkg/cloudapi/lb/backend_create.go
Normal file
90
pkg/cloudapi/lb/backend_create.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// BackendCreateRequest struct to create backend
|
||||
type BackendCreateRequest struct {
|
||||
// ID of the load balancer instance to backendCreate
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must be unique among all backends of this load balancer - name of the new backend to create
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
|
||||
// Algorithm
|
||||
// Should be one of:
|
||||
// - roundrobin
|
||||
// - static-rr
|
||||
// - leastconn
|
||||
// Required: false
|
||||
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty" validate:"omitempty,lbAlgorithm"`
|
||||
|
||||
// Interval in milliseconds between two consecutive availability
|
||||
// checks of the server that is considered available
|
||||
// Required: false
|
||||
Inter uint64 `url:"inter,omitempty" json:"inter,omitempty"`
|
||||
|
||||
// Interval in milliseconds between two consecutive checks to
|
||||
// restore the availability of a server that is currently considered unavailable
|
||||
// Required: false
|
||||
DownInter uint64 `url:"downinter,omitempty" json:"downinter,omitempty"`
|
||||
|
||||
// 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
|
||||
Rise uint64 `url:"rise,omitempty" json:"rise,omitempty"`
|
||||
|
||||
// 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
|
||||
Fall uint64 `url:"fall,omitempty" json:"fall,omitempty"`
|
||||
|
||||
// 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
|
||||
SlowStart uint64 `url:"slowstart,omitempty" json:"slowstart,omitempty"`
|
||||
|
||||
// Limit of simultaneous connections to the server. When this limit is reached,
|
||||
// the server is temporarily excluded from the balancing scheme
|
||||
// Required: false
|
||||
MaxConn uint64 `url:"maxconn,omitempty" json:"maxconn,omitempty"`
|
||||
|
||||
// Limit of connections waiting in the queue.
|
||||
// When this limit is reached, all subsequent connections will be forwarded to other servers
|
||||
// Required: false
|
||||
MaxQueue uint64 `url:"maxqueue,omitempty" json:"maxqueue,omitempty"`
|
||||
|
||||
// Server weight for use in weight balancing algorithms
|
||||
// Required: false
|
||||
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
|
||||
}
|
||||
|
||||
// BackendCreate creates new backend on the specified load balancer
|
||||
func (l LB) BackendCreate(ctx context.Context, req BackendCreateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/backendCreate"
|
||||
|
||||
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
|
||||
}
|
||||
43
pkg/cloudapi/lb/backend_delete.go
Normal file
43
pkg/cloudapi/lb/backend_delete.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// BackendDeleteRequest struct to delete backend
|
||||
type BackendDeleteRequest struct {
|
||||
// ID of the load balancer instance to BackendDelete
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Cannot be emtpy string - name of the backend to delete
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
}
|
||||
|
||||
// BackendDelete deletes backend from the specified load balancer.
|
||||
// Warning: you cannot undo this action!
|
||||
func (l LB) BackendDelete(ctx context.Context, req BackendDeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/backendDelete"
|
||||
|
||||
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
|
||||
}
|
||||
95
pkg/cloudapi/lb/backend_server_add.go
Normal file
95
pkg/cloudapi/lb/backend_server_add.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// BackendServerAddRequest struct to add server definition to the backend
|
||||
type BackendServerAddRequest struct {
|
||||
// ID of the load balancer instance to BackendServerAdd
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must match one of the existing backens - name of the backend to add servers to
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
|
||||
// Must be unique among all servers defined for this backend - name of the server definition to add
|
||||
// Required: true
|
||||
ServerName string `url:"serverName" json:"serverName" validate:"required"`
|
||||
|
||||
// IP address of the server
|
||||
// Required: true
|
||||
Address string `url:"address" json:"address" validate:"required"`
|
||||
|
||||
// Port number on the server
|
||||
// Required: true
|
||||
Port uint64 `url:"port" json:"port" validate:"required"`
|
||||
|
||||
// Set to disabled if this server should be used regardless of its state
|
||||
// Required: false
|
||||
Check string `url:"check,omitempty" json:"check,omitempty"`
|
||||
|
||||
// Interval in milliseconds between two consecutive availability checks of the server that is considered available
|
||||
// Required: false
|
||||
Inter uint64 `url:"inter,omitempty" json:"inter,omitempty"`
|
||||
|
||||
// Interval in milliseconds between two consecutive checks to restore
|
||||
// the availability of a server that is currently considered unavailable
|
||||
// Required: false
|
||||
DownInter uint64 `url:"downinter,omitempty" json:"downinter,omitempty"`
|
||||
|
||||
// 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
|
||||
Rise uint64 `url:"rise,omitempty" json:"rise,omitempty"`
|
||||
|
||||
// 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
|
||||
Fall uint64 `url:"fall,omitempty" json:"fall,omitempty"`
|
||||
|
||||
// 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
|
||||
SlowStart uint64 `url:"slowstart,omitempty" json:"slowstart,omitempty"`
|
||||
|
||||
// Limit of simultaneous connections to the server. When this limit is reached, the server is temporarily excluded from the balancing scheme
|
||||
// Required: false
|
||||
MaxConn uint64 `url:"maxconn,omitempty" json:"maxconn,omitempty"`
|
||||
|
||||
// Limit of connections waiting in the queue. When this limit is reached, all subsequent connections will be forwarded to other servers
|
||||
// Required: false
|
||||
MaxQueue uint64 `url:"maxqueue,omitempty" json:"maxqueue,omitempty"`
|
||||
|
||||
// Server weight for use in weight balancing algorithms
|
||||
// Required: false
|
||||
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
|
||||
}
|
||||
|
||||
// BackendServerAdd adds server definition to the backend on the specified load balancer
|
||||
func (l LB) BackendServerAdd(ctx context.Context, req BackendServerAddRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
47
pkg/cloudapi/lb/backend_server_delete.go
Normal file
47
pkg/cloudapi/lb/backend_server_delete.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// BackendServerDeleteRequest struct to delete server definition
|
||||
type BackendServerDeleteRequest struct {
|
||||
// ID of the load balancer instance to BackendServerDelete
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must match one of the existing backends - name of the backend to add servers to
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
|
||||
// Must be unique among all servers defined for this backend - name of the server definition to add
|
||||
// Required: true
|
||||
ServerName string `url:"serverName" json:"serverName" validate:"required"`
|
||||
}
|
||||
|
||||
// BackendServerDelete deletes server definition from the backend on the specified load balancer.
|
||||
// Warning: you cannot undo this action!
|
||||
func (l LB) BackendServerDelete(ctx context.Context, req BackendServerDeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/backendServerDelete"
|
||||
|
||||
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
|
||||
}
|
||||
95
pkg/cloudapi/lb/backend_server_update.go
Normal file
95
pkg/cloudapi/lb/backend_server_update.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// BackendServerUpdateRequest struct to update server
|
||||
type BackendServerUpdateRequest struct {
|
||||
// ID of the load balancer instance to BackendServerAdd
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must match one of the existing backends - name of the backend to add servers to
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
|
||||
// Must be unique among all servers defined for this backend - name of the server definition to add
|
||||
// Required: true
|
||||
ServerName string `url:"serverName" json:"serverName" validate:"required"`
|
||||
|
||||
// IP address of the server
|
||||
// Required: true
|
||||
Address string `url:"address" json:"address" validate:"required"`
|
||||
|
||||
// Port number on the server
|
||||
// Required: true
|
||||
Port uint64 `url:"port" json:"port" validate:"required"`
|
||||
|
||||
// Set to disabled if this server should be used regardless of its state
|
||||
// Required: false
|
||||
Check string `url:"check,omitempty" json:"check,omitempty"`
|
||||
|
||||
// Interval in milliseconds between two consecutive availability checks of the server that is considered available
|
||||
// Required: false
|
||||
Inter uint64 `url:"inter,omitempty" json:"inter,omitempty"`
|
||||
|
||||
// Interval in milliseconds between two consecutive checks to restore
|
||||
// the availability of a server that is currently considered unavailable
|
||||
// Required: false
|
||||
DownInter uint64 `url:"downinter,omitempty" json:"downinter,omitempty"`
|
||||
|
||||
// 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
|
||||
Rise uint64 `url:"rise,omitempty" json:"rise,omitempty"`
|
||||
|
||||
// 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
|
||||
Fall uint64 `url:"fall,omitempty" json:"fall,omitempty"`
|
||||
|
||||
// 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
|
||||
SlowStart uint64 `url:"slowstart,omitempty" json:"slowstart,omitempty"`
|
||||
|
||||
// Limit of simultaneous connections to the server. When this limit is reached, the server is temporarily excluded from the balancing scheme
|
||||
// Required: false
|
||||
MaxConn uint64 `url:"maxconn,omitempty" json:"maxconn,omitempty"`
|
||||
|
||||
// Limit of connections waiting in the queue. When this limit is reached, all subsequent connections will be forwarded to other servers
|
||||
// Required: false
|
||||
MaxQueue uint64 `url:"maxqueue,omitempty" json:"maxqueue,omitempty"`
|
||||
|
||||
// Server weight for use in weight balancing algorithms
|
||||
// Required: false
|
||||
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
|
||||
}
|
||||
|
||||
// BackendServerUpdate updates server definition on the backend of load balancer
|
||||
func (l LB) BackendServerUpdate(ctx context.Context, req BackendServerUpdateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/backendServerUpdate"
|
||||
|
||||
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
|
||||
}
|
||||
90
pkg/cloudapi/lb/backend_update.go
Normal file
90
pkg/cloudapi/lb/backend_update.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// BackendUpdateRequest struct to update backend
|
||||
type BackendUpdateRequest struct {
|
||||
// ID of the load balancer instance to backendCreate
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must be unique among all backends of this load balancer - name of the new backend to create
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
|
||||
// Algorithm
|
||||
// Should be one of:
|
||||
// - roundrobin
|
||||
// - static-rr
|
||||
// - leastconn
|
||||
// Required: false
|
||||
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty" validate:"omitempty,lbAlgorithm"`
|
||||
|
||||
// Interval in milliseconds between two consecutive availability
|
||||
// checks of the server that is considered available
|
||||
// Required: false
|
||||
Inter uint64 `url:"inter,omitempty" json:"inter,omitempty"`
|
||||
|
||||
// Interval in milliseconds between two consecutive checks to
|
||||
// restore the availability of a server that is currently considered unavailable
|
||||
// Required: false
|
||||
DownInter uint64 `url:"downinter,omitempty" json:"downinter,omitempty"`
|
||||
|
||||
// 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
|
||||
Rise uint64 `url:"rise,omitempty" json:"rise,omitempty"`
|
||||
|
||||
// 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
|
||||
Fall uint64 `url:"fall,omitempty" json:"fall,omitempty"`
|
||||
|
||||
// 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
|
||||
SlowStart uint64 `url:"slowstart,omitempty" json:"slowstart,omitempty"`
|
||||
|
||||
// Limit of simultaneous connections to the server. When this limit is reached,
|
||||
// the server is temporarily excluded from the balancing scheme
|
||||
// Required: false
|
||||
MaxConn uint64 `url:"maxconn,omitempty" json:"maxconn,omitempty"`
|
||||
|
||||
// Limit of connections waiting in the queue.
|
||||
// When this limit is reached, all subsequent connections will be forwarded to other servers
|
||||
// Required: false
|
||||
MaxQueue uint64 `url:"maxqueue,omitempty" json:"maxqueue,omitempty"`
|
||||
|
||||
// Server weight for use in weight balancing algorithms
|
||||
// Required: false
|
||||
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
|
||||
}
|
||||
|
||||
// BackendUpdate updates existing backend on the specified load balancer. Note that backend name cannot be changed
|
||||
func (l LB) BackendUpdate(ctx context.Context, req BackendUpdateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/backendUpdate"
|
||||
|
||||
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
|
||||
}
|
||||
39
pkg/cloudapi/lb/config_reset.go
Normal file
39
pkg/cloudapi/lb/config_reset.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ConfigResetRequest struct for reset config
|
||||
type ConfigResetRequest struct {
|
||||
// ID of the load balancer instance to ConfigReset
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigReset reset current software configuration of the specified load balancer.
|
||||
// Warning: this action cannot be undone!
|
||||
func (l LB) ConfigReset(ctx context.Context, req ConfigResetRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/configReset"
|
||||
|
||||
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
|
||||
}
|
||||
98
pkg/cloudapi/lb/create.go
Normal file
98
pkg/cloudapi/lb/create.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// CreateRequest struct to create load balancer
|
||||
type CreateRequest struct {
|
||||
// ID of the resource group where this load balancer instance will be located
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Name of the load balancer.
|
||||
// Must be unique among all load balancers in this Resource Group
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// External network to connect this load balancer to
|
||||
// Required: true, can be 0
|
||||
ExtNetID uint64 `url:"extnetId" json:"extnetId"`
|
||||
|
||||
// Internal network (VINS) to connect this load balancer to
|
||||
// Required: true, can be 0
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId"`
|
||||
|
||||
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||
// Required: false
|
||||
SysctlParams []map[string]interface{} `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
|
||||
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) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
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 _, m := range req.SysctlParams {
|
||||
encodeStr, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
params = append(params, string(encodeStr))
|
||||
}
|
||||
} else {
|
||||
params = []string{}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateRequest{
|
||||
CreateRequest: req,
|
||||
Params: params,
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/create"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudapi/lb/delete.go
Normal file
42
pkg/cloudapi/lb/delete.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DeleteRequest struct to delete load balancer
|
||||
type DeleteRequest struct {
|
||||
// ID of the load balancer instance to delete
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Set to true to delete load balancer immediately bypassing recycle bin
|
||||
// Required: false
|
||||
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
// Delete deletes specified load balancer
|
||||
func (l LB) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/delete"
|
||||
|
||||
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
|
||||
}
|
||||
60
pkg/cloudapi/lb/disable_enable.go
Normal file
60
pkg/cloudapi/lb/disable_enable.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DisableEnableRequest struct for disable/enable load balancer
|
||||
type DisableEnableRequest struct {
|
||||
// ID of the load balancer instance to disable/enable
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// Disable disables specified load balancer instance
|
||||
func (l LB) Disable(ctx context.Context, req DisableEnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/disable"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Enable enables specified load balancer instance
|
||||
func (l LB) Enable(ctx context.Context, req DisableEnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/enable"
|
||||
|
||||
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
|
||||
}
|
||||
91
pkg/cloudapi/lb/filter.go
Normal file
91
pkg/cloudapi/lb/filter.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/pkg/cloudapi/k8s"
|
||||
)
|
||||
|
||||
// FilterByID returns ListLB with specified ID.
|
||||
func (ll ListLB) FilterByID(id uint64) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.ID == id
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListLB with specified Name.
|
||||
func (ll ListLB) FilterByName(name string) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.Name == name
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByExtNetID returns ListLB with specified ExtNetID.
|
||||
func (ll ListLB) FilterByExtNetID(extNetID int64) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.ExtNetID == extNetID
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByImageID returns ListLB with specified ImageID.
|
||||
func (ll ListLB) FilterByImageID(imageID uint64) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.ImageID == imageID
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByK8SID returns ListLB used by specified K8S cluster.
|
||||
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListLB, error) {
|
||||
caller := k8s.New(decortClient)
|
||||
|
||||
req := k8s.GetRequest{
|
||||
K8SID: k8sID,
|
||||
}
|
||||
|
||||
cluster, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return cluster.LBID == ill.ID
|
||||
}
|
||||
|
||||
result := ll.FilterFunc(predicate)
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListLB based on a user-specified predicate.
|
||||
func (ll ListLB) FilterFunc(predicate func(ItemLoadBalancer) bool) ListLB {
|
||||
var result ListLB
|
||||
|
||||
for _, item := range ll.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(ll.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemLoadBalancer
|
||||
// If none was found, returns an empty struct.
|
||||
func (ll ListLB) FindOne() ItemLoadBalancer {
|
||||
if len(ll.Data) == 0 {
|
||||
return ItemLoadBalancer{}
|
||||
}
|
||||
|
||||
return ll.Data[0]
|
||||
}
|
||||
148
pkg/cloudapi/lb/filter_test.go
Normal file
148
pkg/cloudapi/lb/filter_test.go
Normal file
@@ -0,0 +1,148 @@
|
||||
package lb
|
||||
|
||||
import "testing"
|
||||
|
||||
var lbs = ListLB{
|
||||
Data: []ItemLoadBalancer{
|
||||
{
|
||||
DPAPIPassword: "0000",
|
||||
RecordLB: RecordLB{
|
||||
HAMode: true,
|
||||
ACL: []interface{}{},
|
||||
Backends: []ItemBackend{},
|
||||
CreatedBy: "test_user_1",
|
||||
CreatedTime: 1636667448,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DPAPIUser: "api_user",
|
||||
ExtNetID: 2522,
|
||||
Frontends: []ItemFrontend{},
|
||||
GID: 212,
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
ImageID: 2121,
|
||||
Milestones: 129000,
|
||||
Name: "k8s-lb-test-1",
|
||||
RGID: 25090,
|
||||
RGName: "",
|
||||
Status: "ENABLED",
|
||||
TechStatus: "STARTED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINSID: 101,
|
||||
},
|
||||
},
|
||||
{
|
||||
DPAPIPassword: "0000",
|
||||
RecordLB: RecordLB{
|
||||
HAMode: false,
|
||||
ACL: []interface{}{},
|
||||
Backends: []ItemBackend{},
|
||||
CreatedBy: "test_user_2",
|
||||
CreatedTime: 1636667506,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DPAPIUser: "api_user_2",
|
||||
ExtNetID: 2524,
|
||||
Frontends: []ItemFrontend{},
|
||||
GID: 212,
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
ImageID: 2129,
|
||||
Milestones: 129013,
|
||||
Name: "k8s-lb-test-2",
|
||||
RGID: 25092,
|
||||
RGName: "",
|
||||
Status: "ENABLED",
|
||||
TechStatus: "STOPPED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINSID: 102,
|
||||
},
|
||||
},
|
||||
{
|
||||
DPAPIPassword: "0000",
|
||||
RecordLB: RecordLB{
|
||||
HAMode: true,
|
||||
ACL: []interface{}{},
|
||||
Backends: []ItemBackend{},
|
||||
CreatedBy: "te2t_user_3",
|
||||
CreatedTime: 1636667534,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DPAPIUser: "api_user_3",
|
||||
ExtNetID: 2536,
|
||||
Frontends: []ItemFrontend{},
|
||||
GID: 212,
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
ImageID: 2139,
|
||||
Milestones: 129025,
|
||||
Name: "k8s-lb-test-3",
|
||||
RGID: 25106,
|
||||
RGName: "",
|
||||
Status: "DISABLED",
|
||||
TechStatus: "STOPPED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINSID: 118,
|
||||
},
|
||||
},
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := lbs.FilterByID(2).FindOne()
|
||||
|
||||
if actual.ID != 2 {
|
||||
t.Fatal("expected ID 2, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := lbs.FilterByName("k8s-lb-test-3").FindOne()
|
||||
|
||||
if actual.Name != "k8s-lb-test-3" {
|
||||
t.Fatal("expected Name 'k8s-lb-test-3', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByExtNetID(t *testing.T) {
|
||||
actual := lbs.FilterByExtNetID(2522).FindOne()
|
||||
|
||||
if actual.ExtNetID != 2522 {
|
||||
t.Fatal("expected ExtNetID 2522, found: ", actual.ExtNetID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByImageID(t *testing.T) {
|
||||
actual := lbs.FilterByImageID(2139).FindOne()
|
||||
|
||||
if actual.ImageID != 2139 {
|
||||
t.Fatal("expected ImageID 2139, found: ", actual.ImageID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := lbs.FilterFunc(func(rl ItemLoadBalancer) bool {
|
||||
return rl.Status == "DISABLED"
|
||||
})
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "DISABLED" {
|
||||
t.Fatal("expected Status 'DISABLED', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortByCreatedTime(t *testing.T) {
|
||||
actual := lbs.SortByCreatedTime(true)
|
||||
|
||||
if actual.Data[0].CreatedTime != 1636667534 || actual.Data[2].CreatedTime != 1636667448 {
|
||||
t.Fatal("expected descending order, found ascending")
|
||||
}
|
||||
}
|
||||
54
pkg/cloudapi/lb/frontend_bind.go
Normal file
54
pkg/cloudapi/lb/frontend_bind.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// FrontendBindRequest struct for frontend bind
|
||||
type FrontendBindRequest struct {
|
||||
// ID of the load balancer instance to FrontendBind
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Name of the frontend to update
|
||||
// Required: true
|
||||
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
|
||||
|
||||
// Name of the binding to update
|
||||
// Required: true
|
||||
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: 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: true
|
||||
BindingPort uint64 `url:"bindingPort" json:"bindingPort" validate:"required"`
|
||||
}
|
||||
|
||||
// FrontendBind bind frontend from specified load balancer instance
|
||||
func (l LB) FrontendBind(ctx context.Context, req FrontendBindRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/frontendBind"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
43
pkg/cloudapi/lb/frontend_bind_delete.go
Normal file
43
pkg/cloudapi/lb/frontend_bind_delete.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// FrontendBindDeleteRequest struct to delete bind
|
||||
type FrontendBindDeleteRequest struct {
|
||||
// ID of the load balancer instance to FrontendBindDelete
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Name of the frontend to delete
|
||||
// Required: true
|
||||
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
|
||||
|
||||
// Name of the binding to delete
|
||||
// Required: true
|
||||
BindingName string `url:"bindingName" json:"bindingName" validate:"required"`
|
||||
}
|
||||
|
||||
// FrontendBindDelete deletes binding from the specified load balancer frontend
|
||||
func (l LB) FrontendBindDelete(ctx context.Context, req FrontendBindDeleteRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/frontendBindDelete"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
54
pkg/cloudapi/lb/frontend_bind_update.go
Normal file
54
pkg/cloudapi/lb/frontend_bind_update.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// FrontendBindUpdateRequest struct to update binding
|
||||
type FrontendBindUpdateRequest struct {
|
||||
// ID of the load balancer instance to FrontendBindUpdate
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Name of the frontend to update
|
||||
// Required: true
|
||||
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
|
||||
|
||||
// Name of the binding to update
|
||||
// Required: true
|
||||
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: 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: true
|
||||
BindingPort uint64 `url:"bindingPort" json:"bindingPort" validate:"required"`
|
||||
}
|
||||
|
||||
// FrontendBindUpdate updates binding for the specified load balancer frontend
|
||||
func (l LB) FrontendBindUpdate(ctx context.Context, req FrontendBindUpdateRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/frontendBindingUpdate"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
48
pkg/cloudapi/lb/frontend_create.go
Normal file
48
pkg/cloudapi/lb/frontend_create.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// FrontendCreateRequest struct to create frontend
|
||||
type FrontendCreateRequest struct {
|
||||
// ID of the load balancer instance to FrontendCreate
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must be unique among all frontends of
|
||||
// this load balancer - name of the new frontend to create
|
||||
// Required: true
|
||||
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
|
||||
|
||||
// Should be one of the backends existing on
|
||||
// this load balancer - name of the backend to use
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
}
|
||||
|
||||
// FrontendCreate creates new frontend on the specified load balancer
|
||||
func (l LB) FrontendCreate(ctx context.Context, req FrontendCreateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/frontendCreate"
|
||||
|
||||
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
|
||||
}
|
||||
43
pkg/cloudapi/lb/frontend_delete.go
Normal file
43
pkg/cloudapi/lb/frontend_delete.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// FrontendDeleteRequest struct to delete frontend
|
||||
type FrontendDeleteRequest struct {
|
||||
// ID of the load balancer instance to FrontendDelete
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Name of the frontend to delete
|
||||
// Required: true
|
||||
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
|
||||
}
|
||||
|
||||
// FrontendDelete deletes frontend from the specified load balancer.
|
||||
// Warning: you cannot undo this action!
|
||||
func (l LB) FrontendDelete(ctx context.Context, req FrontendDeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/frontendDelete"
|
||||
|
||||
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
|
||||
}
|
||||
46
pkg/cloudapi/lb/get.go
Normal file
46
pkg/cloudapi/lb/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get detailed information about load balancer
|
||||
type GetRequest struct {
|
||||
// ID of the load balancer to get details for
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets detailed information about load balancer as a RecordLB struct
|
||||
func (l LB) Get(ctx context.Context, req GetRequest) (*RecordLB, error) {
|
||||
res, err := l.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordLB{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets detailed information about load balancer as an array of bytes
|
||||
func (l LB) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/get"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
10
pkg/cloudapi/lb/ids.go
Normal file
10
pkg/cloudapi/lb/ids.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package lb
|
||||
|
||||
// IDs gets array of LBIDs from ListLB struct
|
||||
func (llb ListLB) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(llb.Data))
|
||||
for _, lb := range llb.Data {
|
||||
res = append(res, lb.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
18
pkg/cloudapi/lb/lb.go
Normal file
18
pkg/cloudapi/lb/lb.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// API to manage load balancer instance
|
||||
package lb
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to load balancer
|
||||
type LB struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for load balancer
|
||||
func New(client interfaces.Caller) *LB {
|
||||
return &LB{
|
||||
client,
|
||||
}
|
||||
}
|
||||
91
pkg/cloudapi/lb/list.go
Normal file
91
pkg/cloudapi/lb/list.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of load balancers
|
||||
type ListRequest struct {
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by resource group ID
|
||||
// Required: false
|
||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||
|
||||
// Find by tech status
|
||||
// Required: false
|
||||
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by frontend Ip
|
||||
// Required: false
|
||||
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
|
||||
|
||||
// Find by backend Ip
|
||||
// Required: false
|
||||
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
|
||||
|
||||
// Included deleted load balancers
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of all load balancers as a ListLB struct
|
||||
func (l LB) List(ctx context.Context, req ListRequest) (*ListLB, error) {
|
||||
|
||||
res, err := l.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListLB{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of all load balancers as an array of bytes
|
||||
func (l LB) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/list"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
76
pkg/cloudapi/lb/list_deleted.go
Normal file
76
pkg/cloudapi/lb/list_deleted.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListDeletedRequest struct to get list of deleted load balancers
|
||||
type ListDeletedRequest struct {
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by resource group ID
|
||||
// Required: false
|
||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||
|
||||
// Find by tech status
|
||||
// Required: false
|
||||
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||
|
||||
// Find by frontend Ip
|
||||
// Required: false
|
||||
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
|
||||
|
||||
// Find by backend Ip
|
||||
// Required: false
|
||||
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: true
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListDeleted gets list of deleted load balancers
|
||||
func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListLB, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/listDeleted"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListLB{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
38
pkg/cloudapi/lb/make_highly_available.go
Normal file
38
pkg/cloudapi/lb/make_highly_available.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// HighlyAvailableRequest struct to make Load Balancer Highly available
|
||||
type HighlyAvailableRequest struct {
|
||||
// ID of the LB instance
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// HighlyAvailable makes load balancer highly available
|
||||
func (l LB) HighlyAvailable(ctx context.Context, req HighlyAvailableRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
253
pkg/cloudapi/lb/models.go
Normal file
253
pkg/cloudapi/lb/models.go
Normal file
@@ -0,0 +1,253 @@
|
||||
package lb
|
||||
|
||||
// Detailed information about load balancer
|
||||
type RecordLB struct {
|
||||
//HAMode
|
||||
HAMode bool `json:"HAmode"`
|
||||
|
||||
// Access Control List
|
||||
ACL interface{} `json:"acl"`
|
||||
|
||||
// BackendHAIP
|
||||
BackendHAIP string `json:"backendHAIP"`
|
||||
|
||||
// List of load balancer backends
|
||||
Backends ListBackends `json:"backends"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// DPAPIUser
|
||||
DPAPIUser string `json:"dpApiUser"`
|
||||
|
||||
// External network ID
|
||||
ExtNetID int64 `json:"extnetId"`
|
||||
|
||||
// FrontendHAIP
|
||||
FrontendHAIP string `json:"frontendHAIP"`
|
||||
|
||||
// List of load balancer frontends
|
||||
Frontends ListFrontends `json:"frontends"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// ManagerId
|
||||
ManagerId uint64 `json:"managerId"`
|
||||
|
||||
// ManagerType
|
||||
ManagerType string `json:"managerType"`
|
||||
|
||||
// Image ID
|
||||
ImageID uint64 `json:"imageId"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Part K8s
|
||||
PartK8s bool `json:"partK8s"`
|
||||
|
||||
// Primary node
|
||||
PrimaryNode RecordNode `json:"primaryNode"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// Secondary node
|
||||
SecondaryNode RecordNode `json:"secondaryNode"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Sysctl Params
|
||||
SysctlParams interface{} `json:"sysctlParams"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// UserManaged
|
||||
UserManaged bool `json:"userManaged"`
|
||||
|
||||
// VINS ID
|
||||
VINSID uint64 `json:"vinsId"`
|
||||
}
|
||||
|
||||
// Main information about load balancer
|
||||
type ItemLoadBalancer struct {
|
||||
// DPAPIPassword
|
||||
DPAPIPassword string `json:"dpApiPassword"`
|
||||
// Detailed information about load balancer
|
||||
RecordLB
|
||||
}
|
||||
|
||||
// List of load balancers
|
||||
type ListLB struct {
|
||||
// Data
|
||||
Data []ItemLoadBalancer `json:"data"`
|
||||
|
||||
// EntryCount
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about backend
|
||||
type ItemBackend struct {
|
||||
// Algorithm
|
||||
Algorithm string `json:"algorithm"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Server settings
|
||||
ServerDefaultSettings RecordServerSettings `json:"serverDefaultSettings"`
|
||||
|
||||
// List of servers
|
||||
Servers ListServers `json:"servers"`
|
||||
}
|
||||
|
||||
// List of backends
|
||||
type ListBackends []ItemBackend
|
||||
|
||||
// Server settings
|
||||
type RecordServerSettings struct {
|
||||
// Inter
|
||||
Inter uint64 `json:"inter"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// DownInter
|
||||
DownInter uint64 `json:"downinter"`
|
||||
|
||||
// Rise
|
||||
Rise uint64 `json:"rise"`
|
||||
|
||||
// Fall
|
||||
Fall uint64 `json:"fall"`
|
||||
|
||||
// SlowStart
|
||||
SlowStart uint64 `json:"slowstart"`
|
||||
|
||||
// Max connections
|
||||
MaxConn uint64 `json:"maxconn"`
|
||||
|
||||
// Max queue
|
||||
MaxQueue uint64 `json:"maxqueue"`
|
||||
|
||||
// Weight
|
||||
Weight uint64 `json:"weight"`
|
||||
}
|
||||
|
||||
// Main information about server
|
||||
type ItemServer struct {
|
||||
|
||||
// Address
|
||||
Address string `json:"address"`
|
||||
|
||||
// Check
|
||||
Check string `json:"check"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Port
|
||||
Port uint64 `json:"port"`
|
||||
|
||||
// Server settings
|
||||
ServerSettings RecordServerSettings `json:"serverSettings"`
|
||||
}
|
||||
|
||||
// List of servers
|
||||
type ListServers []ItemServer
|
||||
|
||||
// Main information about node
|
||||
type RecordNode struct {
|
||||
// Backend IP
|
||||
BackendIP string `json:"backendIp"`
|
||||
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
// Frontend IP
|
||||
FrontendIP string `json:"frontendIp"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// MGMTIP
|
||||
MGMTIP string `json:"mgmtIp"`
|
||||
|
||||
// Network ID
|
||||
NetworkID uint64 `json:"networkId"`
|
||||
}
|
||||
|
||||
// Main information about frontend
|
||||
type ItemFrontend struct {
|
||||
// Backend
|
||||
Backend string `json:"backend"`
|
||||
|
||||
// List of bindings
|
||||
Bindings ListBindings `json:"bindings"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// List of frontends
|
||||
type ListFrontends []ItemFrontend
|
||||
|
||||
// Main information about bindings
|
||||
type ItemBinding struct {
|
||||
// Address
|
||||
Address string `json:"address"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Port
|
||||
Port uint64 `json:"port"`
|
||||
}
|
||||
|
||||
// List of bindings
|
||||
type ListBindings []ItemBinding
|
||||
43
pkg/cloudapi/lb/restart.go
Normal file
43
pkg/cloudapi/lb/restart.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// RestartRequest struct to restart load balancer
|
||||
type RestartRequest struct {
|
||||
// ID of the load balancer instance to restart
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// restart secondary and primary nodes sequentially in HA mode
|
||||
// Default is true
|
||||
// Required: false
|
||||
Safe bool `url:"safe" json:"safe"`
|
||||
}
|
||||
|
||||
// Restart restarts specified load balancer instance
|
||||
func (l LB) Restart(ctx context.Context, req RestartRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/restart"
|
||||
|
||||
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
|
||||
}
|
||||
38
pkg/cloudapi/lb/restore.go
Normal file
38
pkg/cloudapi/lb/restore.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// RestoreRequest struct to restore load balancer
|
||||
type RestoreRequest struct {
|
||||
// ID of the load balancer instance to restore
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// Restore restores load balancer from recycle bin
|
||||
func (l LB) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/restore"
|
||||
|
||||
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
|
||||
}
|
||||
43
pkg/cloudapi/lb/serialize.go
Normal file
43
pkg/cloudapi/lb/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ll ListLB) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(ll.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ll, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ll)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ill ItemLoadBalancer) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ill, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ill)
|
||||
}
|
||||
60
pkg/cloudapi/lb/sorting.go
Normal file
60
pkg/cloudapi/lb/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package lb
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListLB by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
|
||||
if len(ll.Data) < 2 {
|
||||
return ll
|
||||
}
|
||||
|
||||
sort.Slice(ll.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ll.Data[i].CreatedTime > ll.Data[j].CreatedTime
|
||||
}
|
||||
|
||||
return ll.Data[i].CreatedTime < ll.Data[j].CreatedTime
|
||||
})
|
||||
|
||||
return ll
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListLB by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
|
||||
if len(ll.Data) < 2 {
|
||||
return ll
|
||||
}
|
||||
|
||||
sort.Slice(ll.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ll.Data[i].UpdatedTime > ll.Data[j].UpdatedTime
|
||||
}
|
||||
|
||||
return ll.Data[i].UpdatedTime < ll.Data[j].UpdatedTime
|
||||
})
|
||||
|
||||
return ll
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListLB by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ll ListLB) SortByDeletedTime(inverse bool) ListLB {
|
||||
if len(ll.Data) < 2 {
|
||||
return ll
|
||||
}
|
||||
|
||||
sort.Slice(ll.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ll.Data[i].DeletedTime > ll.Data[j].DeletedTime
|
||||
}
|
||||
|
||||
return ll.Data[i].DeletedTime < ll.Data[j].DeletedTime
|
||||
})
|
||||
|
||||
return ll
|
||||
}
|
||||
38
pkg/cloudapi/lb/start.go
Normal file
38
pkg/cloudapi/lb/start.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// StartRequest struct to start load balancer
|
||||
type StartRequest struct {
|
||||
// ID of the load balancer instance to start
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// Start starts specified load balancer instance
|
||||
func (l LB) Start(ctx context.Context, req StartRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/start"
|
||||
|
||||
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
|
||||
}
|
||||
38
pkg/cloudapi/lb/stop.go
Normal file
38
pkg/cloudapi/lb/stop.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// StopRequest struct to stop load balancer
|
||||
type StopRequest struct {
|
||||
// ID of the load balancer instance to stop
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// Stop stops specified load balancer instance
|
||||
func (l LB) Stop(ctx context.Context, req StopRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/stop"
|
||||
|
||||
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
|
||||
}
|
||||
43
pkg/cloudapi/lb/update.go
Normal file
43
pkg/cloudapi/lb/update.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// UpdateRequest struct to update load balancer
|
||||
type UpdateRequest struct {
|
||||
// ID of the load balancer to update
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// New description of this load balancer.
|
||||
// If omitted, current description is retained
|
||||
// Required: true
|
||||
Description string `url:"desc" json:"desc" validate:"required"`
|
||||
}
|
||||
|
||||
// Update updates some of load balancer attributes
|
||||
func (l LB) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/update"
|
||||
|
||||
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
|
||||
}
|
||||
68
pkg/cloudapi/lb/update_sysctl_params.go
Normal file
68
pkg/cloudapi/lb/update_sysctl_params.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// UpdateSysctParamsRequest struct to 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 []map[string]interface{} `url:"-" json:"sysctlParams" validate:"required,dive"`
|
||||
}
|
||||
|
||||
type wrapperUpdateSysctParamsRequest struct {
|
||||
UpdateSysctParamsRequest
|
||||
Params []string `url:"sysctlParams" validate:"required"`
|
||||
}
|
||||
|
||||
// UpdateSysctParams updates sysct paarams for lb
|
||||
func (l LB) UpdateSysctlParams(ctx context.Context, req UpdateSysctParamsRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
var params []string
|
||||
|
||||
if len(req.SysctlParams) != 0 {
|
||||
params = make([]string, 0, len(req.SysctlParams))
|
||||
for _, m := range req.SysctlParams {
|
||||
encodeStr, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
params = append(params, string(encodeStr))
|
||||
}
|
||||
} else {
|
||||
params = []string{}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperUpdateSysctParamsRequest{
|
||||
UpdateSysctParamsRequest: req,
|
||||
Params: params,
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/updateSysctlParams"
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user