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
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package vgpu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -15,6 +16,11 @@ type DestroyRequest struct {
|
||||
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)
|
||||
@@ -24,7 +30,12 @@ func (v VGPU) Destroy(ctx context.Context, req DestroyRequest) (bool, error) {
|
||||
|
||||
url := "/cloudbroker/vgpu/destroy"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
aReq := asyncWrapperDestroyRequest{
|
||||
DestroyRequest: req,
|
||||
AsyncMode: false,
|
||||
}
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, aReq)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -36,3 +47,32 @@ func (v VGPU) Destroy(ctx context.Context, req DestroyRequest) (bool, error) {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -42,6 +42,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Sort by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
@@ -60,6 +60,12 @@ type ItemVGPU struct {
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Node ID
|
||||
NodeID uint64 `json:"node_id"`
|
||||
}
|
||||
|
||||
// List of VGPU
|
||||
|
||||
Reference in New Issue
Block a user