v1.5.0-gamma2

This commit is contained in:
2023-07-07 12:40:03 +03:00
parent 20fd7ab50c
commit 7c787f6fce
111 changed files with 2905 additions and 1505 deletions

View File

@@ -18,6 +18,10 @@ type DiskAttachRequest struct {
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Type of the disk B;D
// Required: false
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`

View File

@@ -21,6 +21,10 @@ type DiskQOSRequest struct {
// Limit IO for a certain disk total and read/write options are not allowed to be combined
// Required: true
Limits string `url:"limits" json:"limits" validate:"required"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
// DiskQOS change QOS of the disk

View File

@@ -59,7 +59,7 @@ func (lc ListComputes) FilterByDiskID(diskID uint64) ListComputes {
}
// FilterByK8SID returns master and worker nodes (ListComputes) inside specified K8S cluster.
func (lc ListComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListComputes, error) {
func (lc ListComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListComputes, error) {
caller := k8s.New(decortClient)
req := k8s.GetRequest{
@@ -89,7 +89,9 @@ func (lc ListComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortCl
return false
}
return lc.FilterFunc(predicate), nil
result := lc.FilterFunc(predicate)
return &result, nil
}
// K8SMasters is used to filter master nodes. Best used after FilterByK8SID function.
@@ -121,7 +123,7 @@ func (lc ListComputes) FilterByK8SWorkers() ListComputes {
}
// FilterByLBID is used to filter ListComputes used by specified Load Balancer.
func (lc ListComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (ListComputes, error) {
func (lc ListComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (*ListComputes, error) {
caller := lb.New(decortClient)
req := lb.GetRequest{
@@ -137,28 +139,32 @@ func (lc ListComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClie
return ic.ID == foundLB.PrimaryNode.ComputeID || ic.ID == foundLB.SecondaryNode.ComputeID
}
return lc.FilterFunc(predicate), nil
result := lc.FilterFunc(predicate)
return &result, nil
}
// FilterFunc allows filtering ListComputes based on a user-specified predicate.
func (lc ListComputes) FilterFunc(predicate func(ItemCompute) bool) ListComputes {
var result ListComputes
for _, item := range lc {
for _, item := range lc.Data {
if predicate(item) {
result = append(result, item)
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemCompute
// If none was found, returns an empty struct.
func (lc ListComputes) FindOne() ItemCompute {
if len(lc) == 0 {
if len(lc.Data) == 0 {
return ItemCompute{}
}
return lc[0]
return lc.Data[0]
}

View File

@@ -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{
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,
},
},
{
Disks: []InfoDisk{
{
GUID: "",
Key: "antiaff_key",
Mode: "ANY",
Policy: "RECOMMENDED",
Topology: "compute",
Value: "antiaff_val",
ID: 65248,
PCISlot: 6,
},
},
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: 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,
},
},
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,
},
},
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
})
actual := computes.FilterFunc(func(ic ItemCompute) bool {
return ic.Registered == true
})
if len(actual) != 2 {
t.Fatal("expected 2 elements found, actual: ", len(actual))
}
if len(actual.Data) != 2 {
t.Fatal("expected 2 elements found, actual: ", len(actual.Data))
}
for _, item := range actual {
if item.Registered != true {
t.Fatal("expected Registered to be true, actual: ", item.Registered)
}
}
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)
}
}

View File

@@ -8,6 +8,46 @@ import (
// Request struct for get list available computes
type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by resource group name
// Required: false
RGName string `url:"rgName,omitempty" json:"rgName,omitempty"`
// Find by resource group ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by tech status
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by IP address
// Required: false
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
// Find by external network name
// Required: false
ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"`
// Find by external network ID
// Required: false
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
// Include deleted computes
// Required: false
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
@@ -23,7 +63,7 @@ type ListRequest struct {
// List gets list of the available computes.
// Filtering based on status is possible
func (c Compute) List(ctx context.Context, req ListRequest) (ListComputes, error) {
func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, error) {
url := "/cloudbroker/compute/list"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -38,5 +78,5 @@ func (c Compute) List(ctx context.Context, req ListRequest) (ListComputes, error
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -8,6 +8,42 @@ import (
// Request struct for get deleted computes list
type ListDeletedRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by resource group name
// Required: false
RGName string `url:"rgName,omitempty" json:"rgName,omitempty"`
// Find by resource group ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by tech status
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Find by IP address
// Required: false
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
// Find by external network name
// Required: false
ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"`
// Find by external network ID
// Required: false
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -18,7 +54,7 @@ type ListDeletedRequest struct {
}
// ListDeleted gets list all deleted computes
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListComputes, error) {
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListComputes, error) {
url := "/cloudbroker/compute/listDeleted"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -33,5 +69,5 @@ func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListC
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -13,10 +13,34 @@ type ListPCIDeviceRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Find by resource group ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by device id
// Required: false
DevID uint64 `url:"devId,omitempty" json:"devId,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"`
}
// ListPCIDevice gets list PCI device
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (ListPCIDevices, error) {
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (*ListPCIDevices, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -38,5 +62,5 @@ func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (L
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -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
}

View File

@@ -119,6 +119,9 @@ type RecordNetAttach struct {
// Default GW
DefGW string `json:"defGw"`
// Enabled
Enabled bool `json:"enabled"`
// FLIPGroup ID
FLIPGroupID uint64 `json:"flipgroupId"`
@@ -742,7 +745,13 @@ type InfoDisk struct {
}
// List computes
type ListComputes []ItemCompute
type ListComputes struct {
// Data
Data []ItemCompute `json:"data"`
// Entru Count
EntryCount uint64 `json:"entrycount"`
}
// Short information about audir
type ItemAudit struct {
@@ -796,4 +805,19 @@ type ItemPCIDevice struct {
}
// List PCI devices
type ListPCIDevices []ItemPCIDevice
type ListPCIDevices struct {
// Data
Data []ItemPCIDevice `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// List VGPUs
type ListVGPUs struct {
// Data
Data []interface{} `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -17,16 +17,16 @@ type ResizeRequest struct {
// New CPU count.
// Pass 0 if no change to CPU count is required
// Required: false
Force bool `url:"force,omitempty" json:"force,omitempty"`
CPU uint64 `url:"cpu,omitempty" json:"cpu,omitempty"`
// New RAM volume in MB.
// Pass 0 if no change to RAM volume is required
// Required: false
CPU uint64 `url:"cpu,omitempty" json:"cpu,omitempty"`
RAM uint64 `url:"ram,omitempty" json:"ram,omitempty"`
// Force compute resize
// Required: false
RAM uint64 `url:"ram,omitempty" json:"ram,omitempty"`
Force bool `url:"force,omitempty" json:"force,omitempty"`
// Reason for action
// Required: false

View File

@@ -12,7 +12,7 @@ import (
// - First argument -> prefix
// - Second argument -> indent
func (lc ListComputes) Serialize(params ...string) (serialization.Serialized, error) {
if len(lc) == 0 {
if len(lc.Data) == 0 {
return []byte{}, nil
}

View File

@@ -6,16 +6,16 @@ import "sort"
//
// If inverse param is set to true, the order is reversed.
func (lc ListComputes) SortByCPU(inverse bool) ListComputes {
if len(lc) < 2 {
if len(lc.Data) < 2 {
return lc
}
sort.Slice(lc, func(i, j int) bool {
sort.Slice(lc.Data, func(i, j int) bool {
if inverse {
return lc[i].CPUs > lc[j].CPUs
return lc.Data[i].CPUs > lc.Data[j].CPUs
}
return lc[i].CPUs < lc[j].CPUs
return lc.Data[i].CPUs < lc.Data[j].CPUs
})
return lc
@@ -25,16 +25,16 @@ func (lc ListComputes) SortByCPU(inverse bool) ListComputes {
//
// If inverse param is set to true, the order is reversed.
func (lc ListComputes) SortByRAM(inverse bool) ListComputes {
if len(lc) < 2 {
if len(lc.Data) < 2 {
return lc
}
sort.Slice(lc, func(i, j int) bool {
sort.Slice(lc.Data, func(i, j int) bool {
if inverse {
return lc[i].RAM > lc[j].RAM
return lc.Data[i].RAM > lc.Data[j].RAM
}
return lc[i].RAM < lc[j].RAM
return lc.Data[i].RAM < lc.Data[j].RAM
})
return lc
@@ -44,16 +44,16 @@ func (lc ListComputes) SortByRAM(inverse bool) ListComputes {
//
// If inverse param is set to true, the order is reversed.
func (lc ListComputes) SortByCreatedTime(inverse bool) ListComputes {
if len(lc) < 2 {
if len(lc.Data) < 2 {
return lc
}
sort.Slice(lc, func(i, j int) bool {
sort.Slice(lc.Data, func(i, j int) bool {
if inverse {
return lc[i].CreatedTime > lc[j].CreatedTime
return lc.Data[i].CreatedTime > lc.Data[j].CreatedTime
}
return lc[i].CreatedTime < lc[j].CreatedTime
return lc.Data[i].CreatedTime < lc.Data[j].CreatedTime
})
return lc
@@ -63,16 +63,16 @@ func (lc ListComputes) SortByCreatedTime(inverse bool) ListComputes {
//
// If inverse param is set to true, the order is reversed.
func (lc ListComputes) SortByUpdatedTime(inverse bool) ListComputes {
if len(lc) < 2 {
if len(lc.Data) < 2 {
return lc
}
sort.Slice(lc, func(i, j int) bool {
sort.Slice(lc.Data, func(i, j int) bool {
if inverse {
return lc[i].UpdatedTime > lc[j].UpdatedTime
return lc.Data[i].UpdatedTime > lc.Data[j].UpdatedTime
}
return lc[i].UpdatedTime < lc[j].UpdatedTime
return lc.Data[i].UpdatedTime < lc.Data[j].UpdatedTime
})
return lc
@@ -82,16 +82,16 @@ func (lc ListComputes) SortByUpdatedTime(inverse bool) ListComputes {
//
// If inverse param is set to true, the order is reversed.
func (lc ListComputes) SortByDeletedTime(inverse bool) ListComputes {
if len(lc) < 2 {
if len(lc.Data) < 2 {
return lc
}
sort.Slice(lc, func(i, j int) bool {
sort.Slice(lc.Data, func(i, j int) bool {
if inverse {
return lc[i].DeletedTime > lc[j].DeletedTime
return lc.Data[i].DeletedTime > lc.Data[j].DeletedTime
}
return lc[i].DeletedTime < lc[j].DeletedTime
return lc.Data[i].DeletedTime < lc.Data[j].DeletedTime
})
return lc