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

@@ -9,17 +9,43 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for create FLIPGroup
type CreateRequest struct {
AccountID uint64 `url:"accountId"`
Name string `url:"name"`
NetType string `url:"netType"`
NetID uint64 `url:"netId"`
ClientType string `url:"clientType"`
IP string `url:"ip,omitempty"`
// Account ID
// Required: true
AccountID uint64 `url:"accountId"`
// FLIPGroup name
// Required: true
Name string `url:"name"`
// Network type
// Should be one of:
// - EXTNET
// - VINS
// Required: true
NetType string `url:"netType"`
// ID of external network or VINS
// Required: true
NetID uint64 `url:"netId"`
// Type of client
// - 'compute'
// - 'vins' (will be later)
// Required: true
ClientType string `url:"clientType"`
// IP address to associate with this group. If empty, the platform will autoselect IP address
// Required: false
IP string `url:"ip,omitempty"`
// Text description of this FLIPGorup instance
// Required: false
Description string `url:"desc,omitempty"`
}
func (frq CreateRequest) Validate() error {
func (frq CreateRequest) validate() error {
if frq.AccountID == 0 {
return errors.New("field AccountID can not be empty or equal to 0")
}
@@ -29,7 +55,6 @@ func (frq CreateRequest) Validate() error {
if frq.Name == "" {
return errors.New("field Name can not be empty")
}
validator := validators.StringInSlice(frq.NetType, []string{"EXTNET", "VINS"})
if !validator {
return errors.New("field Name can be only EXTNET or VINS")
@@ -42,21 +67,26 @@ func (frq CreateRequest) Validate() error {
return nil
}
func (f FlipGroup) Create(ctx context.Context, req CreateRequest) (*FlipGroupRecord, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/flipgroup/create"
fgRaw, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
// Create method will create a new FLIPGorup in the specified Account
func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGroup, error) {
err := req.validate()
if err != nil {
return nil, err
}
fg := &FlipGroupRecord{}
if err := json.Unmarshal(fgRaw, fg); err != nil {
url := "/cloudapi/flipgroup/create"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
return fg, nil
info := RecordFLIPGroup{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}