This commit is contained in:
asteam
2025-09-23 14:34:24 +03:00
parent b924e85e49
commit f1ffb4c0fd
1108 changed files with 72020 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package vgpu
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AllocateRequest struct for allocating VGPU
type AllocateRequest struct {
// Virtual GPU ID
// Required: true
VGPUID uint64 `url:"vgpuId" json:"vgpuId" validate:"required"`
}
// Allocate allocates GPU
func (v VGPU) Allocate(ctx context.Context, req AllocateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vgpu/allocate"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,50 @@
package vgpu
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// CreateRequest struct for creating VGPU
type CreateRequest struct {
// ID of pGPU
// Required: true
PGPUID uint64 `url:"pgpuId" json:"pgpuId" validate:"required"`
// ID of the target resource group.
// Required: true
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Virtual profile id
// Required: false
ProfileID uint64 `url:"profileId,omitempty" json:"profileId,omitempty"`
// Allocate vgpu after creation
// Required: false
Allocate bool `url:"allocate,omitempty" json:"allocate,omitempty"`
}
// Create creates VGPU
func (v VGPU) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vgpu/create"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -0,0 +1,42 @@
package vgpu
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DeallocateRequest struct for deallocating VGPU
type DeallocateRequest struct {
// Virtual GPU ID
// Required: true
VGPUID uint64 `url:"vgpuId" json:"vgpuId" validate:"required"`
// Force delete (detach from compute)
// Required: false
Force bool `url:"force,omitempty" json:"force,omitempty"`
}
// Deallocate releases GPU resources
func (v VGPU) Deallocate(ctx context.Context, req DeallocateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vgpu/deallocate"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,42 @@
package vgpu
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DestroyRequest struct for destroying VGPU
type DestroyRequest struct {
// Virtual GPU ID
// Required: true
VGPUID uint64 `url:"vgpuId" json:"vgpuId" validate:"required"`
// Force delete (deallocate and detach from compute)
// Required: false
Force bool `url:"force,omitempty" json:"force,omitempty"`
}
// 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"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,10 @@
package vgpu
// IDs gets array of VGPUIDs from ListVGPU struct
func (lvg ListVGPU) IDs() []uint64 {
res := make([]uint64, 0, len(lvg.Data))
for _, s := range lvg.Data {
res = append(res, s.ID)
}
return res
}

View File

@@ -0,0 +1,88 @@
package vgpu
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListRequest struct to get list of VGPU
type ListRequest struct {
// Find by id
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by vgpu status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by vgpu type
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
// Find by vgpu mode
// Required: false
Mode string `url:"mode,omitempty" json:"mode,omitempty"`
// Find by id resgroup
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by account id
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by compute id
// Required: false
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
// Find by pgpu id
// Required: false
PGPUID uint64 `url:"pgpuId,omitempty" json:"pgpuId,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of all VGPU as a ListVGPU struct
func (v VGPU) List(ctx context.Context, req ListRequest) (*ListVGPU, error) {
res, err := v.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListVGPU{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of all VGPU as an array of bytes
func (v VGPU) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vgpu/list"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,72 @@
package vgpu
type ItemVGPU struct {
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// Account ID
AccountID uint64 `json:"accountId"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
//Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// VGPU ID
ID uint64 `json:"id"`
// Last claimed by
LastClaimedBy uint64 `json:"lastClaimedBy"`
// Last update time
LastUpdateTime uint64 `json:"lastUpdateTime"`
// Mode
Mode string `json:"mode"`
// PCI Slot
PCISlot interface{} `json:"pciSlot"`
// PGPUID
PGPUID uint64 `json:"pgpuid"`
// Profile ID
ProfileID interface{} `json:"profileId"`
// RAM
RAM uint64 `json:"ram"`
// Reference ID
ReferenceID interface{} `json:"referenceId"`
// RGID
RGID uint64 `json:"rgId"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
// VMID
VMID uint64 `json:"vmid"`
}
// List of VGPU
type ListVGPU struct {
// Data
Data []ItemVGPU `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -0,0 +1,43 @@
package vgpu
import (
"encoding/json"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/serialization"
)
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (l ListVGPU) Serialize(params ...string) (serialization.Serialized, error) {
if len(l.Data) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(l, prefix, indent)
}
return json.Marshal(l)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (i ItemVGPU) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(i, prefix, indent)
}
return json.Marshal(i)
}

View File

@@ -0,0 +1,15 @@
package vgpu
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
// Structure for creating request to VGPU
type VGPU struct {
client interfaces.Caller
}
// Builder for VGPU endpoints
func New(client interfaces.Caller) *VGPU {
return &VGPU{
client: client,
}
}