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.
73 lines
1.6 KiB
73 lines
1.6 KiB
package vins
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
// Request struct for create VINS in account
|
|
type CreateInAccountRequest struct {
|
|
// VINS name
|
|
// Required: true
|
|
Name string `url:"name" json:"name"`
|
|
|
|
// ID of account
|
|
// Required: true
|
|
AccountID uint64 `url:"accountId" json:"accountId"`
|
|
|
|
// Grid ID
|
|
// Required: false
|
|
GID uint64 `url:"gid,omitempty" json:"gid,omitempty"`
|
|
|
|
// Private network IP CIDR
|
|
// Required: false
|
|
IPCIDR string `url:"ipcidr,omitempty" json:"ipcidr,omitempty"`
|
|
|
|
// Description
|
|
// Required: false
|
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
|
|
|
// Number of pre created reservations
|
|
// Required: false
|
|
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
|
|
|
// Reason for action
|
|
// Required: false
|
|
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
|
}
|
|
|
|
func (vrq CreateInAccountRequest) validate() error {
|
|
if vrq.Name == "" {
|
|
return errors.New("validation-error: field Name must be set")
|
|
}
|
|
if vrq.AccountID == 0 {
|
|
return errors.New("validation-error: field AccountID must be set")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreateInAccount creates VINS in account level
|
|
func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (uint64, error) {
|
|
err := req.validate()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
url := "/cloudbroker/vins/createInAccount"
|
|
|
|
res, err := v.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
|
|
}
|