v1.5.0-gamma2
This commit is contained in:
@@ -70,7 +70,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{
|
||||
@@ -85,20 +85,20 @@ 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
|
||||
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{
|
||||
@@ -111,31 +111,33 @@ func (ld ListDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient
|
||||
}
|
||||
|
||||
var result ListDisks
|
||||
result = append(result, ld.FilterByComputeID(foundLB.PrimaryNode.ComputeID)...)
|
||||
result = append(result, ld.FilterByComputeID(foundLB.SecondaryNode.ComputeID)...)
|
||||
result.Data = append(result.Data, ld.FilterByComputeID(foundLB.PrimaryNode.ComputeID).Data...)
|
||||
result.Data = append(result.Data, ld.FilterByComputeID(foundLB.SecondaryNode.ComputeID).Data...)
|
||||
|
||||
return result, nil
|
||||
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 {
|
||||
for _, item := range ld.Data {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(ld.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemDisk
|
||||
// If none was found, returns an empty struct.
|
||||
func (ld ListDisks) FindOne() ItemDisk {
|
||||
if len(ld) == 0 {
|
||||
if len(ld.Data) == 0 {
|
||||
return ItemDisk{}
|
||||
}
|
||||
|
||||
return ld[0]
|
||||
return ld.Data[0]
|
||||
}
|
||||
|
||||
@@ -3,131 +3,134 @@ package disks
|
||||
import "testing"
|
||||
|
||||
var disks = ListDisks{
|
||||
ItemDisk{
|
||||
MachineID: 0,
|
||||
MachineName: "",
|
||||
RecordDisk: RecordDisk{
|
||||
DeviceName: "vda",
|
||||
SEPType: "",
|
||||
InfoDisk: InfoDisk{
|
||||
AccountID: 132847,
|
||||
AccountName: "std_2",
|
||||
ACL: map[string]interface{}{},
|
||||
BootPartition: 0,
|
||||
Computes: map[string]string{
|
||||
"48500": "test",
|
||||
Data: []ItemDisk{
|
||||
{
|
||||
MachineID: 0,
|
||||
MachineName: "",
|
||||
RecordDisk: RecordDisk{
|
||||
DeviceName: "vda",
|
||||
SEPType: "",
|
||||
InfoDisk: InfoDisk{
|
||||
AccountID: 132847,
|
||||
AccountName: "std_2",
|
||||
ACL: map[string]interface{}{},
|
||||
BootPartition: 0,
|
||||
Computes: map[string]string{
|
||||
"48500": "test",
|
||||
},
|
||||
CreatedTime: 1676975177,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
DiskPath: "",
|
||||
GID: 212,
|
||||
GUID: 65191,
|
||||
ID: 65191,
|
||||
ImageID: 9884,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
},
|
||||
IQN: "",
|
||||
Login: "",
|
||||
Milestones: 363501,
|
||||
Name: "bootdisk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
Password: "",
|
||||
PCISlot: 6,
|
||||
Pool: "vmstor",
|
||||
PresentTo: []uint64{
|
||||
27,
|
||||
},
|
||||
PurgeAttempts: 0,
|
||||
PurgeTime: 0,
|
||||
RealityDeviceNumber: 0,
|
||||
ReferenceID: "sample",
|
||||
ResID: "sample",
|
||||
ResName: "sample",
|
||||
Role: "",
|
||||
SEPID: 2504,
|
||||
Shareable: false,
|
||||
SizeMax: 2,
|
||||
SizeUsed: 2,
|
||||
Snapshots: []ItemSnapshot{},
|
||||
Status: "ASSIGNED",
|
||||
TechStatus: "ALLOCATED",
|
||||
Type: "B",
|
||||
VMID: 48500,
|
||||
},
|
||||
CreatedTime: 1676975177,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
DiskPath: "",
|
||||
GID: 212,
|
||||
GUID: 65191,
|
||||
ID: 65191,
|
||||
ImageID: 9884,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
},
|
||||
},
|
||||
{
|
||||
MachineID: 0,
|
||||
MachineName: "",
|
||||
RecordDisk: RecordDisk{
|
||||
DeviceName: "vda",
|
||||
SEPType: "",
|
||||
InfoDisk: InfoDisk{
|
||||
AccountID: 132852,
|
||||
AccountName: "std",
|
||||
ACL: map[string]interface{}{},
|
||||
BootPartition: 0,
|
||||
Computes: map[string]string{
|
||||
"48502": "stdvm2",
|
||||
},
|
||||
CreatedTime: 1676982606,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
DiskPath: "",
|
||||
GID: 212,
|
||||
GUID: 65193,
|
||||
ID: 65193,
|
||||
ImageID: 9885,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
},
|
||||
IQN: "",
|
||||
Login: "",
|
||||
Milestones: 363516,
|
||||
Name: "bootdisk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
Password: "",
|
||||
PCISlot: 6,
|
||||
Pool: "vmstor",
|
||||
PresentTo: []uint64{
|
||||
27,
|
||||
27,
|
||||
},
|
||||
PurgeAttempts: 0,
|
||||
PurgeTime: 0,
|
||||
RealityDeviceNumber: 0,
|
||||
ReferenceID: "sample",
|
||||
ResID: "sample",
|
||||
ResName: "sample",
|
||||
Role: "",
|
||||
SEPID: 2504,
|
||||
Shareable: false,
|
||||
SizeMax: 4,
|
||||
SizeUsed: 4,
|
||||
Snapshots: []ItemSnapshot{},
|
||||
Status: "ASSIGNED",
|
||||
TechStatus: "ALLOCATED",
|
||||
Type: "B",
|
||||
VMID: 48502,
|
||||
},
|
||||
IQN: "",
|
||||
Login: "",
|
||||
Milestones: 363501,
|
||||
Name: "bootdisk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
Password: "",
|
||||
PCISlot: 6,
|
||||
Pool: "vmstor",
|
||||
PresentTo: []uint64{
|
||||
27,
|
||||
},
|
||||
PurgeAttempts: 0,
|
||||
PurgeTime: 0,
|
||||
RealityDeviceNumber: 0,
|
||||
ReferenceID: "sample",
|
||||
ResID: "sample",
|
||||
ResName: "sample",
|
||||
Role: "",
|
||||
SEPID: 2504,
|
||||
Shareable: false,
|
||||
SizeMax: 2,
|
||||
SizeUsed: 2,
|
||||
Snapshots: []ItemSnapshot{},
|
||||
Status: "ASSIGNED",
|
||||
TechStatus: "ALLOCATED",
|
||||
Type: "B",
|
||||
VMID: 48500,
|
||||
},
|
||||
},
|
||||
},
|
||||
ItemDisk{
|
||||
MachineID: 0,
|
||||
MachineName: "",
|
||||
RecordDisk: RecordDisk{
|
||||
DeviceName: "vda",
|
||||
SEPType: "",
|
||||
InfoDisk: InfoDisk{
|
||||
AccountID: 132852,
|
||||
AccountName: "std",
|
||||
ACL: map[string]interface{}{},
|
||||
BootPartition: 0,
|
||||
Computes: map[string]string{
|
||||
"48502": "stdvm2",
|
||||
},
|
||||
CreatedTime: 1676982606,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
DiskPath: "",
|
||||
GID: 212,
|
||||
GUID: 65193,
|
||||
ID: 65193,
|
||||
ImageID: 9885,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
},
|
||||
IQN: "",
|
||||
Login: "",
|
||||
Milestones: 363516,
|
||||
Name: "bootdisk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
Password: "",
|
||||
PCISlot: 6,
|
||||
Pool: "vmstor",
|
||||
PresentTo: []uint64{
|
||||
27,
|
||||
27,
|
||||
},
|
||||
PurgeAttempts: 0,
|
||||
PurgeTime: 0,
|
||||
RealityDeviceNumber: 0,
|
||||
ReferenceID: "sample",
|
||||
ResID: "sample",
|
||||
ResName: "sample",
|
||||
Role: "",
|
||||
SEPID: 2504,
|
||||
Shareable: false,
|
||||
SizeMax: 4,
|
||||
SizeUsed: 4,
|
||||
Snapshots: []ItemSnapshot{},
|
||||
Status: "ASSIGNED",
|
||||
TechStatus: "ALLOCATED",
|
||||
Type: "B",
|
||||
VMID: 48502,
|
||||
},
|
||||
},
|
||||
},
|
||||
EntryCount: 2,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := disks.FilterByID(65193)
|
||||
|
||||
if len(actual) == 0 {
|
||||
if len(actual.Data) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
@@ -141,11 +144,11 @@ func TestFilterByID(t *testing.T) {
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := disks.FilterByName("bootdisk")
|
||||
|
||||
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 != "bootdisk" {
|
||||
t.Fatal("expected 'bootdisk' name, found: ", item.Name)
|
||||
}
|
||||
@@ -155,11 +158,11 @@ func TestFilterByName(t *testing.T) {
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := disks.FilterByStatus("ASSIGNED")
|
||||
|
||||
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 != "ASSIGNED" {
|
||||
t.Fatal("expected 'ASSIGNED' status, found: ", item.Status)
|
||||
}
|
||||
@@ -169,11 +172,11 @@ func TestFilterByStatus(t *testing.T) {
|
||||
func TestFilterByTechStatus(t *testing.T) {
|
||||
actual := disks.FilterByTechStatus("ALLOCATED")
|
||||
|
||||
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.TechStatus != "ALLOCATED" {
|
||||
t.Fatal("expected 'ALLOCATED' techStatus, found: ", item.TechStatus)
|
||||
}
|
||||
@@ -183,12 +186,12 @@ func TestFilterByTechStatus(t *testing.T) {
|
||||
func TestFilterByImageID(t *testing.T) {
|
||||
actual := disks.FilterByImageID(9885)
|
||||
|
||||
if len(actual) == 0 {
|
||||
if len(actual.Data) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
if actual[0].ImageID != 9885 {
|
||||
t.Fatal("expected 9885 ImageID, found: ", actual[0].ImageID)
|
||||
if actual.Data[0].ImageID != 9885 {
|
||||
t.Fatal("expected 9885 ImageID, found: ", actual.Data[0].ImageID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,25 +200,25 @@ func TestFilterFunc(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 TestSortByCreatedTime(t *testing.T) {
|
||||
actual := disks.SortByCreatedTime(false)
|
||||
|
||||
if actual[0].ID != 65191 {
|
||||
t.Fatal("expected ID 65191, found: ", actual[0].ID)
|
||||
if actual.Data[0].ID != 65191 {
|
||||
t.Fatal("expected ID 65191, found: ", actual.Data[0].ID)
|
||||
}
|
||||
|
||||
actual = disks.SortByCreatedTime(true)
|
||||
|
||||
if actual[0].ID != 65193 {
|
||||
t.Fatal("expected ID 65193, found: ", actual[0].ID)
|
||||
if actual.Data[0].ID != 65193 {
|
||||
t.Fatal("expected ID 65193, found: ", actual.Data[0].ID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,30 @@ import (
|
||||
|
||||
// Request struct for get list/list_deleted 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 := "/cloudbroker/disks/list"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -41,5 +65,5 @@ func (d Disks) List(ctx context.Context, req ListRequest) (ListDisks, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -8,6 +8,26 @@ import (
|
||||
|
||||
// Request struct for get list deleted disks
|
||||
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 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 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 +46,7 @@ type ListDeletedRequest struct {
|
||||
}
|
||||
|
||||
// ListDeleted gets list the deleted disks based on filter
|
||||
func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDeletedDisks, error) {
|
||||
func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListDisks, error) {
|
||||
url := "/cloudbroker/disks/listDeleted"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -34,12 +54,12 @@ func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDel
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListDeletedDisks{}
|
||||
list := ListDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -11,12 +11,20 @@ import (
|
||||
// Request struct for get list types of disks
|
||||
type ListTypesRequest struct {
|
||||
// Show detailed disk types by seps
|
||||
// Required: true
|
||||
Detailed bool `url:"detailed" json:"detailed" validate:"required"`
|
||||
// Required: false
|
||||
Detailed bool `url:"detailed" json:"detailed"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListTypes gets list defined disk types
|
||||
func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface{}, error) {
|
||||
func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) (*ListTypes, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -31,13 +39,13 @@ func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]interface{}, 0)
|
||||
list := ListTypes{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,30 @@ 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"`
|
||||
@@ -22,7 +46,7 @@ type ListUnattachedRequest struct {
|
||||
}
|
||||
|
||||
// ListUnattached gets list of unattached disks
|
||||
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (ListUnattachedDisks, error) {
|
||||
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (*ListUnattachedDisks, error) {
|
||||
url := "/cloudbroker/disks/listUnattached"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -37,5 +61,5 @@ func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (L
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -199,28 +199,16 @@ type ItemDisk struct {
|
||||
}
|
||||
|
||||
// List disks
|
||||
type ListDisks []ItemDisk
|
||||
type ListDisks struct {
|
||||
// Data
|
||||
Data []ItemDisk `json:"data"`
|
||||
|
||||
// Main information about deleted disk
|
||||
type ItemDeletedDisk struct {
|
||||
// Machine ID
|
||||
MachineID uint64 `json:"machineId"`
|
||||
|
||||
// Machine name
|
||||
MachineName string `json:"machineName"`
|
||||
|
||||
// Detailed information about disk
|
||||
RecordDisk
|
||||
|
||||
// Updated by
|
||||
UpdatedBy uint64 `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// List deleted disks
|
||||
type ListDeletedDisks []ItemDeletedDisk
|
||||
// ListSearchDisks
|
||||
type SearchListDisks []ItemDisk
|
||||
|
||||
// Main information about unattached disk
|
||||
type ItemUnattachedDisk struct {
|
||||
@@ -241,7 +229,13 @@ type ItemUnattachedDisk struct {
|
||||
}
|
||||
|
||||
// List unattached disks
|
||||
type ListUnattachedDisks []ItemUnattachedDisk
|
||||
type ListUnattachedDisks struct {
|
||||
// Data
|
||||
Data []ItemUnattachedDisk `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about snapshot
|
||||
type ItemSnapshot struct {
|
||||
@@ -269,3 +263,11 @@ type ItemSnapshot struct {
|
||||
|
||||
// List snapshots
|
||||
type ListSnapshots []ItemSnapshot
|
||||
|
||||
type ListTypes struct {
|
||||
// Data
|
||||
Data []interface{} `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
@@ -29,7 +29,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) (SearchListDisks, error) {
|
||||
url := "/cloudbroker/disks/search"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -37,7 +37,7 @@ func (d Disks) Search(ctx context.Context, req SearchRequest) (ListDisks, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListDisks{}
|
||||
list := SearchListDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ld ListDisks) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(ld) == 0 {
|
||||
if len(ld.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -6,16 +6,16 @@ import "sort"
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListDisks) SortByCreatedTime(inverse bool) ListDisks {
|
||||
if len(ld) < 2 {
|
||||
if len(ld.Data) < 2 {
|
||||
return ld
|
||||
}
|
||||
|
||||
sort.Slice(ld, func(i, j int) bool {
|
||||
sort.Slice(ld.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ld[i].CreatedTime > ld[j].CreatedTime
|
||||
return ld.Data[i].CreatedTime > ld.Data[j].CreatedTime
|
||||
}
|
||||
|
||||
return ld[i].CreatedTime < ld[j].CreatedTime
|
||||
return ld.Data[i].CreatedTime < ld.Data[j].CreatedTime
|
||||
})
|
||||
|
||||
return ld
|
||||
@@ -25,16 +25,16 @@ func (ld ListDisks) SortByCreatedTime(inverse bool) ListDisks {
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListDisks) SortByDestructionTime(inverse bool) ListDisks {
|
||||
if len(ld) < 2 {
|
||||
if len(ld.Data) < 2 {
|
||||
return ld
|
||||
}
|
||||
|
||||
sort.Slice(ld, func(i, j int) bool {
|
||||
sort.Slice(ld.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ld[i].DestructionTime > ld[j].DestructionTime
|
||||
return ld.Data[i].DestructionTime > ld.Data[j].DestructionTime
|
||||
}
|
||||
|
||||
return ld[i].DestructionTime < ld[j].DestructionTime
|
||||
return ld.Data[i].DestructionTime < ld.Data[j].DestructionTime
|
||||
})
|
||||
|
||||
return ld
|
||||
@@ -44,16 +44,16 @@ func (ld ListDisks) SortByDestructionTime(inverse bool) ListDisks {
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListDisks) SortByDeletedTime(inverse bool) ListDisks {
|
||||
if len(ld) < 2 {
|
||||
if len(ld.Data) < 2 {
|
||||
return ld
|
||||
}
|
||||
|
||||
sort.Slice(ld, func(i, j int) bool {
|
||||
sort.Slice(ld.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ld[i].DeletedTime > ld[j].DeletedTime
|
||||
return ld.Data[i].DeletedTime > ld.Data[j].DeletedTime
|
||||
}
|
||||
|
||||
return ld[i].DeletedTime < ld[j].DeletedTime
|
||||
return ld.Data[i].DeletedTime < ld.Data[j].DeletedTime
|
||||
})
|
||||
|
||||
return ld
|
||||
|
||||
Reference in New Issue
Block a user