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

@@ -16,7 +16,7 @@ type DeleteRequest struct {
// Reason for action
// Required: true
Reason string `url:"reason" json:"reason" validate:"required"`
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
// Whether to completely delete the image
// Required: false

View File

@@ -49,9 +49,9 @@ func (li ListImages) FilterByBootType(bootType string) ListImages {
func (li ListImages) FilterFunc(predicate func(RecordImage) 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)
}
}
@@ -61,9 +61,9 @@ func (li ListImages) FilterFunc(predicate func(RecordImage) bool) ListImages {
// FindOne returns first found RecordImage
// If none was found, returns an empty struct.
func (li ListImages) FindOne() RecordImage {
if len(li) == 0 {
if len(li.Data) == 0 {
return RecordImage{}
}
return li[0]
return li.Data[0]
}

View File

@@ -3,155 +3,157 @@ package image
import "testing"
var images = ListImages{
RecordImage{
UNCPath: "",
CKey: "",
Meta: []interface{}{
"osismodel",
"cloudbroker",
"image",
1,
Data: []RecordImage{
{
UNCPath: "",
CKey: "",
Meta: []interface{}{
"osismodel",
"cloudbroker",
"image",
1,
},
AccountID: 0,
ACL: []ACL{},
Architecture: "X86_64",
BootType: "bios",
Bootable: true,
ComputeCIID: 0,
DeletedTime: 0,
Description: "",
Drivers: []string{
"KVM_X86",
},
Enabled: true,
GID: 212,
GUID: 9882,
History: []History{},
HotResize: true,
ID: 9882,
LastModified: 0,
LinkTo: 0,
Milestones: 363491,
Name: "u16",
Password: "",
Pool: "vmstor",
PresentTo: []uint64{},
ProviderName: "",
PurgeAttempts: 0,
ReferenceID: "sample_reference_id_u16",
ResID: "b321318-3214as-324-213-fdas",
ResName: "templates/image_9882",
RescueCD: false,
SEPID: 2504,
SharedWith: []uint64{},
Size: 5,
Status: "CREATED",
TechStatus: "ALLOCATED",
Type: "linux",
URL: "http://sample_url:8000/u16",
Username: "",
Version: "",
Virtual: false,
},
AccountID: 0,
ACL: []ACL{},
Architecture: "X86_64",
BootType: "bios",
Bootable: true,
ComputeCIID: 0,
DeletedTime: 0,
Description: "",
Drivers: []string{
"KVM_X86",
{
UNCPath: "",
CKey: "",
Meta: []interface{}{
"osismodel",
"cloudbroker",
"image",
1,
},
AccountID: 0,
ACL: []ACL{},
Architecture: "X86_64",
BootType: "bois",
Bootable: true,
ComputeCIID: 0,
DeletedTime: 0,
Description: "",
Drivers: []string{
"KVM_X86",
},
Enabled: false,
GID: 212,
GUID: 9884,
History: []History{},
HotResize: false,
ID: 9884,
LastModified: 0,
LinkTo: 0,
Milestones: 363499,
Name: "alpine-virt-3.17",
Password: "",
Pool: "vmstor",
PresentTo: []uint64{},
ProviderName: "",
PurgeAttempts: 0,
ReferenceID: "sample_reference_id_alpine",
ResID: "31d1d410-74f1-4e09-866b-046a5a8433c3",
ResName: "templates/image_9884",
RescueCD: false,
SEPID: 2504,
SharedWith: []uint64{},
Size: 1,
Status: "CREATED",
TechStatus: "ALLOCATED",
Type: "linux",
URL: "http://sample_url:8000/alpine-virt-3",
Username: "",
Version: "",
Virtual: true,
},
Enabled: true,
GID: 212,
GUID: 9882,
History: []History{},
HotResize: true,
ID: 9882,
LastModified: 0,
LinkTo: 0,
Milestones: 363491,
Name: "u16",
Password: "",
Pool: "vmstor",
PresentTo: []uint64{},
ProviderName: "",
PurgeAttempts: 0,
ReferenceID: "sample_reference_id_u16",
ResID: "b321318-3214as-324-213-fdas",
ResName: "templates/image_9882",
RescueCD: false,
SEPID: 2504,
SharedWith: []uint64{},
Size: 5,
Status: "CREATED",
TechStatus: "ALLOCATED",
Type: "linux",
URL: "http://sample_url:8000/u16",
Username: "",
Version: "",
Virtual: false,
},
RecordImage{
UNCPath: "",
CKey: "",
Meta: []interface{}{
"osismodel",
"cloudbroker",
"image",
1,
{
UNCPath: "",
CKey: "",
Meta: []interface{}{
"osismodel",
"cloudbroker",
"image",
1,
},
AccountID: 1,
ACL: []ACL{},
Architecture: "X86_64",
BootType: "bios",
Bootable: true,
ComputeCIID: 0,
DeletedTime: 0,
Description: "",
Drivers: []string{
"KVM_X86",
},
Enabled: true,
GID: 212,
GUID: 9885,
History: []History{},
HotResize: true,
ID: 9885,
LastModified: 0,
LinkTo: 0,
Milestones: 363513,
Name: "test",
Password: "",
Pool: "vmstor",
PresentTo: []uint64{},
ProviderName: "",
PurgeAttempts: 0,
ReferenceID: "sample_reference_id_test",
ResID: "1f53b815-1ac9-4a4b-af98-a0a3b69a34bb",
ResName: "templates/image_9885",
RescueCD: false,
SEPID: 2505,
SharedWith: []uint64{},
Size: 4,
Status: "DESTROYED",
TechStatus: "ALLOCATED",
Type: "linux",
URL: "http://sample_url:8000/test",
Username: "",
Version: "",
Virtual: false,
},
AccountID: 0,
ACL: []ACL{},
Architecture: "X86_64",
BootType: "bois",
Bootable: true,
ComputeCIID: 0,
DeletedTime: 0,
Description: "",
Drivers: []string{
"KVM_X86",
},
Enabled: false,
GID: 212,
GUID: 9884,
History: []History{},
HotResize: false,
ID: 9884,
LastModified: 0,
LinkTo: 0,
Milestones: 363499,
Name: "alpine-virt-3.17",
Password: "",
Pool: "vmstor",
PresentTo: []uint64{},
ProviderName: "",
PurgeAttempts: 0,
ReferenceID: "sample_reference_id_alpine",
ResID: "31d1d410-74f1-4e09-866b-046a5a8433c3",
ResName: "templates/image_9884",
RescueCD: false,
SEPID: 2504,
SharedWith: []uint64{},
Size: 1,
Status: "CREATED",
TechStatus: "ALLOCATED",
Type: "linux",
URL: "http://sample_url:8000/alpine-virt-3",
Username: "",
Version: "",
Virtual: true,
},
RecordImage{
UNCPath: "",
CKey: "",
Meta: []interface{}{
"osismodel",
"cloudbroker",
"image",
1,
},
AccountID: 1,
ACL: []ACL{},
Architecture: "X86_64",
BootType: "bios",
Bootable: true,
ComputeCIID: 0,
DeletedTime: 0,
Description: "",
Drivers: []string{
"KVM_X86",
},
Enabled: true,
GID: 212,
GUID: 9885,
History: []History{},
HotResize: true,
ID: 9885,
LastModified: 0,
LinkTo: 0,
Milestones: 363513,
Name: "test",
Password: "",
Pool: "vmstor",
PresentTo: []uint64{},
ProviderName: "",
PurgeAttempts: 0,
ReferenceID: "sample_reference_id_test",
ResID: "1f53b815-1ac9-4a4b-af98-a0a3b69a34bb",
ResName: "templates/image_9885",
RescueCD: false,
SEPID: 2505,
SharedWith: []uint64{},
Size: 4,
Status: "DESTROYED",
TechStatus: "ALLOCATED",
Type: "linux",
URL: "http://sample_url:8000/test",
Username: "",
Version: "",
Virtual: false,
},
}
@@ -159,56 +161,56 @@ func TestFilterByID(t *testing.T) {
actual := images.FilterByID(9885).FindOne()
if actual.ID != 9885 {
t.Fatal("expected ID 9885, found: ", actual.ID)
t.Fatal("expected ID 9885, found: ", actual.ID)
}
}
func TestFilterByName(t *testing.T) {
actual := images.FilterByName("u16").FindOne()
actual := images.FilterByName("u16").FindOne()
if actual.Name != "u16" {
t.Fatal("expected Name 'u16', found: ", actual.Name)
}
if actual.Name != "u16" {
t.Fatal("expected Name 'u16', found: ", actual.Name)
}
}
func TestFilterByStatus(t *testing.T) {
actual := images.FilterByStatus("CREATED")
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 {
if item.Status != "CREATED" {
t.Fatal("expected Status 'CREATED', found: ", item.Status)
}
}
for _, item := range actual.Data {
if item.Status != "CREATED" {
t.Fatal("expected Status 'CREATED', found: ", item.Status)
}
}
}
func TestFilterByBootType(t *testing.T) {
actual := images.FilterByBootType("bios")
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 {
if item.BootType != "bios" {
t.Fatal("expected BootType 'bios', found: ", item.BootType)
}
}
for _, item := range actual.Data {
if item.BootType != "bios" {
t.Fatal("expected BootType 'bios', found: ", item.BootType)
}
}
}
func TestFilterFunc(t *testing.T) {
actual := images.FilterFunc(func(ri RecordImage) bool {
return ri.Virtual == true
})
actual := images.FilterFunc(func(ri RecordImage) bool {
return ri.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 {
t.Fatal("expected Virtual true, found false")
}
if actual.Data[0].Virtual != true {
t.Fatal("expected Virtual true, found false")
}
}

View File

@@ -12,9 +12,49 @@ type ListRequest struct {
// Required: false
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Filter images by account ID availability
// Find by ID
// Required: false
SharedWith uint64 `url:"sharedWith,omitempty" json:"sharedWith,omitempty"`
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 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
@@ -26,7 +66,7 @@ type ListRequest struct {
}
// List gets list of information about images
func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) {
func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) {
url := "/cloudbroker/image/list"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -41,5 +81,5 @@ func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) {
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -21,10 +21,22 @@ type ListStacksRequest struct {
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Find by name
// 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 type
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
}
// ListStacks gets list stack by image ID
func (i Image) ListStacks(ctx context.Context, req ListStacksRequest) (ListStacks, error) {
func (i Image) ListStacks(ctx context.Context, req ListStacksRequest) (*ListStacks, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -46,5 +58,5 @@ func (i Image) ListStacks(ctx context.Context, req ListStacksRequest) (ListStack
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -127,7 +127,13 @@ type RecordImage struct {
}
// List images
type ListImages []RecordImage
type ListImages struct {
// Data
Data []RecordImage `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Access Control List
type ACL struct {
@@ -156,7 +162,7 @@ type ListACL []ACL
// History information
type History struct {
// GUID
GUID string `json:"guid"`
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
@@ -169,61 +175,75 @@ type History struct {
type ListHistory []History
// List stacks
type ListStacks []struct {
// CKey
CKey string `json:"_ckey"`
type ListStacks struct {
Data []struct {
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// Meta
Meta []interface{} `json:"_meta"`
// API URL
APIURL string `json:"apiUrl"`
// API URL
APIURL string `json:"apiUrl"`
// API key
APIKey string `json:"apikey"`
// API key
APIKey string `json:"apikey"`
// App ID
AppID string `json:"appId"`
// App ID
AppID string `json:"appId"`
// Description
Description string `json:"desc"`
// CPU allocation ratio
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
// Drivers
Drivers []string `json:"drivers"`
// Description
Description string `json:"desc"`
// Eco
Eco interface{} `json:"eco"`
// Descr
Descr string `json:"descr"`
// Error
Error uint64 `json:"error"`
// Drivers
Drivers []string `json:"drivers"`
// Grid ID
GID uint64 `json:"gid"`
// Eco
Eco interface{} `json:"eco"`
// GID
GUID uint64 `json:"guid"`
// Error
Error uint64 `json:"error"`
// ID
ID uint64 `json:"id"`
// Grid ID
GID uint64 `json:"gid"`
// List image IDs
Images []uint64 `json:"images"`
// GID
GUID uint64 `json:"guid"`
// Login
Login string `json:"login"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// List image IDs
Images []uint64 `json:"images"`
// Password
Password string `json:"passwd"`
// Login
Login string `json:"login"`
// Reference ID
ReferenceID string `json:"referenceId"`
// Mem allocation ratio
// Required: false
MemAllocationRatio float64 `json:"mem_allocation_ratio"`
// Status
Status string `json:"status"`
// Name
Name string `json:"name"`
// Type
Type string `json:"type"`
// Password
Password string `json:"passwd"`
// Reference ID
ReferenceID string `json:"referenceId"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
} `json:"data"`
EntryCount uint64 `json:"entryCount"`
}

View File

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