This commit is contained in:
stSolo
2022-12-22 17:56:47 +03:00
parent 8712561853
commit d4b1ab7133
672 changed files with 28509 additions and 4419 deletions

View File

@@ -0,0 +1,106 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for create backend
type BackendCreateRequest struct {
// ID of the load balancer instance to backendCreate
// Required: true
LBID uint64 `url:"lbId"`
// Must be unique among all backends of this load balancer - name of the new backend to create
// Required: true
BackendName string `url:"backendName"`
// Algorithm
// Should be one of:
// - roundrobin
// - static-rr
// - leastconn
// Required: false
Algorithm string `url:"algorithm,omitempty"`
// Interval in milliseconds between two consecutive availability
// checks of the server that is considered available
// Required: false
Inter uint64 `url:"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"`
// 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"`
// 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"`
// 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"`
// 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"`
// 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"`
// Server weight for use in weight balancing algorithms
// Required: false
Weight uint64 `url:"weight,omitempty"`
}
func (lbrq BackendCreateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName must be set")
}
validate := validators.StringInSlice(lbrq.Algorithm, []string{"roundrobin", "static-rr", "leastconn"})
if !validate {
return errors.New("validation-error: field Algorithm must be one of roundrobin, static-rr, leastconn")
}
return nil
}
// BackendCreate creates new backend on the specified load balancer
func (lb LB) BackendCreate(ctx context.Context, req BackendCreateRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/backendCreate"
res, err := lb.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
}

View File

@@ -0,0 +1,53 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for delete backend
type BackendDeleteRequest struct {
// ID of the load balancer instance to BackendDelete
// Required: true
LBID uint64 `url:"lbId"`
// Cannot be emtpy string - name of the backend to delete
// Required: true
BackendName string `url:"backendName"`
}
func (lbrq BackendDeleteRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName must be set")
}
return nil
}
// BackendDelete deletes backend from the specified load balancer.
// Warning: you cannot undo this action!
func (lb LB) BackendDelete(ctx context.Context, req BackendDeleteRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/backendDelete"
res, err := lb.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
}

View File

@@ -0,0 +1,114 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for add server definition to the backend
type BackendServerAddRequest struct {
// ID of the load balancer instance to BackendServerAdd
// Required: true
LBID uint64 `url:"lbId"`
// Must match one of the existing backens - name of the backend to add servers to
// Required: true
BackendName string `url:"backendName"`
// Must be unique among all servers defined for this backend - name of the server definition to add
// Required: true
ServerName string `url:"serverName"`
// IP address of the server
// Required: true
Address string `url:"address"`
// Port number on the server
// Required: true
Port uint64 `url:"port"`
// Set to disabled if this server should be used regardless of its state
// Required: false
Check string `url:"check,omitempty"`
// Interval in milliseconds between two consecutive availability checks of the server that is considered available
// Required: false
Inter uint64 `url:"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"`
// 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"`
// 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"`
// 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"`
// 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"`
// 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"`
// Server weight for use in weight balancing algorithms
// Required: false
Weight uint64 `url:"weight,omitempty"`
}
func (lbrq BackendServerAddRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName must be set")
}
if lbrq.ServerName == "" {
return errors.New("validation-error: field ServerName must be set")
}
if lbrq.Address == "" {
return errors.New("validation-error: field Address must be set")
}
if lbrq.Port == 0 {
return errors.New("validation-error: field Port must be set")
}
return nil
}
// BackendServerAdd adds server definition to the backend on the specified load balancer
func (lb LB) BackendServerAdd(ctx context.Context, req BackendServerAddRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/backendServerAdd"
res, err := lb.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
}

View File

@@ -0,0 +1,62 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for delete server definition
type BackendServerDeleteRequest struct {
// ID of the load balancer instance to BackendServerDelete
// Required: true
LBID uint64 `url:"lbId"`
// Must match one of the existing backens - name of the backend to add servers to
// Required: true
BackendName string `url:"backendName"`
// Must be unique among all servers defined for this backend - name of the server definition to add
// Required: true
ServerName string `url:"serverName"`
}
func (lbrq BackendServerDeleteRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName must be set")
}
if lbrq.ServerName == "" {
return errors.New("validation-error: field ServerName must be set")
}
return nil
}
// BackendServerDelete deletes server definition from the backend on the specified load balancer.
// Warning: you cannot undo this action!
func (lb LB) BackendServerDelete(ctx context.Context, req BackendServerDeleteRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/backendServerDelete"
res, err := lb.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
}

View File

@@ -0,0 +1,114 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for update server
type BackendServerUpdateRequest struct {
// ID of the load balancer instance to BackendServerAdd
// Required: true
LBID uint64 `url:"lbId"`
// Must match one of the existing backens - name of the backend to add servers to
// Required: true
BackendName string `url:"backendName"`
// Must be unique among all servers defined for this backend - name of the server definition to add
// Required: true
ServerName string `url:"serverName"`
// IP address of the server
// Required: true
Address string `url:"address"`
// Port number on the server
// Required: true
Port uint64 `url:"port"`
// Set to disabled if this server should be used regardless of its state
// Required: false
Check string `url:"check,omitempty"`
// Interval in milliseconds between two consecutive availability checks of the server that is considered available
// Required: false
Inter uint64 `url:"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"`
// 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"`
// 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"`
// 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"`
// 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"`
// 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"`
// Server weight for use in weight balancing algorithms
// Required: false
Weight uint64 `url:"weight,omitempty"`
}
func (lbrq BackendServerUpdateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName must be set")
}
if lbrq.ServerName == "" {
return errors.New("validation-error: field ServerName must be set")
}
if lbrq.Address == "" {
return errors.New("validation-error: field Address must be set")
}
if lbrq.Port == 0 {
return errors.New("validation-error: field Port must be set")
}
return nil
}
// BackendServerUpdate updates server definition on the backend of load balancer
func (lb LB) BackendServerUpdate(ctx context.Context, req BackendServerUpdateRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/backendServerUpdate"
res, err := lb.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
}

View File

@@ -0,0 +1,100 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for update backend
type BackendUpdateRequest struct {
// ID of the load balancer instance to backendCreate
// Required: true
LBID uint64 `url:"lbId"`
// Must be unique among all backends of this load balancer - name of the new backend to create
// Required: true
BackendName string `url:"backendName"`
// Algorithm
// Should be one of:
// - roundrobin
// - static-rr
// - leastconn
// Required: false
Algorithm string `url:"algorithm,omitempty"`
// Interval in milliseconds between two consecutive availability
// checks of the server that is considered available
// Required: false
Inter uint64 `url:"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"`
// 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"`
// 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"`
// 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"`
// 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"`
// 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"`
// Server weight for use in weight balancing algorithms
// Required: false
Weight uint64 `url:"weight,omitempty"`
}
func (lbrq BackendUpdateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName must be set")
}
return nil
}
// BackendUpdate updates existing backend on the specified load balancer. Note that backend name cannot be changed
func (lb LB) BackendUpdate(ctx context.Context, req BackendUpdateRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/backendUpdate"
res, err := lb.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
}

View File

@@ -0,0 +1,46 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for reset config
type ConfigResetRequest struct {
// ID of the load balancer instance to ConfigReset
// Required: true
LBID uint64 `url:"lbId"`
}
func (lbrq ConfigResetRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
return nil
}
// ConfigReset reset current software configuration of the specified load balancer.
// Warning: this action cannot be undone!
func (lb LB) ConfigReset(ctx context.Context, req ConfigResetRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/configReset"
res, err := lb.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
}

View File

@@ -0,0 +1,79 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for 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"`
// Name of the load balancer.
// Must be unique among all load balancers in this resource group
// Required: true
Name string `url:"name"`
// OS image ID to create load balancer from
// Required: false
ImageID uint64 `url:"imageId,omitempty"`
// External network to connect this load balancer to
// Required: true
ExtNetID uint64 `url:"extnetId"`
// Internal network (VINS) to connect this load balancer to
// Required: true
VINSID uint64 `url:"vinsId"`
// Start now Load balancer
// Required: false
Start bool `url:"start"`
// Text description of this load balancer
// Required: false
Description string `url:"desc,omitempty"`
}
func (lbrq CreateRequest) validate() error {
if lbrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if lbrq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
if lbrq.ExtNetID == 0 {
return errors.New("validation-error: field ExtNetID must be set")
}
if lbrq.VINSID == 0 {
return errors.New("validation-error: field VINSID must be set")
}
return nil
}
// Create method will create a new load balancer instance
func (lb LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/lb/create"
res, err := lb.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

@@ -0,0 +1,49 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for delete load balancer
type DeleteRequest struct {
// ID of the load balancer instance to delete
// Required: true
LBID uint64 `url:"lbId"`
// Set to true to delete load balancer immediately bypassing recycle bin
// Required: false
Permanently bool `url:"permanently,omitempty"`
}
func (lbrq DeleteRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
return nil
}
// Delete deletes specified load balancer
func (lb LB) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/delete"
res, err := lb.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
}

View File

@@ -0,0 +1,45 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for disable load balancer
type DisableRequest struct {
// ID of the load balancer instance to disable
// Required: true
LBID uint64 `url:"lbId"`
}
func (lbrq DisableRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
return nil
}
// Disable disables specified load balancer instance
func (lb LB) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/disable"
res, err := lb.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
}

View File

@@ -0,0 +1,45 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for enable load balancer
type EnableRequest struct {
// ID of the load balancer instance to enable
// Required: true
LBID uint64 `url:"lbId"`
}
func (lbrq EnableRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
return nil
}
// Enable enables specified load balancer instance
func (lb LB) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/enable"
res, err := lb.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
}

