2023-04-20 11:17:35 +03:00
|
|
|
package vgpu
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2026-10-09 16:23:35 +03:00
|
|
|
"encoding/json"
|
2023-04-20 11:17:35 +03:00
|
|
|
"net/http"
|
|
|
|
|
"strconv"
|
2026-08-21 17:52:28 +04:00
|
|
|
|
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
2023-04-20 11:17:35 +03:00
|
|
|
)
|
|
|
|
|
|
2023-10-25 17:37:18 +03:00
|
|
|
// DestroyRequest struct for destroying VGPU
|
2023-04-20 11:17:35 +03:00
|
|
|
type DestroyRequest struct {
|
|
|
|
|
// Virtual GPU ID
|
|
|
|
|
// Required: true
|
2026-08-21 17:52:28 +04:00
|
|
|
VGPUID uint64 `url:"vgpu_id" json:"vgpu_id" validate:"required"`
|
2023-04-20 11:17:35 +03:00
|
|
|
}
|
|
|
|
|
|
2026-10-09 16:23:35 +03:00
|
|
|
type asyncWrapperDestroyRequest struct {
|
|
|
|
|
DestroyRequest
|
|
|
|
|
AsyncMode bool `url:"async_mode"`
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-20 11:17:35 +03:00
|
|
|
// Destroy destroys VGPU
|
|
|
|
|
func (v VGPU) Destroy(ctx context.Context, req DestroyRequest) (bool, error) {
|
|
|
|
|
err := validators.ValidateRequest(req)
|
|
|
|
|
if err != nil {
|
2023-10-25 17:37:18 +03:00
|
|
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
2023-04-20 11:17:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url := "/cloudbroker/vgpu/destroy"
|
|
|
|
|
|
2026-10-09 16:23:35 +03:00
|
|
|
aReq := asyncWrapperDestroyRequest{
|
|
|
|
|
DestroyRequest: req,
|
|
|
|
|
AsyncMode: false,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, aReq)
|
2023-04-20 11:17:35 +03:00
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := strconv.ParseBool(string(res))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|
2026-10-09 16:23:35 +03:00
|
|
|
|
|
|
|
|
// Destroy destroys VGPU in async mode
|
|
|
|
|
func (v VGPU) DestroyAsync(ctx context.Context, req DestroyRequest) (string, error) {
|
|
|
|
|
err := validators.ValidateRequest(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", validators.ValidationErrors(validators.GetErrors(err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url := "/cloudbroker/vgpu/destroy"
|
|
|
|
|
|
|
|
|
|
aReq := asyncWrapperDestroyRequest{
|
|
|
|
|
DestroyRequest: req,
|
|
|
|
|
AsyncMode: true,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, aReq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resp string
|
|
|
|
|
|
|
|
|
|
err = json.Unmarshal(res, &resp)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|