Refactoring
This commit is contained in:
66
pkg/cloudapi/lb/backend_create.go
Normal file
66
pkg/cloudapi/lb/backend_create.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type BackendCreateRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
BackendName string `url:"backendName"`
|
||||
Algorithm string `url:"algorithm,omitempty"`
|
||||
Inter uint64 `url:"inter,omitempty"`
|
||||
DownInter uint64 `url:"downinter,omitempty"`
|
||||
Rise uint `url:"rise,omitempty"`
|
||||
Fall uint `url:"fall,omitempty"`
|
||||
SlowStart uint64 `url:"slowstart,omitempty"`
|
||||
MaxConn uint `url:"maxconn,omitempty"`
|
||||
MaxQueue uint `url:"maxqueue,omitempty"`
|
||||
Weight uint `url:"weight,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq BackendCreateRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) BackendCreate(ctx context.Context, req BackendCreateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/backendCreate"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
57
pkg/cloudapi/lb/backend_delete.go
Normal file
57
pkg/cloudapi/lb/backend_delete.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type BackendDeleteRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
BackendName string `url:"backendName"`
|
||||
}
|
||||
|
||||
func (lbrq BackendDeleteRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) BackendDelete(ctx context.Context, req BackendDeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/backendDelete"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
81
pkg/cloudapi/lb/backend_server_add.go
Normal file
81
pkg/cloudapi/lb/backend_server_add.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type BackendServerAddRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
BackendName string `url:"backendName"`
|
||||
ServerName string `url:"serverName"`
|
||||
Address string `url:"address"`
|
||||
Port uint `url:"port"`
|
||||
Check string `url:"check,omitempty"`
|
||||
Inter uint64 `url:"inter,omitempty"`
|
||||
DownInter uint64 `url:"downinter,omitempty"`
|
||||
Rise uint `url:"rise,omitempty"`
|
||||
Fall uint `url:"fall,omitempty"`
|
||||
SlowStart uint64 `url:"slowstart,omitempty"`
|
||||
MaxConn uint `url:"maxconn,omitempty"`
|
||||
MaxQueue uint `url:"maxqueue,omitempty"`
|
||||
Weight uint `url:"weight,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq BackendServerAddRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.ServerName == "" {
|
||||
return errors.New("validation-error: field ServerName can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.Address == "" {
|
||||
return errors.New("validation-error: field Address can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.Port == 0 {
|
||||
return errors.New("validation-error: field Port can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) BackendServerAdd(ctx context.Context, req BackendServerAddRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/backendServerAdd"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
62
pkg/cloudapi/lb/backend_server_delete.go
Normal file
62
pkg/cloudapi/lb/backend_server_delete.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type BackendServerDeleteRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
BackendName string `url:"backendName"`
|
||||
ServerName string `url:"serverName"`
|
||||
}
|
||||
|
||||
func (lbrq BackendServerDeleteRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.ServerName == "" {
|
||||
return errors.New("validation-error: field ServerName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) BackendServerDelete(ctx context.Context, req BackendServerDeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/backendServerDelete"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
81
pkg/cloudapi/lb/backend_server_update.go
Normal file
81
pkg/cloudapi/lb/backend_server_update.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type BackendServerUpdateRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
BackendName string `url:"backendName"`
|
||||
ServerName string `url:"serverName"`
|
||||
Address string `url:"address"`
|
||||
Port uint `url:"port"`
|
||||
Check string `url:"check,omitempty"`
|
||||
Inter uint64 `url:"inter,omitempty"`
|
||||
DownInter uint64 `url:"downinter,omitempty"`
|
||||
Rise uint `url:"rise,omitempty"`
|
||||
Fall uint `url:"fall,omitempty"`
|
||||
SlowStart uint64 `url:"slowstart,omitempty"`
|
||||
MaxConn uint `url:"maxconn,omitempty"`
|
||||
MaxQueue uint `url:"maxqueue,omitempty"`
|
||||
Weight uint `url:"weight,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq BackendServerUpdateRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.ServerName == "" {
|
||||
return errors.New("validation-error: field ServerName can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.Address == "" {
|
||||
return errors.New("validation-error: field Address can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.Port == 0 {
|
||||
return errors.New("validation-error: field Port can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) BackendServerUpdate(ctx context.Context, req BackendServerUpdateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/backendServerUpdate"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
66
pkg/cloudapi/lb/backend_update.go
Normal file
66
pkg/cloudapi/lb/backend_update.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type BackendUpdateRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
BackendName string `url:"backendName"`
|
||||
Algorithm string `url:"algorithm,omitempty"`
|
||||
Inter uint64 `url:"inter,omitempty"`
|
||||
DownInter uint64 `url:"downinter,omitempty"`
|
||||
Rise uint `url:"rise,omitempty"`
|
||||
Fall uint `url:"fall,omitempty"`
|
||||
SlowStart uint64 `url:"slowstart,omitempty"`
|
||||
MaxConn uint `url:"maxconn,omitempty"`
|
||||
MaxQueue uint `url:"maxqueue,omitempty"`
|
||||
Weight uint `url:"weight,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq BackendUpdateRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) BackendUpdate(ctx context.Context, req BackendUpdateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/backendUpdate"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
52
pkg/cloudapi/lb/config_reset.go
Normal file
52
pkg/cloudapi/lb/config_reset.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ConfigResetRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq ConfigResetRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) ConfigReset(ctx context.Context, req ConfigResetRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/configReset"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
64
pkg/cloudapi/lb/create.go
Normal file
64
pkg/cloudapi/lb/create.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
RGID uint64 `url:"rgId"`
|
||||
Name string `url:"name"`
|
||||
ExtnetId uint64 `url:"extnetId"`
|
||||
VinsId uint64 `url:"vinsId"`
|
||||
Start bool `url:"start"`
|
||||
Description string `url:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq CreateRequest) Validate() error {
|
||||
if lbrq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.ExtnetId == 0 {
|
||||
return errors.New("validation-error: field ExtnetId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.VinsId == 0 {
|
||||
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/lb/create"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.ReplaceAll(string(res), "\"", ""), nil
|
||||
}
|
||||
53
pkg/cloudapi/lb/delete.go
Normal file
53
pkg/cloudapi/lb/delete.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
Permanently bool `url:"permanently"`
|
||||
}
|
||||
|
||||
func (lbrq DeleteRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/delete"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
82
pkg/cloudapi/lb/disable_enable.go
Normal file
82
pkg/cloudapi/lb/disable_enable.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DisabelEnableRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq DisabelEnableRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) Disable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/disable"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (l LB) Enable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/enable"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
59
pkg/cloudapi/lb/frontend_bind.go
Normal file
59
pkg/cloudapi/lb/frontend_bind.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type FrontendBindRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
FrontendName string `url:"frontendName"`
|
||||
BindingName string `url:"bindingName"`
|
||||
BindingAddress string `url:"bindingAddress,omitempty"`
|
||||
BindingPort uint `url:"bindingPort,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq FrontendBindRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.FrontendName == "" {
|
||||
return errors.New("validation-error: field FrontendName can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.BindingName == "" {
|
||||
return errors.New("validation-error: field BindingName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) FrontendBind(ctx context.Context, req FrontendBindRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/lb/frontendBind"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.ReplaceAll(string(res), "\"", ""), nil
|
||||
}
|
||||
57
pkg/cloudapi/lb/frontend_bind_delete.go
Normal file
57
pkg/cloudapi/lb/frontend_bind_delete.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type FrontendBindDeleteRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
FrontendName string `url:"frontendName"`
|
||||
BindingName string `url:"bindingName"`
|
||||
}
|
||||
|
||||
func (lbrq FrontendBindDeleteRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.FrontendName == "" {
|
||||
return errors.New("validation-error: field FrontendName can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.BindingName == "" {
|
||||
return errors.New("validation-error: field BindingName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) FrontendBindDelete(ctx context.Context, req FrontendBindDeleteRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/lb/frontendBindDelete"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.ReplaceAll(string(res), "\"", ""), nil
|
||||
}
|
||||
59
pkg/cloudapi/lb/frontend_bind_update.go
Normal file
59
pkg/cloudapi/lb/frontend_bind_update.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type FrontendBindUpdateRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
FrontendName string `url:"frontendName"`
|
||||
BindingName string `url:"bindingName"`
|
||||
BindingAddress string `url:"bindingAddress,omitempty"`
|
||||
BindingPort uint `url:"bindingPort,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq FrontendBindUpdateRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.FrontendName == "" {
|
||||
return errors.New("validation-error: field FrontendName can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.BindingName == "" {
|
||||
return errors.New("validation-error: field BindingName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) FrontendBindUpdate(ctx context.Context, req FrontendBindUpdateRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/lb/frontendBindingUpdate"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.ReplaceAll(string(res), "\"", ""), nil
|
||||
}
|
||||
62
pkg/cloudapi/lb/frontend_create.go
Normal file
62
pkg/cloudapi/lb/frontend_create.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type FrontendCreateRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
FrontendName string `url:"frontendName"`
|
||||
BackendName string `url:"backendName"`
|
||||
}
|
||||
|
||||
func (lbrq FrontendCreateRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.FrontendName == "" {
|
||||
return errors.New("validation-error: field FrontendName can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) FrontendCreate(ctx context.Context, req FrontendCreateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/frontendCreate"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
57
pkg/cloudapi/lb/frontend_delete.go
Normal file
57
pkg/cloudapi/lb/frontend_delete.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type FrontendDeleteRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
FrontendName string `url:"frontendName"`
|
||||
}
|
||||
|
||||
func (lbrq FrontendDeleteRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.FrontendName == "" {
|
||||
return errors.New("validation-error: field FrontendName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) FrontendDelete(ctx context.Context, req FrontendDeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/frontendDelete"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
54
pkg/cloudapi/lb/get.go
Normal file
54
pkg/cloudapi/lb/get.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq GetRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*LoadBalancer, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/lb/get"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
lbRaw, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lb := &LoadBalancer{}
|
||||
err = json.Unmarshal(lbRaw, lb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return lb, nil
|
||||
|
||||
}
|
||||
15
pkg/cloudapi/lb/lb.go
Normal file
15
pkg/cloudapi/lb/lb.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
type LB struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *LB {
|
||||
return &LB{
|
||||
client,
|
||||
}
|
||||
}
|
||||
42
pkg/cloudapi/lb/list.go
Normal file
42
pkg/cloudapi/lb/list.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
IncludeDeleted bool `url:"includedeleted"`
|
||||
Page uint64 `url:"page"`
|
||||
Size uint64 `url:"size"`
|
||||
}
|
||||
|
||||
func (l LB) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (LBList, error) {
|
||||
url := "/lb/list"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
lbListRaw, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lbList := LBList{}
|
||||
err = json.Unmarshal(lbListRaw, &lbList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return lbList, nil
|
||||
|
||||
}
|
||||
41
pkg/cloudapi/lb/list_deleted.go
Normal file
41
pkg/cloudapi/lb/list_deleted.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListDeletedRequest struct {
|
||||
Page uint64 `url:"page"`
|
||||
Size uint64 `url:"size"`
|
||||
}
|
||||
|
||||
func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (LBList, error) {
|
||||
url := "/lb/listDeleted"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
lbListRaw, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lbList := LBList{}
|
||||
err = json.Unmarshal(lbListRaw, &lbList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return lbList, nil
|
||||
|
||||
}
|
||||
89
pkg/cloudapi/lb/models.go
Normal file
89
pkg/cloudapi/lb/models.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package lb
|
||||
|
||||
type LoadBalancer struct {
|
||||
HAMode bool `json:"HAmode"`
|
||||
ACL interface{} `json:"acl"`
|
||||
Backends []Backend `json:"backends"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Description string `json:"desc"`
|
||||
DPAPIUser string `json:"dpApiUser"`
|
||||
ExtnetId uint64 `json:"extnetId"`
|
||||
Frontends []Frontend `json:"frontends"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
ImageId uint64 `json:"imageId"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
PrimaryNode Node `json:"primaryNode"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
SecondaryNode Node `json:"secondaryNode"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
VinsId uint64 `json:"vinsId"`
|
||||
}
|
||||
|
||||
type LoadBalancerDetailed struct {
|
||||
DPAPIPassword string `json:"dpApiPassword"`
|
||||
LoadBalancer
|
||||
}
|
||||
|
||||
type Backend struct {
|
||||
Algorithm string `json:"algorithm"`
|
||||
GUID string `json:"guid"`
|
||||
Name string `json:"name"`
|
||||
ServerDefaultSettings ServerSettings `json:"serverDefaultSettings"`
|
||||
Servers []Server `json:"servers"`
|
||||
}
|
||||
|
||||
type LBList []LoadBalancerDetailed
|
||||
|
||||
type ServerSettings struct {
|
||||
Inter uint64 `json:"inter"`
|
||||
GUID string `json:"guid"`
|
||||
DownInter uint64 `json:"downinter"`
|
||||
Rise uint `json:"rise"`
|
||||
Fall uint `json:"fall"`
|
||||
SlowStart uint64 `json:"slowstart"`
|
||||
MaxConn uint `json:"maxconn"`
|
||||
MaxQueue uint `json:"maxqueue"`
|
||||
Weight uint `json:"weight"`
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Address string `json:"address"`
|
||||
Check string `json:"check"`
|
||||
GUID string `json:"guid"`
|
||||
Name string `json:"name"`
|
||||
Port uint `json:"port"`
|
||||
ServerSettings ServerSettings `json:"serverSettings"`
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
BackendIp string `json:"backendIp"`
|
||||
ComputeId uint64 `json:"computeId"`
|
||||
FrontendIp string `json:"frontendIp"`
|
||||
GUID string `json:"guid"`
|
||||
MGMTIp string `json:"mgmtIp"`
|
||||
NetworkId uint64 `json:"networkId"`
|
||||
}
|
||||
|
||||
type Frontend struct {
|
||||
Backend string `json:"backend"`
|
||||
Bindings []Binding `json:"bindings"`
|
||||
GUID string `json:"guid"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Binding struct {
|
||||
Address string `json:"address"`
|
||||
GUID string `json:"guid"`
|
||||
Name string `json:"name"`
|
||||
Port uint `json:"port"`
|
||||
}
|
||||
52
pkg/cloudapi/lb/restart.go
Normal file
52
pkg/cloudapi/lb/restart.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type RestartRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq RestartRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) Restart(ctx context.Context, req RestartRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/restart"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
52
pkg/cloudapi/lb/restore.go
Normal file
52
pkg/cloudapi/lb/restore.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type RestoreRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq RestoreRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/restore"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
56
pkg/cloudapi/lb/update.go
Normal file
56
pkg/cloudapi/lb/update.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type UpdateRequest struct {
|
||||
LBID uint64 `url:"lbId"`
|
||||
Description string `url:"desc"`
|
||||
}
|
||||
|
||||
func (lbrq UpdateRequest) Validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.Description == "" {
|
||||
return errors.New("validation-error: field Description can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l LB) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/lb/update"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
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