parent
20fd7ab50c
commit
7c787f6fce
@ -1,247 +1,250 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var computes = ListComputes{
|
||||
ItemCompute{
|
||||
Disks: []InfoDisk{
|
||||
{
|
||||
ID: 65191,
|
||||
PCISlot: 6,
|
||||
},
|
||||
},
|
||||
InfoCompute: InfoCompute{
|
||||
ACL: []interface{}{},
|
||||
AccountID: 132847,
|
||||
AccountName: "std_2",
|
||||
AffinityLabel: "",
|
||||
AffinityRules: []ItemRule{
|
||||
Data: []ItemCompute{
|
||||
{
|
||||
Disks: []InfoDisk{
|
||||
{
|
||||
GUID: "",
|
||||
Key: "aff_key",
|
||||
Mode: "ANY",
|
||||
Policy: "RECOMMENDED",
|
||||
Topology: "compute",
|
||||
Value: "aff_val",
|
||||
ID: 65191,
|
||||
PCISlot: 6,
|
||||
},
|
||||
},
|
||||
AffinityWeight: 0,
|
||||
AntiAffinityRules: []ItemRule{
|
||||
{
|
||||
GUID: "",
|
||||
Key: "antiaff_key",
|
||||
Mode: "ANY",
|
||||
Policy: "RECOMMENDED",
|
||||
Topology: "compute",
|
||||
Value: "antiaff_val",
|
||||
InfoCompute: InfoCompute{
|
||||
ACL: []interface{}{},
|
||||
AccountID: 132847,
|
||||
AccountName: "std_2",
|
||||
AffinityLabel: "",
|
||||
AffinityRules: []ItemRule{
|
||||
{
|
||||
GUID: "",
|
||||
Key: "aff_key",
|
||||
Mode: "ANY",
|
||||
Policy: "RECOMMENDED",
|
||||
Topology: "compute",
|
||||
Value: "aff_val",
|
||||
},
|
||||
},
|
||||
AffinityWeight: 0,
|
||||
AntiAffinityRules: []ItemRule{
|
||||
{
|
||||
GUID: "",
|
||||
Key: "antiaff_key",
|
||||
Mode: "ANY",
|
||||
Policy: "RECOMMENDED",
|
||||
Topology: "compute",
|
||||
Value: "antiaff_val",
|
||||
},
|
||||
},
|
||||
Arch: "X86_64",
|
||||
BootOrder: []string{
|
||||
"hd", "cdrom",
|
||||
},
|
||||
BootDiskSize: 0,
|
||||
CloneReference: 0,
|
||||
Clones: []uint64{},
|
||||
ComputeCIID: 0,
|
||||
CPUs: 4,
|
||||
CreatedBy: "timofey_tkachev_1@decs3o",
|
||||
CreatedTime: 1676975175,
|
||||
CustomFields: map[string]interface{}{},
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
Devices: nil,
|
||||
Driver: "KVM_X86",
|
||||
GID: 212,
|
||||
GUID: 48500,
|
||||
ID: 48500,
|
||||
ImageID: 9884,
|
||||
Interfaces: ListInterfaces{},
|
||||
LockStatus: "UNLOCKED",
|
||||
ManagerID: 0,
|
||||
ManagerType: "",
|
||||
MigrationJob: 0,
|
||||
Milestones: 363500,
|
||||
Name: "test",
|
||||
Pinned: false,
|
||||
RAM: 4096,
|
||||
ReferenceID: "c7cb19ac-af4a-4067-852f-c5572949207e",
|
||||
Registered: true,
|
||||
ResName: "compute-48500",
|
||||
RGID: 79724,
|
||||
RGName: "std_broker2",
|
||||
SnapSets: ListSnapshots{},
|
||||
StatelessSEPID: 0,
|
||||
StatelessSEPType: "",
|
||||
Status: "ENABLED",
|
||||
Tags: map[string]interface{}{},
|
||||
TechStatus: "STOPPED",
|
||||
TotalDiskSize: 2,
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 1677058904,
|
||||
UserManaged: true,
|
||||
VGPUs: []uint64{},
|
||||
VINSConnected: 0,
|
||||
VirtualImageID: 0,
|
||||
},
|
||||
Arch: "X86_64",
|
||||
BootOrder: []string{
|
||||
"hd", "cdrom",
|
||||
},
|
||||
BootDiskSize: 0,
|
||||
CloneReference: 0,
|
||||
Clones: []uint64{},
|
||||
ComputeCIID: 0,
|
||||
CPUs: 4,
|
||||
CreatedBy: "timofey_tkachev_1@decs3o",
|
||||
CreatedTime: 1676975175,
|
||||
CustomFields: map[string]interface{}{},
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
Devices: nil,
|
||||
Driver: "KVM_X86",
|
||||
GID: 212,
|
||||
GUID: 48500,
|
||||
ID: 48500,
|
||||
ImageID: 9884,
|
||||
Interfaces: ListInterfaces{},
|
||||
LockStatus: "UNLOCKED",
|
||||
ManagerID: 0,
|
||||
ManagerType: "",
|
||||
MigrationJob: 0,
|
||||
Milestones: 363500,
|
||||
Name: "test",
|
||||
Pinned: false,
|
||||
RAM: 4096,
|
||||
ReferenceID: "c7cb19ac-af4a-4067-852f-c5572949207e",
|
||||
Registered: true,
|
||||
ResName: "compute-48500",
|
||||
RGID: 79724,
|
||||
RGName: "std_broker2",
|
||||
SnapSets: ListSnapshots{},
|
||||
StatelessSEPID: 0,
|
||||
StatelessSEPType: "",
|
||||
Status: "ENABLED",
|
||||
Tags: map[string]interface{}{},
|
||||
TechStatus: "STOPPED",
|
||||
TotalDiskSize: 2,
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 1677058904,
|
||||
UserManaged: true,
|
||||
VGPUs: []uint64{},
|
||||
VINSConnected: 0,
|
||||
VirtualImageID: 0,
|
||||
},
|
||||
},
|
||||
ItemCompute{
|
||||
Disks: []InfoDisk{
|
||||
{
|
||||
ID: 65248,
|
||||
PCISlot: 6,
|
||||
{
|
||||
Disks: []InfoDisk{
|
||||
{
|
||||
ID: 65248,
|
||||
PCISlot: 6,
|
||||
},
|
||||
},
|
||||
},
|
||||
InfoCompute: InfoCompute{
|
||||
ACL: []interface{}{},
|
||||
AccountID: 132848,
|
||||
AccountName: "std_broker",
|
||||
AffinityLabel: "",
|
||||
AffinityRules: []ItemRule{},
|
||||
AffinityWeight: 0,
|
||||
AntiAffinityRules: []ItemRule{},
|
||||
Arch: "X86_64",
|
||||
BootOrder: []string{
|
||||
"hd", "cdrom",
|
||||
InfoCompute: InfoCompute{
|
||||
ACL: []interface{}{},
|
||||
AccountID: 132848,
|
||||
AccountName: "std_broker",
|
||||
AffinityLabel: "",
|
||||
AffinityRules: []ItemRule{},
|
||||
AffinityWeight: 0,
|
||||
AntiAffinityRules: []ItemRule{},
|
||||
Arch: "X86_64",
|
||||
BootOrder: []string{
|
||||
"hd", "cdrom",
|
||||
},
|
||||
BootDiskSize: 0,
|
||||
CloneReference: 0,
|
||||
Clones: []uint64{},
|
||||
ComputeCIID: 0,
|
||||
CPUs: 6,
|
||||
CreatedBy: "timofey_tkachev_1@decs3o",
|
||||
CreatedTime: 1677579436,
|
||||
CustomFields: map[string]interface{}{},
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
Devices: nil,
|
||||
Driver: "KVM_X86",
|
||||
GID: 212,
|
||||
GUID: 48556,
|
||||
ID: 48556,
|
||||
ImageID: 9884,
|
||||
Interfaces: ListInterfaces{},
|
||||
LockStatus: "UNLOCKED",
|
||||
ManagerID: 0,
|
||||
ManagerType: "",
|
||||
MigrationJob: 0,
|
||||
Milestones: 363853,
|
||||
Name: "compute_2",
|
||||
Pinned: false,
|
||||
RAM: 4096,
|
||||
ReferenceID: "a542c449-5b1c-4f90-88c5-7bb5f8ae68ff",
|
||||
Registered: true,
|
||||
ResName: "compute-48556",
|
||||
RGID: 79727,
|
||||
RGName: "sdk_negative_fields_test",
|
||||
SnapSets: ListSnapshots{},
|
||||
StatelessSEPID: 0,
|
||||
StatelessSEPType: "",
|
||||
Status: "ENABLED",
|
||||
Tags: map[string]interface{}{},
|
||||
TechStatus: "STARTED",
|
||||
TotalDiskSize: 1,
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 1677579436,
|
||||
UserManaged: true,
|
||||
VGPUs: []uint64{},
|
||||
VINSConnected: 0,
|
||||
VirtualImageID: 0,
|
||||
},
|
||||
BootDiskSize: 0,
|
||||
CloneReference: 0,
|
||||
Clones: []uint64{},
|
||||
ComputeCIID: 0,
|
||||
CPUs: 6,
|
||||
CreatedBy: "timofey_tkachev_1@decs3o",
|
||||
CreatedTime: 1677579436,
|
||||
CustomFields: map[string]interface{}{},
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
Devices: nil,
|
||||
Driver: "KVM_X86",
|
||||
GID: 212,
|
||||
GUID: 48556,
|
||||
ID: 48556,
|
||||
ImageID: 9884,
|
||||
Interfaces: ListInterfaces{},
|
||||
LockStatus: "UNLOCKED",
|
||||
ManagerID: 0,
|
||||
ManagerType: "",
|
||||
MigrationJob: 0,
|
||||
Milestones: 363853,
|
||||
Name: "compute_2",
|
||||
Pinned: false,
|
||||
RAM: 4096,
|
||||
ReferenceID: "a542c449-5b1c-4f90-88c5-7bb5f8ae68ff",
|
||||
Registered: true,
|
||||
ResName: "compute-48556",
|
||||
RGID: 79727,
|
||||
RGName: "sdk_negative_fields_test",
|
||||
SnapSets: ListSnapshots{},
|
||||
StatelessSEPID: 0,
|
||||
StatelessSEPType: "",
|
||||
Status: "ENABLED",
|
||||
Tags: map[string]interface{}{},
|
||||
TechStatus: "STARTED",
|
||||
TotalDiskSize: 1,
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 1677579436,
|
||||
UserManaged: true,
|
||||
VGPUs: []uint64{},
|
||||
VINSConnected: 0,
|
||||
VirtualImageID: 0,
|
||||
},
|
||||
},
|
||||
EntryCount: 2,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := computes.FilterByID(48500).FindOne()
|
||||
actual := computes.FilterByID(48500).FindOne()
|
||||
|
||||
if actual.ID != 48500 {
|
||||
t.Fatal("expected ID 48500, found: ", actual.ID)
|
||||
}
|
||||
if actual.ID != 48500 {
|
||||
t.Fatal("expected ID 48500, found: ", actual.ID)
|
||||
}
|
||||
|
||||
actualEmpty := computes.FilterByID(0)
|
||||
actualEmpty := computes.FilterByID(0)
|
||||
|
||||
if len(actualEmpty) != 0 {
|
||||
t.Fatal("expected empty, actual: ", len(actualEmpty))
|
||||
}
|
||||
if len(actualEmpty.Data) != 0 {
|
||||
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := computes.FilterByName("compute_2").FindOne()
|
||||
actual := computes.FilterByName("compute_2").FindOne()
|
||||
|
||||
if actual.Name != "compute_2" {
|
||||
t.Fatal("expected compute with name 'test', found: ", actual.Name)
|
||||
}
|
||||
if actual.Name != "compute_2" {
|
||||
t.Fatal("expected compute with name 'test', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := computes.FilterByStatus("ENABLED")
|
||||
actual := computes.FilterByStatus("ENABLED")
|
||||
|
||||
for _, item := range actual {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected ENABLED status, found: ", item.Status)
|
||||
}
|
||||
}
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected ENABLED status, found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByTechStatus(t *testing.T) {
|
||||
actual := computes.FilterByTechStatus("STARTED").FindOne()
|
||||
actual := computes.FilterByTechStatus("STARTED").FindOne()
|
||||
|
||||
if actual.ID != 48556 {
|
||||
t.Fatal("expected 48556 with STARTED techStatus, found: ", actual.ID)
|
||||
}
|
||||
if actual.ID != 48556 {
|
||||
t.Fatal("expected 48556 with STARTED techStatus, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByDiskID(t *testing.T) {
|
||||
actual := computes.FilterByDiskID(65248).FindOne()
|
||||
actual := computes.FilterByDiskID(65248).FindOne()
|
||||
|
||||
if actual.ID != 48556 {
|
||||
t.Fatal("expected 48556 with DiskID 65248, found: ", actual.ID)
|
||||
}
|
||||
if actual.ID != 48556 {
|
||||
t.Fatal("expected 48556 with DiskID 65248, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := computes.FilterFunc(func(ic ItemCompute) bool {
|
||||
return ic.Registered == true
|
||||
})
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 elements found, actual: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.Registered != true {
|
||||
t.Fatal("expected Registered to be true, actual: ", item.Registered)
|
||||
}
|
||||
}
|
||||
actual := computes.FilterFunc(func(ic ItemCompute) bool {
|
||||
return ic.Registered == true
|
||||
})
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 elements found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Registered != true {
|
||||
t.Fatal("expected Registered to be true, actual: ", item.Registered)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortingByCreatedTime(t *testing.T) {
|
||||
actual := computes.SortByCreatedTime(false)
|
||||
actual := computes.SortByCreatedTime(false)
|
||||
|
||||
if actual[0].Name != "test" {
|
||||
t.Fatal("expected 'test', found: ", actual[0].Name)
|
||||
}
|
||||
if actual.Data[0].Name != "test" {
|
||||
t.Fatal("expected 'test', found: ", actual.Data[0].Name)
|
||||
}
|
||||
|
||||
actual = computes.SortByCreatedTime(true)
|
||||
if actual[0].Name != "compute_2" {
|
||||
t.Fatal("expected 'compute_2', found: ", actual[0].Name)
|
||||
}
|
||||
actual = computes.SortByCreatedTime(true)
|
||||
if actual.Data[0].Name != "compute_2" {
|
||||
t.Fatal("expected 'compute_2', found: ", actual.Data[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortingByCPU(t *testing.T) {
|
||||
actual := computes.SortByCPU(false)
|
||||
actual := computes.SortByCPU(false)
|
||||
|
||||
if actual[0].CPUs != 4{
|
||||
t.Fatal("expected 4 CPU cores, found: ", actual[0].CPUs)
|
||||
}
|
||||
if actual.Data[0].CPUs != 4 {
|
||||
t.Fatal("expected 4 CPU cores, found: ", actual.Data[0].CPUs)
|
||||
}
|
||||
|
||||
actual = computes.SortByCPU(true)
|
||||
actual = computes.SortByCPU(true)
|
||||
|
||||
if actual[0].CPUs != 6 {
|
||||
t.Fatal("expected 6 CPU cores, found: ", actual[0].CPUs)
|
||||
}
|
||||
if actual.Data[0].CPUs != 6 {
|
||||
t.Fatal("expected 6 CPU cores, found: ", actual.Data[0].CPUs)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list GPU for compute
|
||||
type ListVGPURequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Find by GPU id
|
||||
// Required: false
|
||||
GPUID uint64 `url:"gpuId,omitempty" json:"gpuId,omitempty"`
|
||||
|
||||
// Find by type
|
||||
// Required: false
|
||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
|
||||
// Include deleted computes. If using field 'status', then includedeleted will be ignored
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
||||
}
|
||||
|
||||
// ListVGPU gets list GPU for compute
|
||||
func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) (*ListVGPUs, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/listVGpu"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListVGPUs{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetResourceConsumptionRequest struct {
|
||||
// ID of the grid
|
||||
// Required: true
|
||||
GridID uint64 `url:"gridId" json:"gridId" validate:"required"`
|
||||
}
|
||||
|
||||
func (g Grid) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*RecordResourcesConsumption, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/grid/getResourceConsumption"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := RecordResourcesConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (g Grid) ListResourceConsumption(ctx context.Context) (*ListResourceConsumption, error) {
|
||||
url := "/cloudbroker/grid/listResourceConsumption"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := ListResourceConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue