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.
decort-golang-sdk/pkg/cloudapi/flipgroup/create.go

70 lines
1.7 KiB

package flipgroup
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CreateRequest struct to create FLIPGroup
type CreateRequest struct {
// Account ID
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// FLIPGroup name
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Network type
// Should be one of:
// - EXTNET
// - VINS
// Required: true
NetType string `url:"netType" json:"netType" validate:"computeNetType"`
// ID of external network or VINS
// Required: true
NetID uint64 `url:"netId" json:"netId" validate:"required"`
// Type of client
// - 'compute'
// - 'vins' (will be later)
// Required: true
ClientType string `url:"clientType" json:"clientType" validate:"flipgroupClientType"`
// IP address to associate with this group. If empty, the platform will autoselect IP address
// Required: false
IP string `url:"ip,omitempty" json:"ip,omitempty"`
// Text description of this FLIPGorup instance
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
}
// Create method will create a new FLIPGorup in the specified Account
func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGroupCreated, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/flipgroup/create"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := RecordFLIPGroupCreated{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}