Files
decort-golang-sdk/pkg/cloudbroker/vins/vnfdev_redeploy.go
2026-09-15 17:35:01 +03:00

79 lines
1.7 KiB
Go

package vins
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// VNFDevRedeployRequest struct to redeploy VNF devices
type VNFDevRedeployRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
type asyncWrapperVNFDevRedeployRequest struct {
VNFDevRedeployRequest
AsyncMode bool `url:"asyncMode"`
}
// VNFDevRedeploy redeploys VINS VNFDevs
func (v VINS) VNFDevRedeploy(ctx context.Context, req VNFDevRedeployRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vins/vnfdevRedeploy"
syncReq := asyncWrapperVNFDevRedeployRequest{
VNFDevRedeployRequest: req,
AsyncMode: false,
}
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, syncReq)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
// VNFDevRedeploy redeploys VINS VNFDevs in async mode
func (v VINS) AsyncVNFDevRedeploy(ctx context.Context, req VNFDevRedeployRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vins/vnfdevRedeploy"
asyncReq := asyncWrapperVNFDevRedeployRequest{
VNFDevRedeployRequest: req,
AsyncMode: true,
}
result, err := v.client.DecortApiCall(ctx, http.MethodPost, url, asyncReq)
if err != nil {
return "", err
}
var resp string
err = json.Unmarshal(result, &resp)
if err != nil {
return "", err
}
return resp, nil
}