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 extnet
import (
"context"
"encoding/json"
"net/http"
"strconv"
@@ -15,6 +16,11 @@ type DeviceDeployRequest struct {
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
}
type asyncWrapperDeviceDeployRequest struct {
DeviceDeployRequest
AsyncMode bool `url:"async_mode"`
}
// DeviceDeploy deploys network device for external network (make not virtual, "physical")
func (e ExtNet) DeviceDeploy(ctx context.Context, req DeviceDeployRequest) (bool, error) {
err := validators.ValidateRequest(req)
@@ -24,7 +30,12 @@ func (e ExtNet) DeviceDeploy(ctx context.Context, req DeviceDeployRequest) (bool
url := "/cloudbroker/extnet/deviceDeploy"
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
syncReq := asyncWrapperDeviceDeployRequest{
DeviceDeployRequest: req,
AsyncMode: false,
}
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, syncReq)
if err != nil {
return false, err
}
@@ -36,3 +47,32 @@ func (e ExtNet) DeviceDeploy(ctx context.Context, req DeviceDeployRequest) (bool
return result, nil
}
// AsyncDeviceDeploy deploys network device for external network (make not virtual, "physical") in async mode
func (e ExtNet) AsyncDeviceDeploy(ctx context.Context, req DeviceDeployRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/extnet/deviceDeploy"
syncReq := asyncWrapperDeviceDeployRequest{
DeviceDeployRequest: req,
AsyncMode: true,
}
result, err := e.client.DecortApiCall(ctx, http.MethodPost, url, syncReq)
if err != nil {
return "", err
}
var resp string
err = json.Unmarshal(result, &resp)
if err != nil {
return "", err
}
return resp, nil
}