v1.16.7
v1.16.7
This commit is contained in:
@@ -2,6 +2,7 @@ package vgpu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -14,6 +15,10 @@ type CreateRequest struct {
|
||||
// Required: true
|
||||
PGPUID uint64 `url:"pgpu_id" json:"pgpu_id" validate:"required"`
|
||||
|
||||
// Name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Virtual profile id
|
||||
// Required: false
|
||||
ProfileID string `url:"profile_id,omitempty" json:"profile_id,omitempty"`
|
||||
@@ -31,6 +36,11 @@ type CreateRequest struct {
|
||||
AccountIDs []uint64 `url:"account_ids,omitempty" json:"account_ids,omitempty"`
|
||||
}
|
||||
|
||||
type asyncWrapperCreateRequest struct {
|
||||
CreateRequest
|
||||
AsyncMode bool `url:"async_mode"`
|
||||
}
|
||||
|
||||
// Create creates VGPU
|
||||
func (v VGPU) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
@@ -40,7 +50,12 @@ func (v VGPU) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
|
||||
url := "/cloudbroker/vgpu/create"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
aReq := asyncWrapperCreateRequest{
|
||||
CreateRequest: req,
|
||||
AsyncMode: false,
|
||||
}
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, aReq)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -52,3 +67,33 @@ func (v VGPU) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CreateAsync creates VGPU in async mode
|
||||
func (v VGPU) CreateAsync(ctx context.Context, req CreateRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vgpu/create"
|
||||
|
||||
aReq := asyncWrapperCreateRequest{
|
||||
CreateRequest: 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