v1.5.0-gamma2
This commit is contained in:
@@ -40,21 +40,23 @@ func (li ListImages) FilterByBootType(bootType string) ListImages {
|
||||
func (li ListImages) FilterFunc(predicate func(ItemImage) bool) ListImages {
|
||||
var result ListImages
|
||||
|
||||
for _, item := range li {
|
||||
for _, item := range li.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 ItemImage
|
||||
// If none was found, returns an empty struct.
|
||||
func (li ListImages) FindOne() ItemImage {
|
||||
if len(li) == 0 {
|
||||
if len(li.Data) == 0 {
|
||||
return ItemImage{}
|
||||
}
|
||||
|
||||
return li[0]
|
||||
return li.Data[0]
|
||||
}
|
||||
|
||||
@@ -3,66 +3,69 @@ package image
|
||||
import "testing"
|
||||
|
||||
var images = ListImages{
|
||||
ItemImage{
|
||||
AccountID: 0,
|
||||
Architecture: "X86_64",
|
||||
BootType: "bios",
|
||||
Bootable: true,
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
Data: []ItemImage{
|
||||
{
|
||||
AccountID: 0,
|
||||
Architecture: "X86_64",
|
||||
BootType: "bios",
|
||||
Bootable: true,
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
},
|
||||
HotResize: true,
|
||||
ID: 9882,
|
||||
LinkTo: 0,
|
||||
Name: "u16",
|
||||
Pool: "vmstor",
|
||||
Size: 5,
|
||||
Status: "CREATED",
|
||||
Type: "linux",
|
||||
Username: "",
|
||||
Virtual: false,
|
||||
},
|
||||
HotResize: true,
|
||||
ID: 9882,
|
||||
LinkTo: 0,
|
||||
Name: "u16",
|
||||
Pool: "vmstor",
|
||||
Size: 5,
|
||||
Status: "CREATED",
|
||||
Type: "linux",
|
||||
Username: "",
|
||||
Virtual: false,
|
||||
},
|
||||
ItemImage{
|
||||
AccountID: 0,
|
||||
Architecture: "X86_64",
|
||||
BootType: "bois",
|
||||
Bootable: true,
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
{
|
||||
AccountID: 0,
|
||||
Architecture: "X86_64",
|
||||
BootType: "bois",
|
||||
Bootable: true,
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
},
|
||||
HotResize: false,
|
||||
ID: 9884,
|
||||
LinkTo: 0,
|
||||
Name: "alpine-virt-3.17",
|
||||
Pool: "vmstor",
|
||||
Size: 1,
|
||||
Status: "CREATED",
|
||||
Type: "linux",
|
||||
Username: "",
|
||||
Virtual: true,
|
||||
},
|
||||
HotResize: false,
|
||||
ID: 9884,
|
||||
LinkTo: 0,
|
||||
Name: "alpine-virt-3.17",
|
||||
Pool: "vmstor",
|
||||
Size: 1,
|
||||
Status: "CREATED",
|
||||
Type: "linux",
|
||||
Username: "",
|
||||
Virtual: true,
|
||||
},
|
||||
ItemImage{
|
||||
AccountID: 1,
|
||||
Architecture: "X86_64",
|
||||
BootType: "bios",
|
||||
Bootable: true,
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
{
|
||||
AccountID: 1,
|
||||
Architecture: "X86_64",
|
||||
BootType: "bios",
|
||||
Bootable: true,
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
},
|
||||
HotResize: true,
|
||||
ID: 9885,
|
||||
LinkTo: 0,
|
||||
Name: "test",
|
||||
Pool: "vmstor",
|
||||
Size: 4,
|
||||
Status: "DESTROYED",
|
||||
Type: "linux",
|
||||
Username: "",
|
||||
Virtual: false,
|
||||
},
|
||||
HotResize: true,
|
||||
ID: 9885,
|
||||
LinkTo: 0,
|
||||
Name: "test",
|
||||
Pool: "vmstor",
|
||||
Size: 4,
|
||||
Status: "DESTROYED",
|
||||
Type: "linux",
|
||||
Username: "",
|
||||
Virtual: false,
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
@@ -84,11 +87,11 @@ func TestFilterByName(t *testing.T) {
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := images.FilterByStatus("CREATED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "CREATED" {
|
||||
t.Fatal("expected Status 'CREATED', found: ", item.Status)
|
||||
}
|
||||
@@ -98,11 +101,11 @@ func TestFilterByStatus(t *testing.T) {
|
||||
func TestFilterByBootType(t *testing.T) {
|
||||
actual := images.FilterByBootType("bios")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.BootType != "bios" {
|
||||
t.Fatal("expected BootType 'bios', found: ", item.BootType)
|
||||
}
|
||||
@@ -110,15 +113,15 @@ func TestFilterByBootType(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := images.FilterFunc(func(ii ItemImage) bool {
|
||||
return ii.Virtual == true
|
||||
})
|
||||
actual := images.FilterFunc(func(ii ItemImage) bool {
|
||||
return ii.Virtual == true
|
||||
})
|
||||
|
||||
if len(actual) != 1 {
|
||||
t.Fatal("expected 1 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 1 {
|
||||
t.Fatal("expected 1 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
if actual[0].Virtual != true {
|
||||
if actual.Data[0].Virtual != true {
|
||||
t.Fatal("expected Virtual true, found false")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,53 @@ import (
|
||||
|
||||
// Request struct for get list available images
|
||||
type ListRequest struct {
|
||||
// Optional account ID to include account images
|
||||
// Find by storage endpoint provider ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||
|
||||
// Find by id
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by ID
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by architecture
|
||||
// Required: false
|
||||
Architecture string `url:"architecture,omitempty" json:"architecture,omitempty"`
|
||||
|
||||
// Find by type
|
||||
// Required: false
|
||||
TypeImage string `url:"typeImage,omitempty" json:"typeImage,omitempty"`
|
||||
|
||||
// Find by image size
|
||||
// Required: false
|
||||
ImageSize uint64 `url:"imageSize,omitempty" json:"imageSize,omitempty"`
|
||||
|
||||
// Find by SEP name
|
||||
// Required: false
|
||||
SEPName string `url:"sepName,omitempty" json:"sepName,omitempty"`
|
||||
|
||||
// Find by pool
|
||||
// Required: false
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Find by public True or False
|
||||
// Required: false
|
||||
Public bool `url:"public,omitempty" json:"public,omitempty"`
|
||||
|
||||
// Find by hot resize True or False
|
||||
// Required: false
|
||||
HotResize bool `url:"hotResize,omitempty" json:"hotResize,omitempty"`
|
||||
|
||||
// Find by bootable True or False
|
||||
// Required: false
|
||||
Bootable bool `url:"bootable,omitempty" json:"bootable,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
@@ -22,7 +66,7 @@ type ListRequest struct {
|
||||
}
|
||||
|
||||
// List gets list available images, optionally filtering by account ID
|
||||
func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) {
|
||||
func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) {
|
||||
url := "/cloudapi/image/list"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -37,5 +81,5 @@ func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -58,7 +58,13 @@ type ItemImage struct {
|
||||
}
|
||||
|
||||
// List of information about images
|
||||
type ListImages []ItemImage
|
||||
type ListImages struct {
|
||||
// Data
|
||||
Data []ItemImage `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// History
|
||||
type History struct {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (li ListImages) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(li) == 0 {
|
||||
if len(li.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user