This commit is contained in:
dayterr
2026-09-15 17:23:58 +03:00
parent 71b53b743d
commit b39021820a
21 changed files with 692 additions and 105 deletions

View File

@@ -2,6 +2,7 @@ package vins
import (
"context"
"encoding/json"
"net/http"
"strconv"
@@ -63,6 +64,11 @@ type CreateInRGRequest struct {
EnableDefaultGateway interface{} `url:"enable_default_gateway,omitempty" json:"enable_default_gateway,omitempty" validate:"omitempty,isBool"`
}
type asyncWrapperCreateInRgRequest struct {
CreateInRGRequest
AsyncMode bool `url:"asyncMode" json:"asyncMode"`
}
// CreateInRG creates VINS in resource group level
func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, error) {
err := validators.ValidateRequest(req)
@@ -72,7 +78,12 @@ func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, er
url := "/cloudapi/vins/createInRG"
res, err := v.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
syncReq := asyncWrapperCreateInRgRequest{
CreateInRGRequest: req,
AsyncMode: false,
}
res, err := v.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, syncReq)
if err != nil {
return 0, err
}
@@ -84,3 +95,32 @@ func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, er
return result, nil
}
// CreateInRG creates VINS in resource group level in async mode
func (v VINS) AsyncCreateInRG(ctx context.Context, req CreateInRGRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/createInRG"
syncReq := asyncWrapperCreateInRgRequest{
CreateInRGRequest: req,
AsyncMode: true,
}
result, err := v.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, syncReq)
if err != nil {
return "", err
}
var resp string
err = json.Unmarshal(result, &resp)
if err != nil {
return "", err
}
return resp, nil
}