View File

@@ -0,0 +1,76 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for frontend bind
type FrontendBindRequest struct {
// ID of the load balancer instance to FrontendBind
// Required: true
LBID uint64 `url:"lbId"`
// Name of the frontend to update
// Required: true
FrontendName string `url:"frontendName"`
// Name of the binding to update
// Required: true
BindingName string `url:"bindingName"`
// 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"`
// New port number to use for this binding.
// If omitted, current port number is retained
// Required: false
BindingPort uint64 `url:"bindingPort,omitempty"`
}
func (lbrq FrontendBindRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.FrontendName == "" {
return errors.New("validation-error: field FrontendName must be set")
}
if lbrq.BindingName == "" {
return errors.New("validation-error: field BindingName must be set")
}
if lbrq.BindingAddress == "" {
return errors.New("validation-error: field BindingAddress must be set")
}
if lbrq.BindingPort == 0 {
return errors.New("validation-error: field BindingPort must be set")
}
return nil
}
// FrontendBind bind frontend from specified load balancer instance
func (lb LB) FrontendBind(ctx context.Context, req FrontendBindRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/frontendBind"
res, err := lb.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
}

View File

@@ -0,0 +1,59 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for delete bind
type FrontendBindDeleteRequest struct {
// ID of the load balancer instance to FrontendBindDelete
// Required: true
LBID uint64 `url:"lbId"`
// Name of the frontend to delete
// Required: true
FrontendName string `url:"frontendName"`
// Name of the binding to delete
// Required: true
BindingName string `url:"bindingName"`
}
func (lbrq FrontendBindDeleteRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.FrontendName == "" {
return errors.New("validation-error: field FrontendName must be set")
}
if lbrq.BindingName == "" {
return errors.New("validation-error: field BindingName must be set")
}
return nil
}
// FrontendBindDelete deletes binding from the specified load balancer frontend
func (lb LB) FrontendBindDelete(ctx context.Context, req FrontendBindDeleteRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/frontendBindDelete"
res, err := lb.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
}

View File

@@ -0,0 +1,76 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for update binding
type FrontendBindUpdateRequest struct {
// ID of the load balancer instance to FrontendBindUpdate
// Required: true
LBID uint64 `url:"lbId"`
// Name of the frontend to update
// Required: true
FrontendName string `url:"frontendName"`
// Name of the binding to update
// Required: true
BindingName string `url:"bindingName"`
// 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"`
// New port number to use for this binding.
// If omitted, current port number is retained
// Required: false
BindingPort uint64 `url:"bindingPort,omitempty"`
}
func (lbrq FrontendBindUpdateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.FrontendName == "" {
return errors.New("validation-error: field FrontendName must be set")
}
if lbrq.BindingName == "" {
return errors.New("validation-error: field BindingName must be set")
}
if lbrq.BindingAddress == "" {
return errors.New("validation-error: field BindingAddress must be set")
}
if lbrq.BindingPort == 0 {
return errors.New("validation-error: field BindingPort must be set")
}
return nil
}
// FrontendBindUpdate updates binding for the specified load balancer frontend
func (lb LB) FrontendBindUpdate(ctx context.Context, req FrontendBindUpdateRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/frontendBindingUpdate"
res, err := lb.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
}

View File

@@ -0,0 +1,61 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for create frontend
type FrontendCreateRequest struct {
// ID of the load balancer instance to FrontendCreate
// Required: true
LBID uint64 `url:"lbId"`
// Must be unique among all frontends of
// this load balancer - name of the new frontend to create
// Required: true
FrontendName string `url:"frontendName"`
// Should be one of the backends existing on
// this load balancer - name of the backend to use
// Required: true
BackendName string `url:"backendName"`
}
func (lbrq FrontendCreateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.FrontendName == "" {
return errors.New("validation-error: field FrontendName must be set")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName must be set")
}
return nil
}
// FrontendCreate creates new frontend on the specified load balancer
func (l LB) FrontendCreate(ctx context.Context, req FrontendCreateRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/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
}

View File

@@ -0,0 +1,53 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for delete frontend
type FrontendDeleteRequest struct {
// ID of the load balancer instance to FrontendDelete
// Required: true
LBID uint64 `url:"lbId"`
// Name of the frontend to delete
// Required: true
FrontendName string `url:"frontendName"`
}
func (lbrq FrontendDeleteRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.FrontendName == "" {
return errors.New("validation-error: field FrontendName must be set")
}
return nil
}
// FrontendDelete deletes frontend from the specified load balancer.
// Warning: you cannot undo this action!
func (lb LB) FrontendDelete(ctx context.Context, req FrontendDeleteRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/frontendDelete"
res, err := lb.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/cloudbroker/lb/get.go Normal file
View File

@@ -0,0 +1,47 @@
package lb
import (
"context"
"encoding/json"
"errors"
"net/http"
)
// Request struct for get detailed information about load balancer
type GetRequest struct {
// ID of the load balancer to get details for
// Required: true
LBID uint64 `url:"lbId"`
}
func (lbrq GetRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
return nil
}
// Get gets detailed information about load balancer
func (lb LB) Get(ctx context.Context, req GetRequest) (*RecordLB, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/lb/get"
res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := RecordLB{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

16
pkg/cloudbroker/lb/lb.go Normal file
View File

@@ -0,0 +1,16 @@
// API to manage load balancer instance
package lb
import "github.com/rudecs/decort-sdk/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: client,
}
}

View File

@@ -0,0 +1,42 @@
package lb
import (
"context"
"encoding/json"
"net/http"
)
// Request struct for get list of load balancers
type ListRequest struct {
// Included deleted load balancers
// Required: false
IncludeDeleted bool `url:"includedeleted,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
// List gets list all load balancers
func (lb LB) List(ctx context.Context, req ListRequest) (ListLB, error) {
url := "/cloudbroker/lb/list"
res, err := lb.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
}

View File

@@ -0,0 +1,38 @@
package lb
import (
"context"
"encoding/json"
"net/http"
)
// Request struct for get list of deleted load balancers
type ListDeletedRequest struct {
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: true
Size uint64 `url:"size,omitempty"`
}
// ListDeleted gets list of deleted load balancers
func (lb LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListLB, error) {
url := "/cloudbroker/lb/listDeleted"
res, err := lb.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
}

View File

@@ -0,0 +1,227 @@
package lb
// Server settings
type ServerSettings 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 ServerSettings `json:"serverSettings"`
}
// List of servers
type ListServers []ItemServer
// 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 ServerSettings `json:"serverDefaultSettings"`
// List of servers
Servers ListServers `json:"servers"`
}
// List of backends
type ListBackends []ItemBackend
// 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
// Main information about node
type Node 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"`
}
// List of load balancers
type ListLB []RecordLB
// Detailed information about load balancer
type RecordLB struct {
// HAMode
HAMode bool `json:"HAmode"`
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// Access Control List
ACL []interface{} `json:"acl"`
// 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"`
// DPAPI password
DPAPIPassword string `json:"dpApiPassword"`
// DPAPI user
DPAPIUser string `json:"dpApiUser"`
// External network ID
ExtNetID uint64 `json:"extnetId"`
// 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"`
// Image ID
ImageID uint64 `json:"imageId"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Primary node
PrimaryNode Node `json:"primaryNode"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group name
RGName string `json:"rgName"`
// Secondary node
SecondaryNode Node `json:"secondaryNode"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// VINS ID
VINSID uint64 `json:"vinsId"`
}

View File

@@ -0,0 +1,45 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for restart load balancer
type RestartRequest struct {
// ID of the load balancer instance to restart
// Required: true
LBID uint64 `url:"lbId"`
}
func (lbrq RestartRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
return nil
}
// Restart restarts specified load balancer instance
func (lb LB) Restart(ctx context.Context, req RestartRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/restart"
res, err := lb.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
}

View File

@@ -0,0 +1,45 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for restore load balancer
type RestoreRequest struct {
// ID of the load balancer instance to restore
// Required: true
LBID uint64 `url:"lbId"`
}
func (lbrq RestoreRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
return nil
}
// Restore restore load balancer from recycle bin
func (lb LB) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/restore"
res, err := lb.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
}

View File

@@ -0,0 +1,45 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for start load balancer
type StartRequest struct {
// ID of the LB instance to start
// Required: true
LBID uint64 `url:"lbId"`
}
func (lbrq StartRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
return nil
}
// Start starts specified load balancer instance
func (lb LB) Start(ctx context.Context, req StartRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/start"
res, err := lb.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
}

View File

@@ -0,0 +1,45 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for stop load balancer
type StopRequest struct {
// ID of the LB instance to stop
// Required: true
LBID uint64 `url:"lbId"`
}
func (lbrq StopRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
return nil
}
// Stop stops specified load balancer instance
func (lb LB) Stop(ctx context.Context, req StopRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/stop"
res, err := lb.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
}

View File

@@ -0,0 +1,53 @@
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for update load balancer
type UpdateRequest struct {
// ID of the load balancer to update
// Required: true
LBID uint64 `url:"lbId"`
// New description of this load balancer.
// If omitted, current description is retained
// Required: true
Description string `url:"desc"`
}
func (lbrq UpdateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID must be set")
}
if lbrq.Description == "" {
return errors.New("validation-error: field Description must be set")
}
return nil
}
// Update updates some of load balancer attributes
func (lb LB) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/lb/update"
res, err := lb.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
}