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

@@ -44,7 +44,7 @@ func (ll ListLB) FilterByImageID(imageID uint64) ListLB {
}
// FilterByK8SID returns ListLB used by specified K8S cluster.
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListLB, error) {
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListLB, error) {
caller := k8s.New(decortClient)
req := k8s.GetRequest{
@@ -60,28 +60,32 @@ func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient i
return cluster.LBID == ill.ID
}
return ll.FilterFunc(predicate), nil
result := ll.FilterFunc(predicate)
return &result, nil
}
// FilterFunc allows filtering ListLB based on a user-specified predicate.
func (ll ListLB) FilterFunc(predicate func(ItemLoadBalancer) bool) ListLB {
var result ListLB
for _, item := range ll {
for _, item := range ll.Data {
if predicate(item) {
result = append(result, item)
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(ll.Data))
return result
}
// FindOne returns first found ItemLoadBalancer
// If none was found, returns an empty struct.
func (ll ListLB) FindOne() ItemLoadBalancer {
if len(ll) == 0 {
if len(ll.Data) == 0 {
return ItemLoadBalancer{}
}
return ll[0]
return ll.Data[0]
}

View File

@@ -3,93 +3,96 @@ package lb
import "testing"
var lbs = ListLB{
ItemLoadBalancer{
DPAPIPassword: "0000",
RecordLB: RecordLB{
HAMode: true,
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "test_user_1",
CreatedTime: 1636667448,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIUser: "api_user",
ExtNetID: 2522,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 1,
ID: 1,
ImageID: 2121,
Milestones: 129000,
Name: "k8s-lb-test-1",
RGID: 25090,
RGName: "",
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 101,
},
},
ItemLoadBalancer{
DPAPIPassword: "0000",
RecordLB: RecordLB{
HAMode: false,
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "test_user_2",
CreatedTime: 1636667506,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIUser: "api_user_2",
ExtNetID: 2524,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 2,
ID: 2,
ImageID: 2129,
Milestones: 129013,
Name: "k8s-lb-test-2",
RGID: 25092,
RGName: "",
Status: "ENABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 102,
},
},
ItemLoadBalancer{
DPAPIPassword: "0000",
RecordLB: RecordLB{
HAMode: true,
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "te2t_user_3",
CreatedTime: 1636667534,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIUser: "api_user_3",
ExtNetID: 2536,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 3,
ID: 3,
ImageID: 2139,
Milestones: 129025,
Name: "k8s-lb-test-3",
RGID: 25106,
RGName: "",
Status: "DISABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 118,
Data: []ItemLoadBalancer{
{
DPAPIPassword: "0000",
RecordLB: RecordLB{
HAMode: true,
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "test_user_1",
CreatedTime: 1636667448,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIUser: "api_user",
ExtNetID: 2522,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 1,
ID: 1,
ImageID: 2121,
Milestones: 129000,
Name: "k8s-lb-test-1",
RGID: 25090,
RGName: "",
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 101,
},
},
{
DPAPIPassword: "0000",
RecordLB: RecordLB{
HAMode: false,
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "test_user_2",
CreatedTime: 1636667506,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIUser: "api_user_2",
ExtNetID: 2524,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 2,
ID: 2,
ImageID: 2129,
Milestones: 129013,
Name: "k8s-lb-test-2",
RGID: 25092,
RGName: "",
Status: "ENABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 102,
},
},
{
DPAPIPassword: "0000",
RecordLB: RecordLB{
HAMode: true,
ACL: []interface{}{},
Backends: []ItemBackend{},
CreatedBy: "te2t_user_3",
CreatedTime: 1636667534,
DeletedBy: "",
DeletedTime: 0,
Description: "",
DPAPIUser: "api_user_3",
ExtNetID: 2536,
Frontends: []ItemFrontend{},
GID: 212,
GUID: 3,
ID: 3,
ImageID: 2139,
Milestones: 129025,
Name: "k8s-lb-test-3",
RGID: 25106,
RGName: "",
Status: "DISABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 118,
},
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
@@ -129,7 +132,7 @@ func TestFilterFunc(t *testing.T) {
return rl.Status == "DISABLED"
})
for _, item := range actual {
for _, item := range actual.Data {
if item.Status != "DISABLED" {
t.Fatal("expected Status 'DISABLED', found: ", item.Status)
}
@@ -139,7 +142,7 @@ func TestFilterFunc(t *testing.T) {
func TestSortByCreatedTime(t *testing.T) {
actual := lbs.SortByCreatedTime(true)
if actual[0].CreatedTime != 1636667534 || actual[2].CreatedTime != 1636667448 {
if actual.Data[0].CreatedTime != 1636667534 || actual.Data[2].CreatedTime != 1636667448 {
t.Fatal("expected descending order, found ascending")
}
}

View File

@@ -8,6 +8,38 @@ import (
// Request struct for get list of load balancers
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 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 frontend Ip
// Required: false
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
// Find by backend Ip
// Required: false
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
// Included deleted load balancers
// Required: false
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
@@ -22,7 +54,7 @@ type ListRequest struct {
}
// List gets list all load balancers
func (l LB) List(ctx context.Context, req ListRequest) (ListLB, error) {
func (l LB) List(ctx context.Context, req ListRequest) (*ListLB, error) {
url := "/cloudapi/lb/list"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -37,5 +69,5 @@ func (l LB) List(ctx context.Context, req ListRequest) (ListLB, error) {
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -8,6 +8,34 @@ import (
// Request struct for get list of deleted load balancers
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 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 frontend Ip
// Required: false
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
// Find by backend Ip
// Required: false
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -18,7 +46,7 @@ type ListDeletedRequest struct {
}
// ListDeleted gets list of deleted load balancers
func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListLB, error) {
func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListLB, error) {
url := "/cloudapi/lb/listDeleted"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -33,5 +61,5 @@ func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListLB, er
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -90,7 +90,13 @@ type ItemLoadBalancer struct {
}
// List of load balancers
type ListLB []ItemLoadBalancer
type ListLB struct {
// Data
Data []ItemLoadBalancer `json:"data"`
// EntryCount
EntryCount uint64 `json:"entryCount"`
}
// Main information about backend
type ItemBackend struct {

View File

@@ -12,7 +12,7 @@ import (
// - First argument -> prefix
// - Second argument -> indent
func (ll ListLB) Serialize(params ...string) (serialization.Serialized, error) {
if len(ll) == 0 {
if len(ll.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 (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
if len(ll) < 2 {
if len(ll.Data) < 2 {
return ll
}
sort.Slice(ll, func(i, j int) bool {
sort.Slice(ll.Data, func(i, j int) bool {
if inverse {
return ll[i].CreatedTime > ll[j].CreatedTime
return ll.Data[i].CreatedTime > ll.Data[j].CreatedTime
}
return ll[i].CreatedTime < ll[j].CreatedTime
return ll.Data[i].CreatedTime < ll.Data[j].CreatedTime
})
return ll
@@ -25,16 +25,16 @@ func (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
//
// If inverse param is set to true, the order is reversed.
func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
if len(ll) < 2 {
if len(ll.Data) < 2 {
return ll
}
sort.Slice(ll, func(i, j int) bool {
sort.Slice(ll.Data, func(i, j int) bool {
if inverse {
return ll[i].UpdatedTime > ll[j].UpdatedTime
return ll.Data[i].UpdatedTime > ll.Data[j].UpdatedTime
}
return ll[i].UpdatedTime < ll[j].UpdatedTime
return ll.Data[i].UpdatedTime < ll.Data[j].UpdatedTime
})
return ll
@@ -44,16 +44,16 @@ func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
//
// If inverse param is set to true, the order is reversed.
func (ll ListLB) SortByDeletedTime(inverse bool) ListLB {
if len(ll) < 2 {
if len(ll.Data) < 2 {
return ll
}
sort.Slice(ll, func(i, j int) bool {
sort.Slice(ll.Data, func(i, j int) bool {
if inverse {
return ll[i].DeletedTime > ll[j].DeletedTime
return ll.Data[i].DeletedTime > ll.Data[j].DeletedTime
}
return ll[i].DeletedTime < ll[j].DeletedTime
return ll.Data[i].DeletedTime < ll.Data[j].DeletedTime
})
return ll