v1.5.0-gamma
This commit is contained in:
@@ -61,7 +61,7 @@ func (ld ListDisks) FilterByComputeID(computeID uint64) ListDisks {
|
||||
}
|
||||
|
||||
// FilterByK8SID is used to filter ListDisks by specified K8S cluster.
|
||||
func (ld ListDisks) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListDisks, error) {
|
||||
func (ld ListDisks) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListDisks, error) {
|
||||
caller := k8s.New(decortClient)
|
||||
|
||||
req := k8s.GetRequest{
|
||||
@@ -76,20 +76,22 @@ func (ld ListDisks) FilterByK8SID(ctx context.Context, k8sID uint64, decortClien
|
||||
var result ListDisks
|
||||
|
||||
for _, masterCompute := range cluster.K8SGroups.Masters.DetailedInfo {
|
||||
result = append(result, ld.FilterByComputeID(masterCompute.ID)...)
|
||||
result.Data = append(result.Data, ld.FilterByComputeID(masterCompute.ID).Data...)
|
||||
}
|
||||
|
||||
for _, workerGroup := range cluster.K8SGroups.Workers {
|
||||
for _, workerCompute := range workerGroup.DetailedInfo {
|
||||
result = append(result, ld.FilterByComputeID(workerCompute.ID)...)
|
||||
result.Data = append(result.Data, ld.FilterByComputeID(workerCompute.ID).Data...)
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// FilterByLBID is used to filter ListDisks used by computes inside specified Load Balancer.
|
||||
func (ld ListDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (ListDisks, error) {
|
||||
func (ld ListDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (*ListDisks, error) {
|
||||
caller := lb.New(decortClient)
|
||||
|
||||
req := lb.GetRequest{
|
||||
@@ -102,15 +104,141 @@ func (ld ListDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient
|
||||
}
|
||||
|
||||
var result ListDisks
|
||||
result.Data = append(result.Data, ld.FilterByComputeID(foundLB.PrimaryNode.ComputeID).Data...)
|
||||
result.Data = append(result.Data, ld.FilterByComputeID(foundLB.SecondaryNode.ComputeID).Data...)
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListDisks based on a user-specified predicate.
|
||||
func (ld ListDisks) FilterFunc(predicate func(ItemDisk) bool) ListDisks {
|
||||
var result ListDisks
|
||||
|
||||
for _, item := range ld.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemDisk
|
||||
// If none was found, returns an empty struct.
|
||||
func (ld ListDisks) FindOne() ItemDisk {
|
||||
if len(ld.Data) == 0 {
|
||||
return ItemDisk{}
|
||||
}
|
||||
|
||||
return ld.Data[0]
|
||||
}
|
||||
|
||||
// FilterByID returns ListSearchDisks with specified ID.
|
||||
func (ld ListSearchDisks) FilterByID(id uint64) ListSearchDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
return idisk.ID == id
|
||||
}
|
||||
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListSearchDisks with specified Name.
|
||||
func (ld ListSearchDisks) FilterByName(name string) ListSearchDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
return idisk.Name == name
|
||||
}
|
||||
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListSearchDisks with specified Status.
|
||||
func (ld ListSearchDisks) FilterByStatus(status string) ListSearchDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
return idisk.Status == status
|
||||
}
|
||||
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByTechStatus returns ListSearchDisks with specified TechStatus.
|
||||
func (ld ListSearchDisks) FilterByTechStatus(techStatus string) ListSearchDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
return idisk.TechStatus == techStatus
|
||||
}
|
||||
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByComputeID is used to filter ListSearchDisks attached to specified compute.
|
||||
func (ld ListSearchDisks) FilterByComputeID(computeID uint64) ListSearchDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
for k := range idisk.Computes {
|
||||
if k == strconv.FormatUint(computeID, 10) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByK8SID is used to filter ListSearchDisks by specified K8S cluster.
|
||||
func (ld ListSearchDisks) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListSearchDisks, error) {
|
||||
caller := k8s.New(decortClient)
|
||||
|
||||
req := k8s.GetRequest{
|
||||
K8SID: k8sID,
|
||||
}
|
||||
|
||||
cluster, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result ListSearchDisks
|
||||
|
||||
for _, masterCompute := range cluster.K8SGroups.Masters.DetailedInfo {
|
||||
result = append(result, ld.FilterByComputeID(masterCompute.ID)...)
|
||||
}
|
||||
|
||||
for _, workerGroup := range cluster.K8SGroups.Workers {
|
||||
for _, workerCompute := range workerGroup.DetailedInfo {
|
||||
result = append(result, ld.FilterByComputeID(workerCompute.ID)...)
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// FilterByLBID is used to filter ListSearchDisks used by computes inside specified Load Balancer.
|
||||
func (ld ListSearchDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (ListSearchDisks, error) {
|
||||
caller := lb.New(decortClient)
|
||||
|
||||
req := lb.GetRequest{
|
||||
LBID: lbID,
|
||||
}
|
||||
|
||||
foundLB, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result ListSearchDisks
|
||||
result = append(result, ld.FilterByComputeID(foundLB.PrimaryNode.ComputeID)...)
|
||||
result = append(result, ld.FilterByComputeID(foundLB.SecondaryNode.ComputeID)...)
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListDisks based on a user-specified predicate.
|
||||
func (ld ListDisks) FilterFunc(predicate func(ItemDisk) bool) ListDisks {
|
||||
var result ListDisks
|
||||
// FilterFunc allows filtering ListSearchDisks based on a user-specified predicate.
|
||||
func (ld ListSearchDisks) FilterFunc(predicate func(ItemDisk) bool) ListSearchDisks {
|
||||
var result ListSearchDisks
|
||||
|
||||
for _, item := range ld {
|
||||
if predicate(item) {
|
||||
@@ -123,7 +251,7 @@ func (ld ListDisks) FilterFunc(predicate func(ItemDisk) bool) ListDisks {
|
||||
|
||||
// FindOne returns first found ItemDisk
|
||||
// If none was found, returns an empty struct.
|
||||
func (ld ListDisks) FindOne() ItemDisk {
|
||||
func (ld ListSearchDisks) FindOne() ItemDisk {
|
||||
if len(ld) == 0 {
|
||||
return ItemDisk{}
|
||||
}
|
||||
@@ -171,21 +299,23 @@ func (lu ListDisksUnattached) FilterByTechStatus(techStatus string) ListDisksUna
|
||||
func (lu ListDisksUnattached) FilterFunc(predicate func(ItemDiskUnattached) bool) ListDisksUnattached {
|
||||
var result ListDisksUnattached
|
||||
|
||||
for _, item := range lu {
|
||||
for _, item := range lu.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 ItemDiskUnattached
|
||||
// If none was found, returns an empty struct.
|
||||
func (lu ListDisksUnattached) FindOne() ItemDiskUnattached {
|
||||
if len(lu) == 0 {
|
||||
if len(lu.Data) == 0 {
|
||||
return ItemDiskUnattached{}
|
||||
}
|
||||
|
||||
return lu[0]
|
||||
return lu.Data[0]
|
||||
}
|
||||
|
||||
@@ -4,7 +4,186 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var techStatusAllocated = "ALLOCATED"
|
||||
|
||||
var disks = ListDisks{
|
||||
Data: []ItemDisk{
|
||||
{
|
||||
MachineID: 0,
|
||||
MachineName: "",
|
||||
DeviceName: "vda",
|
||||
AccountID: 132847,
|
||||
AccountName: "std_2",
|
||||
ACL: map[string]interface{}{},
|
||||
Computes: map[string]string{
|
||||
"48500": "test",
|
||||
},
|
||||
CreatedTime: 1676975177,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
GID: 212,
|
||||
ID: 65191,
|
||||
ImageID: 9884,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
},
|
||||
Name: "bootdisk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
PCISlot: 6,
|
||||
Pool: "vmstor",
|
||||
PresentTo: []uint64{
|
||||
27,
|
||||
},
|
||||
PurgeTime: 0,
|
||||
ResID: "sample",
|
||||
ResName: "sample",
|
||||
Role: "",
|
||||
Shareable: false,
|
||||
SizeMax: 2,
|
||||
SizeUsed: 2,
|
||||
Snapshots: []ItemSnapshot{},
|
||||
Status: "ASSIGNED",
|
||||
TechStatus: techStatusAllocated,
|
||||
Type: "B",
|
||||
VMID: 48500,
|
||||
},
|
||||
{
|
||||
MachineID: 0,
|
||||
MachineName: "",
|
||||
DeviceName: "vda",
|
||||
AccountID: 132852,
|
||||
AccountName: "std",
|
||||
ACL: map[string]interface{}{},
|
||||
Computes: map[string]string{
|
||||
"48502": "stdvm2",
|
||||
},
|
||||
CreatedTime: 1676982606,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
GID: 212,
|
||||
ID: 65193,
|
||||
ImageID: 9885,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
},
|
||||
Name: "bootdisk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
PCISlot: 6,
|
||||
Pool: "vmstor",
|
||||
PresentTo: []uint64{
|
||||
27,
|
||||
27,
|
||||
},
|
||||
PurgeTime: 0,
|
||||
ResID: "sample",
|
||||
ResName: "sample",
|
||||
Role: "",
|
||||
Shareable: false,
|
||||
SizeMax: 4,
|
||||
SizeUsed: 4,
|
||||
Snapshots: []ItemSnapshot{},
|
||||
Status: "ASSIGNED",
|
||||
TechStatus: techStatusAllocated,
|
||||
Type: "B",
|
||||
VMID: 48502,
|
||||
},
|
||||
},
|
||||
EntryCount: 2,
|
||||
}
|
||||
|
||||
func TestListDisks_FilterByID(t *testing.T) {
|
||||
actual := disks.FilterByID(65193)
|
||||
|
||||
if len(actual.Data) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
actualItem := actual.FindOne()
|
||||
|
||||
if actualItem.ID != 65193 {
|
||||
t.Fatal("expected ID 65193, found: ", actualItem.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListDisks_FilterByName(t *testing.T) {
|
||||
actual := disks.FilterByName("bootdisk")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 elements, found: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Name != "bootdisk" {
|
||||
t.Fatal("expected 'bootdisk' name, found: ", item.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestListDisks_FilterByStatus(t *testing.T) {
|
||||
actual := disks.FilterByStatus("ASSIGNED")
|
||||
|
||||
if len(actual.Data) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "ASSIGNED" {
|
||||
t.Fatal("expected 'ASSIGNED' status, found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestListDisks_FilterByTechStatus(t *testing.T) {
|
||||
actual := disks.FilterByTechStatus(techStatusAllocated)
|
||||
|
||||
if len(actual.Data) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.TechStatus != techStatusAllocated {
|
||||
t.Fatal("expected 'ALLOCATED' techStatus, found: ", item.TechStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestListDisks_FilterFunc(t *testing.T) {
|
||||
actual := disks.FilterFunc(func(id ItemDisk) bool {
|
||||
return len(id.PresentTo) == 2
|
||||
})
|
||||
|
||||
if len(actual.Data) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
if len(actual.Data[0].PresentTo) != 2 {
|
||||
t.Fatal("expected 2 elements in PresentTo, found: ", len(actual.Data[0].PresentTo))
|
||||
}
|
||||
}
|
||||
|
||||
func TestListDisks_SortByCreatedTime(t *testing.T) {
|
||||
actual := disks.SortByCreatedTime(false)
|
||||
|
||||
if actual.Data[0].ID != 65191 {
|
||||
t.Fatal("expected ID 65191, found: ", actual.Data[0].ID)
|
||||
}
|
||||
|
||||
actual = disks.SortByCreatedTime(true)
|
||||
|
||||
if actual.Data[0].ID != 65193 {
|
||||
t.Fatal("expected ID 65193, found: ", actual.Data[0].ID)
|
||||
}
|
||||
}
|
||||
|
||||
var searchDisks = ListSearchDisks{
|
||||
ItemDisk{
|
||||
MachineID: 0,
|
||||
MachineName: "",
|
||||
@@ -44,7 +223,7 @@ var disks = ListDisks{
|
||||
SizeUsed: 2,
|
||||
Snapshots: []ItemSnapshot{},
|
||||
Status: "ASSIGNED",
|
||||
TechStatus: "ALLOCATED",
|
||||
TechStatus: techStatusAllocated,
|
||||
Type: "B",
|
||||
VMID: 48500,
|
||||
},
|
||||
@@ -88,14 +267,14 @@ var disks = ListDisks{
|
||||
SizeUsed: 4,
|
||||
Snapshots: []ItemSnapshot{},
|
||||
Status: "ASSIGNED",
|
||||
TechStatus: "ALLOCATED",
|
||||
TechStatus: techStatusAllocated,
|
||||
Type: "B",
|
||||
VMID: 48502,
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := disks.FilterByID(65193)
|
||||
func TestListSearchDisks_FilterByID(t *testing.T) {
|
||||
actual := searchDisks.FilterByID(65193)
|
||||
|
||||
if len(actual) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
@@ -108,8 +287,8 @@ func TestFilterByID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := disks.FilterByName("bootdisk")
|
||||
func TestListSearchDisks_FilterByName(t *testing.T) {
|
||||
actual := searchDisks.FilterByName("bootdisk")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 elements, found: ", len(actual))
|
||||
@@ -122,8 +301,8 @@ func TestFilterByName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := disks.FilterByStatus("ASSIGNED")
|
||||
func TestListSearchDisks_FilterByStatus(t *testing.T) {
|
||||
actual := searchDisks.FilterByStatus("ASSIGNED")
|
||||
|
||||
if len(actual) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
@@ -136,22 +315,22 @@ func TestFilterByStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByTechStatus(t *testing.T) {
|
||||
actual := disks.FilterByTechStatus("ALLOCATED")
|
||||
func TestListSearchDisks_FilterByTechStatus(t *testing.T) {
|
||||
actual := searchDisks.FilterByTechStatus(techStatusAllocated)
|
||||
|
||||
if len(actual) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.TechStatus != "ALLOCATED" {
|
||||
if item.TechStatus != techStatusAllocated {
|
||||
t.Fatal("expected 'ALLOCATED' techStatus, found: ", item.TechStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := disks.FilterFunc(func(id ItemDisk) bool {
|
||||
func TestListSearchDisks_FilterFunc(t *testing.T) {
|
||||
actual := searchDisks.FilterFunc(func(id ItemDisk) bool {
|
||||
return len(id.PresentTo) == 2
|
||||
})
|
||||
|
||||
@@ -164,14 +343,14 @@ func TestFilterFunc(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortByCreatedTime(t *testing.T) {
|
||||
actual := disks.SortByCreatedTime(false)
|
||||
func TestListSearchDisks_SortByCreatedTime(t *testing.T) {
|
||||
actual := searchDisks.SortByCreatedTime(false)
|
||||
|
||||
if actual[0].ID != 65191 {
|
||||
t.Fatal("expected ID 65191, found: ", actual[0].ID)
|
||||
}
|
||||
|
||||
actual = disks.SortByCreatedTime(true)
|
||||
actual = searchDisks.SortByCreatedTime(true)
|
||||
|
||||
if actual[0].ID != 65193 {
|
||||
t.Fatal("expected ID 65193, found: ", actual[0].ID)
|
||||
@@ -179,119 +358,122 @@ func TestSortByCreatedTime(t *testing.T) {
|
||||
}
|
||||
|
||||
var unattachedDisks = ListDisksUnattached{
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"cloudbroker",
|
||||
"disk",
|
||||
1,
|
||||
Data: []ItemDiskUnattached{
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"cloudbroker",
|
||||
"disk",
|
||||
1,
|
||||
},
|
||||
AccountID: 149,
|
||||
AccountName: "test_account1",
|
||||
ACL: map[string]interface{}{},
|
||||
BootPartition: 0,
|
||||
CreatedTime: 1681477547,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
DiskPath: "",
|
||||
GID: 2002,
|
||||
GUID: 22636,
|
||||
ID: 22636,
|
||||
ImageID: 0,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
},
|
||||
IQN: "",
|
||||
Login: "",
|
||||
Milestones: 43834,
|
||||
Name: "test_disk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
Password: "",
|
||||
PCISlot: -1,
|
||||
Pool: "data05",
|
||||
PresentTo: []uint64{},
|
||||
PurgeAttempts: 0,
|
||||
PurgeTime: 0,
|
||||
RealityDeviceNumber: 0,
|
||||
ReferenceID: "",
|
||||
ResID: "79bd3bd8-3424-48d3-963f-1870d506f169",
|
||||
ResName: "volumes/volume_22636",
|
||||
Role: "",
|
||||
SEPID: 1,
|
||||
Shareable: false,
|
||||
SizeMax: 0,
|
||||
SizeUsed: 0,
|
||||
Snapshots: nil,
|
||||
Status: "CREATED",
|
||||
TechStatus: techStatusAllocated,
|
||||
Type: "D",
|
||||
VMID: 0,
|
||||
},
|
||||
AccountID: 149,
|
||||
AccountName: "test_account1",
|
||||
ACL: map[string]interface{}{},
|
||||
BootPartition: 0,
|
||||
CreatedTime: 1681477547,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
DiskPath: "",
|
||||
GID: 2002,
|
||||
GUID: 22636,
|
||||
ID: 22636,
|
||||
ImageID: 0,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"cloudbroker",
|
||||
"disk",
|
||||
1,
|
||||
},
|
||||
AccountID: 150,
|
||||
AccountName: "test_account",
|
||||
ACL: map[string]interface{}{},
|
||||
BootPartition: 0,
|
||||
CreatedTime: 1681477558,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
DiskPath: "",
|
||||
GID: 2002,
|
||||
GUID: 22637,
|
||||
ID: 22637,
|
||||
ImageID: 0,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
},
|
||||
IQN: "",
|
||||
Login: "",
|
||||
Milestones: 43834,
|
||||
Name: "test_disk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
Password: "",
|
||||
PCISlot: -1,
|
||||
Pool: "data05",
|
||||
PresentTo: []uint64{
|
||||
27,
|
||||
27,
|
||||
},
|
||||
PurgeAttempts: 0,
|
||||
PurgeTime: 0,
|
||||
RealityDeviceNumber: 0,
|
||||
ReferenceID: "",
|
||||
ResID: "79bd3bd8-3424-48d3-963f-1870d506f169",
|
||||
ResName: "volumes/volume_22637",
|
||||
Role: "",
|
||||
SEPID: 1,
|
||||
Shareable: false,
|
||||
SizeMax: 0,
|
||||
SizeUsed: 0,
|
||||
Snapshots: nil,
|
||||
Status: "CREATED",
|
||||
TechStatus: techStatusAllocated,
|
||||
Type: "B",
|
||||
VMID: 0,
|
||||
},
|
||||
IQN: "",
|
||||
Login: "",
|
||||
Milestones: 43834,
|
||||
Name: "test_disk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
Password: "",
|
||||
PCISlot: -1,
|
||||
Pool: "data05",
|
||||
PresentTo: []uint64{},
|
||||
PurgeAttempts: 0,
|
||||
PurgeTime: 0,
|
||||
RealityDeviceNumber: 0,
|
||||
ReferenceID: "",
|
||||
ResID: "79bd3bd8-3424-48d3-963f-1870d506f169",
|
||||
ResName: "volumes/volume_22636",
|
||||
Role: "",
|
||||
SEPID: 1,
|
||||
Shareable: false,
|
||||
SizeMax: 0,
|
||||
SizeUsed: 0,
|
||||
Snapshots: nil,
|
||||
Status: "CREATED",
|
||||
TechStatus: "ALLOCATED",
|
||||
Type: "D",
|
||||
VMID: 0,
|
||||
},
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"cloudbroker",
|
||||
"disk",
|
||||
1,
|
||||
},
|
||||
AccountID: 150,
|
||||
AccountName: "test_account",
|
||||
ACL: map[string]interface{}{},
|
||||
BootPartition: 0,
|
||||
CreatedTime: 1681477558,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
DiskPath: "",
|
||||
GID: 2002,
|
||||
GUID: 22637,
|
||||
ID: 22637,
|
||||
ImageID: 0,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
},
|
||||
IQN: "",
|
||||
Login: "",
|
||||
Milestones: 43834,
|
||||
Name: "test_disk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
Password: "",
|
||||
PCISlot: -1,
|
||||
Pool: "data05",
|
||||
PresentTo: []uint64{
|
||||
27,
|
||||
27,
|
||||
},
|
||||
PurgeAttempts: 0,
|
||||
PurgeTime: 0,
|
||||
RealityDeviceNumber: 0,
|
||||
ReferenceID: "",
|
||||
ResID: "79bd3bd8-3424-48d3-963f-1870d506f169",
|
||||
ResName: "volumes/volume_22637",
|
||||
Role: "",
|
||||
SEPID: 1,
|
||||
Shareable: false,
|
||||
SizeMax: 0,
|
||||
SizeUsed: 0,
|
||||
Snapshots: nil,
|
||||
Status: "CREATED",
|
||||
TechStatus: "ALLOCATED",
|
||||
Type: "B",
|
||||
VMID: 0,
|
||||
},
|
||||
EntryCount: 2,
|
||||
}
|
||||
|
||||
func TestListDisksUnattached_FilterByID(t *testing.T) {
|
||||
actual := unattachedDisks.FilterByID(22636)
|
||||
|
||||
if len(actual) == 0 {
|
||||
if len(actual.Data) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
@@ -305,11 +487,11 @@ func TestListDisksUnattached_FilterByID(t *testing.T) {
|
||||
func TestListDisksUnattached_FilterByName(t *testing.T) {
|
||||
actual := unattachedDisks.FilterByName("test_disk")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 elements, found: ", len(actual))
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 elements, found: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.Name != "test_disk" {
|
||||
t.Fatal("expected 'test_disk' name, found: ", item.Name)
|
||||
}
|
||||
@@ -319,11 +501,11 @@ func TestListDisksUnattached_FilterByName(t *testing.T) {
|
||||
func TestListDisksUnattached_FilterByStatus(t *testing.T) {
|
||||
actual := unattachedDisks.FilterByStatus("CREATED")
|
||||
|
||||
if len(actual) == 0 {
|
||||
if len(actual.Data) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "CREATED" {
|
||||
t.Fatal("expected 'CREATED' status, found: ", item.Status)
|
||||
}
|
||||
@@ -331,14 +513,14 @@ func TestListDisksUnattached_FilterByStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListDisksUnattached_FilterByTechStatus(t *testing.T) {
|
||||
actual := unattachedDisks.FilterByTechStatus("ALLOCATED")
|
||||
actual := unattachedDisks.FilterByTechStatus(techStatusAllocated)
|
||||
|
||||
if len(actual) == 0 {
|
||||
if len(actual.Data) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.TechStatus != "ALLOCATED" {
|
||||
for _, item := range actual.Data {
|
||||
if item.TechStatus != techStatusAllocated {
|
||||
t.Fatal("expected 'ALLOCATED' techStatus, found: ", item.TechStatus)
|
||||
}
|
||||
}
|
||||
@@ -349,26 +531,26 @@ func TestListDisksUnattached_FilterFunc(t *testing.T) {
|
||||
return len(id.PresentTo) == 2
|
||||
})
|
||||
|
||||
if len(actual) == 0 {
|
||||
if len(actual.Data) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
if len(actual[0].PresentTo) != 2 {
|
||||
t.Fatal("expected 2 elements in PresentTo, found: ", len(actual[0].PresentTo))
|
||||
if len(actual.Data[0].PresentTo) != 2 {
|
||||
t.Fatal("expected 2 elements in PresentTo, found: ", len(actual.Data[0].PresentTo))
|
||||
}
|
||||
}
|
||||
|
||||
func TestListDisksUnattached_SortByCreatedTime(t *testing.T) {
|
||||
actual := unattachedDisks.SortByCreatedTime(false)
|
||||
|
||||
if actual[0].ID != 22636 {
|
||||
t.Fatal("expected ID 22636, found: ", actual[0].ID)
|
||||
if actual.Data[0].ID != 22636 {
|
||||
t.Fatal("expected ID 22636, found: ", actual.Data[0].ID)
|
||||
}
|
||||
|
||||
actual = unattachedDisks.SortByCreatedTime(true)
|
||||
|
||||
if actual[0].ID != 22637 {
|
||||
t.Fatal("expected ID 22637, found: ", actual[0].ID)
|
||||
if actual.Data[0].ID != 22637 {
|
||||
t.Fatal("expected ID 22637, found: ", actual.Data[0].ID)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,8 +6,32 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list/list_deleted of disks
|
||||
// Request struct for get list of disks
|
||||
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 name
|
||||
// Required: false
|
||||
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
|
||||
|
||||
// Find by max size disk
|
||||
// Required: false
|
||||
DiskMaxSize int64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by shared, true or false
|
||||
// Required: false
|
||||
Shared bool `url:"shared,omitempty" json:"shared,omitempty"`
|
||||
|
||||
// ID of the account the disks belong to
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
@@ -26,7 +50,7 @@ type ListRequest struct {
|
||||
}
|
||||
|
||||
// List gets list the created disks belonging to an account
|
||||
func (d Disks) List(ctx context.Context, req ListRequest) (ListDisks, error) {
|
||||
func (d Disks) List(ctx context.Context, req ListRequest) (*ListDisks, error) {
|
||||
url := "/cloudapi/disks/list"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -41,24 +65,5 @@ func (d Disks) List(ctx context.Context, req ListRequest) (ListDisks, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// ListDeleted gets list the deleted disks belonging to an account
|
||||
func (d Disks) ListDeleted(ctx context.Context, req ListRequest) (ListDisks, error) {
|
||||
url := "/cloudapi/disks/listDeleted"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
45
pkg/cloudapi/disks/list_deleted.go
Normal file
45
pkg/cloudapi/disks/list_deleted.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list of deleted disks
|
||||
type ListDeletedRequest struct {
|
||||
// ID of the account the disks belong to
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Type of the disks
|
||||
// Required: false
|
||||
Type string `url:"type,omitempty" json:"type,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"`
|
||||
}
|
||||
|
||||
// ListDeleted gets list the deleted disks belonging to an account
|
||||
func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListDisks, error) {
|
||||
url := "/cloudapi/disks/listDeleted"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
@@ -8,13 +8,45 @@ import (
|
||||
|
||||
// Request struct for get list unattached disk
|
||||
type ListUnattachedRequest struct {
|
||||
// Find by id
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by account name
|
||||
// Required: false
|
||||
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
|
||||
|
||||
// Find by max size disk
|
||||
// Required: false
|
||||
DiskMaxSize int64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by shared, true or false
|
||||
// Required: false
|
||||
Shared bool `url:"shared,omitempty" json:"shared,omitempty"`
|
||||
|
||||
// Type of the disks
|
||||
// Required: false
|
||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||
|
||||
// ID of the account
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,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"`
|
||||
}
|
||||
|
||||
// ListUnattached gets list of unattached disks
|
||||
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (ListDisksUnattached, error) {
|
||||
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (*ListDisksUnattached, error) {
|
||||
url := "/cloudapi/disks/listUnattached"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -29,5 +61,5 @@ func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (L
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -248,11 +248,24 @@ type ItemDiskUnattached struct {
|
||||
VMID uint64 `json:"vmid"`
|
||||
}
|
||||
|
||||
// List of disks searched
|
||||
type ListSearchDisks []ItemDisk
|
||||
|
||||
// List of disks
|
||||
type ListDisks []ItemDisk
|
||||
type ListDisks struct {
|
||||
// Data
|
||||
Data []ItemDisk `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// List of unattached disks
|
||||
type ListDisksUnattached []ItemDiskUnattached
|
||||
type ListDisksUnattached struct {
|
||||
Data []ItemDiskUnattached `json:"data"`
|
||||
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about snapshot
|
||||
type ItemSnapshot struct {
|
||||
@@ -262,6 +275,8 @@ type ItemSnapshot struct {
|
||||
// Label
|
||||
Label string `json:"label"`
|
||||
|
||||
ReferenceID string `json:"referenceId"`
|
||||
|
||||
// Resource ID
|
||||
ResID string `json:"resId"`
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ type SearchRequest struct {
|
||||
}
|
||||
|
||||
// Search search disks
|
||||
func (d Disks) Search(ctx context.Context, req SearchRequest) (ListDisks, error) {
|
||||
func (d Disks) Search(ctx context.Context, req SearchRequest) (ListSearchDisks, error) {
|
||||
url := "/cloudapi/disks/search"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -29,7 +29,7 @@ func (d Disks) Search(ctx context.Context, req SearchRequest) (ListDisks, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListDisks{}
|
||||
list := ListSearchDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,6 +12,26 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ld ListDisks) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if ld.EntryCount == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ld, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ld)
|
||||
}
|
||||
|
||||
// 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 (ld ListSearchDisks) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(ld) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
@@ -48,7 +68,7 @@ func (idisk ItemDisk) Serialize(params ...string) (serialization.Serialized, err
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lu ListDisksUnattached) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lu) == 0 {
|
||||
if lu.EntryCount == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,63 @@ import "sort"
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListDisks) SortByCreatedTime(inverse bool) ListDisks {
|
||||
if len(ld.Data) < 2 {
|
||||
return ld
|
||||
}
|
||||
|
||||
sort.Slice(ld.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ld.Data[i].CreatedTime > ld.Data[j].CreatedTime
|
||||
}
|
||||
|
||||
return ld.Data[i].CreatedTime < ld.Data[j].CreatedTime
|
||||
})
|
||||
|
||||
return ld
|
||||
}
|
||||
|
||||
// SortByDestructionTime sorts ListDisks by the DestructionTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListDisks) SortByDestructionTime(inverse bool) ListDisks {
|
||||
if len(ld.Data) < 2 {
|
||||
return ld
|
||||
}
|
||||
|
||||
sort.Slice(ld.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ld.Data[i].DestructionTime > ld.Data[j].DestructionTime
|
||||
}
|
||||
|
||||
return ld.Data[i].DestructionTime < ld.Data[j].DestructionTime
|
||||
})
|
||||
|
||||
return ld
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListDisks by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListDisks) SortByDeletedTime(inverse bool) ListDisks {
|
||||
if len(ld.Data) < 2 {
|
||||
return ld
|
||||
}
|
||||
|
||||
sort.Slice(ld.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ld.Data[i].DeletedTime > ld.Data[j].DeletedTime
|
||||
}
|
||||
|
||||
return ld.Data[i].DeletedTime < ld.Data[j].DeletedTime
|
||||
})
|
||||
|
||||
return ld
|
||||
}
|
||||
|
||||
// SortByCreatedTime sorts ListSearchDisks by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListSearchDisks) SortByCreatedTime(inverse bool) ListSearchDisks {
|
||||
if len(ld) < 2 {
|
||||
return ld
|
||||
}
|
||||
@@ -21,10 +78,10 @@ func (ld ListDisks) SortByCreatedTime(inverse bool) ListDisks {
|
||||
return ld
|
||||
}
|
||||
|
||||
// SortByDestructionTime sorts ListDisks by the DestructionTime field in ascending order.
|
||||
// SortByDestructionTime sorts ListSearchDisks by the DestructionTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListDisks) SortByDestructionTime(inverse bool) ListDisks {
|
||||
func (ld ListSearchDisks) SortByDestructionTime(inverse bool) ListSearchDisks {
|
||||
if len(ld) < 2 {
|
||||
return ld
|
||||
}
|
||||
@@ -40,10 +97,10 @@ func (ld ListDisks) SortByDestructionTime(inverse bool) ListDisks {
|
||||
return ld
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListDisks by the DeletedTime field in ascending order.
|
||||
// SortByDeletedTime sorts ListSearchDisks by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListDisks) SortByDeletedTime(inverse bool) ListDisks {
|
||||
func (ld ListSearchDisks) SortByDeletedTime(inverse bool) ListSearchDisks {
|
||||
if len(ld) < 2 {
|
||||
return ld
|
||||
}
|
||||
@@ -63,16 +120,16 @@ func (ld ListDisks) SortByDeletedTime(inverse bool) ListDisks {
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lu ListDisksUnattached) SortByCreatedTime(inverse bool) ListDisksUnattached {
|
||||
if len(lu) < 2 {
|
||||
if len(lu.Data) < 2 {
|
||||
return lu
|
||||
}
|
||||
|
||||
sort.Slice(lu, func(i, j int) bool {
|
||||
sort.Slice(lu.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lu[i].CreatedTime > lu[j].CreatedTime
|
||||
return lu.Data[i].CreatedTime > lu.Data[j].CreatedTime
|
||||
}
|
||||
|
||||
return lu[i].CreatedTime < lu[j].CreatedTime
|
||||
return lu.Data[i].CreatedTime < lu.Data[j].CreatedTime
|
||||
})
|
||||
|
||||
return lu
|
||||
@@ -82,16 +139,16 @@ func (lu ListDisksUnattached) SortByCreatedTime(inverse bool) ListDisksUnattache
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lu ListDisksUnattached) SortByDestructionTime(inverse bool) ListDisksUnattached {
|
||||
if len(lu) < 2 {
|
||||
if len(lu.Data) < 2 {
|
||||
return lu
|
||||
}
|
||||
|
||||
sort.Slice(lu, func(i, j int) bool {
|
||||
sort.Slice(lu.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lu[i].DestructionTime > lu[j].DestructionTime
|
||||
return lu.Data[i].DestructionTime > lu.Data[j].DestructionTime
|
||||
}
|
||||
|
||||
return lu[i].DestructionTime < lu[j].DestructionTime
|
||||
return lu.Data[i].DestructionTime < lu.Data[j].DestructionTime
|
||||
})
|
||||
|
||||
return lu
|
||||
@@ -101,16 +158,16 @@ func (lu ListDisksUnattached) SortByDestructionTime(inverse bool) ListDisksUnatt
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lu ListDisksUnattached) SortByDeletedTime(inverse bool) ListDisksUnattached {
|
||||
if len(lu) < 2 {
|
||||
if len(lu.Data) < 2 {
|
||||
return lu
|
||||
}
|
||||
|
||||
sort.Slice(lu, func(i, j int) bool {
|
||||
sort.Slice(lu.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lu[i].DeletedTime > lu[j].DeletedTime
|
||||
return lu.Data[i].DeletedTime > lu.Data[j].DeletedTime
|
||||
}
|
||||
|
||||
return lu[i].DeletedTime < lu[j].DeletedTime
|
||||
return lu.Data[i].DeletedTime < lu.Data[j].DeletedTime
|
||||
})
|
||||
|
||||
return lu
|
||||
|
||||
Reference in New Issue
Block a user