You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
package bservice
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strconv"
|
|
|
|
"github.com/rudecs/decort-sdk/internal/validators"
|
|
"github.com/rudecs/decort-sdk/opts"
|
|
"github.com/rudecs/decort-sdk/typed"
|
|
)
|
|
|
|
type GroupResizeRequest struct {
|
|
ServiceID uint64 `url:"serviceId"`
|
|
CompGroupID uint64 `url:"compgroupId"`
|
|
Count int64 `url:"count"`
|
|
Mode string `url:"mode"`
|
|
}
|
|
|
|
func (bsrq GroupResizeRequest) Validate() error {
|
|
if bsrq.ServiceID == 0 {
|
|
return errors.New("field ServiceID can not be empty or equal to 0")
|
|
}
|
|
|
|
if bsrq.CompGroupID == 0 {
|
|
return errors.New("field CompGroupID can not be empty or equal to 0")
|
|
}
|
|
|
|
if bsrq.Mode == "RELATIVE" && bsrq.Count == 0 {
|
|
return errors.New("field Count can not be equal to 0 if Mode if 'RELATIVE'")
|
|
}
|
|
|
|
if !validators.StringInSlice(bsrq.Mode, []string{"RELATIVE", "ABSOLUTE"}) {
|
|
return errors.New("field Mode can only be one of 'RELATIVE' or 'ABSOLUTE'")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest, options ...opts.DecortOpts) (uint64, error) {
|
|
if err := req.Validate(); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
url := "/cloudapi/bservice/groupResize"
|
|
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return strconv.ParseUint(string(res), 10, 64)
|
|
}
|