Files
decort-golang-sdk/pkg/cloudbroker/vgpu/destroy.go
dayterr 8cde0e9371 v1.16.7
v1.16.7
2026-10-09 16:23:35 +03:00

79 lines
1.6 KiB
Go

package vgpu
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DestroyRequest struct for destroying VGPU
type DestroyRequest struct {
// Virtual GPU ID
// Required: true
VGPUID uint64 `url:"vgpu_id" json:"vgpu_id" validate:"required"`
}
type asyncWrapperDestroyRequest struct {
DestroyRequest
AsyncMode bool `url:"async_mode"`
}
// Destroy destroys VGPU
func (v VGPU) Destroy(ctx context.Context, req DestroyRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vgpu/destroy"
aReq := asyncWrapperDestroyRequest{
DestroyRequest: req,
AsyncMode: false,
}
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, aReq)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
// 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
}