v1.16.7
v1.16.7
This commit is contained in:
82
pkg/cloudbroker/vgpu/edit.go
Normal file
82
pkg/cloudbroker/vgpu/edit.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package vgpu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// EditRequest to edit the name
|
||||
type EditRequest struct {
|
||||
// VGPU ID
|
||||
// Required: true
|
||||
VGPUID uint64 `url:"vgpu_id" json:"vgpu_id" validate:"required"`
|
||||
|
||||
// New name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type asyncWrapperEditRequest struct {
|
||||
EditRequest
|
||||
AsyncMode bool `url:"async_mode"`
|
||||
}
|
||||
|
||||
// Edit edits the name
|
||||
func (v VGPU) Edit(ctx context.Context, req EditRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vgpu/edit"
|
||||
|
||||
aReq := asyncWrapperEditRequest{
|
||||
EditRequest: 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
|
||||
}
|
||||
|
||||
// Edit Async edits the name in async mode
|
||||
func (v VGPU) EditAsync(ctx context.Context, req EditRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vgpu/edit"
|
||||
|
||||
aReq := asyncWrapperEditRequest{
|
||||
EditRequest: 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
|
||||
}
|
||||
Reference in New Issue
Block a user