v1.5.0-gamma

This commit is contained in:
2023-06-30 11:21:47 +03:00
parent 29c7f143fe
commit f50f71ab0d
98 changed files with 2369 additions and 1150 deletions

View File

@@ -59,7 +59,7 @@ func (lc ListComputes) FilterByDiskID(diskID uint64) ListComputes {
}
// FilterByK8SID returns master and worker nodes (ListComputes) inside specified K8S cluster.
func (lc ListComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListComputes, error) {
func (lc ListComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListComputes, error) {
caller := k8s.New(decortClient)
req := k8s.GetRequest{
@@ -89,7 +89,9 @@ func (lc ListComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortCl
return false
}
return lc.FilterFunc(predicate), nil
res := lc.FilterFunc(predicate)
return &res, nil
}
// K8SMasters is used to filter master nodes. Best used after FilterByK8SID function.
@@ -121,7 +123,7 @@ func (lc ListComputes) FilterByK8SWorkers() ListComputes {
}
// FilterByLBID returns ListComputes used by specified Load Balancer.
func (lc ListComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (ListComputes, error) {
func (lc ListComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (*ListComputes, error) {
caller := lb.New(decortClient)
req := lb.GetRequest{
@@ -137,28 +139,32 @@ func (lc ListComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClie
return ic.ID == foundLB.PrimaryNode.ComputeID || ic.ID == foundLB.SecondaryNode.ComputeID
}
return lc.FilterFunc(predicate), nil
res := lc.FilterFunc(predicate)
return &res, nil
}
// FilterFunc allows filtering ListComputes based on a user-specified predicate.
func (lc ListComputes) FilterFunc(predicate func(ItemCompute) bool) ListComputes {
var result ListComputes
for _, item := range lc {
for _, item := range lc.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 ItemCompute
// If none was found, returns an empty struct.
func (lc ListComputes) FindOne() ItemCompute {
if len(lc) == 0 {
if len(lc.Data) == 0 {
return ItemCompute{}
}
return lc[0]
return lc.Data[0]
}

View File

@@ -3,150 +3,153 @@ package compute
import "testing"
var computes = ListComputes{
ItemCompute{
ACL: ListACL{},
AccountID: 132847,
AccountName: "std_2",
AffinityLabel: "",
AffinityRules: []ItemRule{
{
GUID: "",
Key: "aff_key",
Mode: "ANY",
Policy: "RECOMMENDED",
Topology: "compute",
Value: "aff_val",
Data: []ItemCompute{
{
ACL: ListACL{},
AccountID: 132847,
AccountName: "std_2",
AffinityLabel: "",
AffinityRules: []ItemRule{
{
GUID: "",
Key: "aff_key",
Mode: "ANY",
Policy: "RECOMMENDED",
Topology: "compute",
Value: "aff_val",
},
},
},
AffinityWeight: 0,
AntiAffinityRules: []ItemRule{
{
GUID: "",
Key: "antiaff_key",
Mode: "ANY",
Policy: "RECOMMENDED",
Topology: "compute",
Value: "antiaff_val",
AffinityWeight: 0,
AntiAffinityRules: []ItemRule{
{
GUID: "",
Key: "antiaff_key",
Mode: "ANY",
Policy: "RECOMMENDED",
Topology: "compute",
Value: "antiaff_val",
},
},
},
Architecture: "X86_64",
BootOrder: []string{
"hd", "cdrom",
},
BootDiskSize: 0,
CloneReference: 0,
Clones: []uint64{},
ComputeCIID: 0,
CPU: 4,
CreatedBy: "timofey_tkachev_1@decs3o",
CreatedTime: 1676975175,
CustomFields: map[string]interface{}{},
DeletedBy: "",
DeletedTime: 0,
Description: "",
Devices: nil,
Disks: []InfoDisk{
{
ID: 65191,
PCISlot: 6,
Architecture: "X86_64",
BootOrder: []string{
"hd", "cdrom",
},
BootDiskSize: 0,
CloneReference: 0,
Clones: []uint64{},
ComputeCIID: 0,
CPU: 4,
CreatedBy: "timofey_tkachev_1@decs3o",
CreatedTime: 1676975175,
CustomFields: map[string]interface{}{},
DeletedBy: "",
DeletedTime: 0,
Description: "",
Devices: nil,
Disks: []InfoDisk{
{
ID: 65191,
PCISlot: 6,
},
},
Driver: "KVM_X86",
GID: 212,
GUID: 48500,
ID: 48500,
ImageID: 9884,
Interfaces: []ItemVNFInterface{},
LockStatus: "UNLOCKED",
ManagerID: 0,
ManagerType: "",
MigrationJob: 0,
Milestones: 363500,
Name: "test",
Pinned: false,
RAM: 4096,
ReferenceID: "c7cb19ac-af4a-4067-852f-c5572949207e",
Registered: true,
ResName: "compute-48500",
RGID: 79724,
RGName: "std_broker2",
SnapSets: []ItemSnapSet{},
StatelessSepID: 0,
StatelessSepType: "",
Status: "ENABLED",
Tags: map[string]string{},
TechStatus: "STOPPED",
TotalDiskSize: 2,
UpdatedBy: "",
UpdatedTime: 1677058904,
UserManaged: true,
VGPUs: []uint64{},
VINSConnected: 0,
VirtualImageID: 0,
},
{
ACL: ListACL{},
AccountID: 132848,
AccountName: "std_broker",
AffinityLabel: "",
AffinityRules: []ItemRule{},
AffinityWeight: 0,
AntiAffinityRules: []ItemRule{},
Architecture: "X86_64",
BootOrder: []string{
"hd", "cdrom",
},
BootDiskSize: 0,
CloneReference: 0,
Clones: []uint64{},
ComputeCIID: 0,
CPU: 6,
CreatedBy: "timofey_tkachev_1@decs3o",
CreatedTime: 1677579436,
CustomFields: map[string]interface{}{},
DeletedBy: "",
DeletedTime: 0,
Description: "",
Devices: nil,
Disks: []InfoDisk{
{
ID: 65248,
PCISlot: 6,
},
},
Driver: "KVM_X86",
GID: 212,
GUID: 48556,
ID: 48556,
ImageID: 9884,
Interfaces: []ItemVNFInterface{},
LockStatus: "UNLOCKED",
ManagerID: 0,
ManagerType: "",
MigrationJob: 0,
Milestones: 363853,
Name: "compute_2",
Pinned: false,
RAM: 4096,
ReferenceID: "a542c449-5b1c-4f90-88c5-7bb5f8ae68ff",
Registered: true,
ResName: "compute-48556",
RGID: 79727,
RGName: "sdk_negative_fields_test",
SnapSets: []ItemSnapSet{},
StatelessSepID: 0,
StatelessSepType: "",
Status: "ENABLED",
Tags: map[string]string{},
TechStatus: "STARTED",
TotalDiskSize: 1,
UpdatedBy: "",
UpdatedTime: 1677579436,
UserManaged: true,
VGPUs: []uint64{},
VINSConnected: 0,
VirtualImageID: 0,
},
Driver: "KVM_X86",
GID: 212,
GUID: 48500,
ID: 48500,
ImageID: 9884,
Interfaces: []ItemVNFInterface{},
LockStatus: "UNLOCKED",
ManagerID: 0,
ManagerType: "",
MigrationJob: 0,
Milestones: 363500,
Name: "test",
Pinned: false,
RAM: 4096,
ReferenceID: "c7cb19ac-af4a-4067-852f-c5572949207e",
Registered: true,
ResName: "compute-48500",
RGID: 79724,
RGName: "std_broker2",
SnapSets: []ItemSnapSet{},
StatelessSepID: 0,
StatelessSepType: "",
Status: "ENABLED",
Tags: map[string]string{},
TechStatus: "STOPPED",
TotalDiskSize: 2,
UpdatedBy: "",
UpdatedTime: 1677058904,
UserManaged: true,
VGPUs: []uint64{},
VINSConnected: 0,
VirtualImageID: 0,
},
ItemCompute{
ACL: ListACL{},
AccountID: 132848,
AccountName: "std_broker",
AffinityLabel: "",
AffinityRules: []ItemRule{},
AffinityWeight: 0,
AntiAffinityRules: []ItemRule{},
Architecture: "X86_64",
BootOrder: []string{
"hd", "cdrom",
},
BootDiskSize: 0,
CloneReference: 0,
Clones: []uint64{},
ComputeCIID: 0,
CPU: 6,
CreatedBy: "timofey_tkachev_1@decs3o",
CreatedTime: 1677579436,
CustomFields: map[string]interface{}{},
DeletedBy: "",
DeletedTime: 0,
Description: "",
Devices: nil,
Disks: []InfoDisk{
{
ID: 65248,
PCISlot: 6,
},
},
Driver: "KVM_X86",
GID: 212,
GUID: 48556,
ID: 48556,
ImageID: 9884,
Interfaces: []ItemVNFInterface{},
LockStatus: "UNLOCKED",
ManagerID: 0,
ManagerType: "",
MigrationJob: 0,
Milestones: 363853,
Name: "compute_2",
Pinned: false,
RAM: 4096,
ReferenceID: "a542c449-5b1c-4f90-88c5-7bb5f8ae68ff",
Registered: true,
ResName: "compute-48556",
RGID: 79727,
RGName: "sdk_negative_fields_test",
SnapSets: []ItemSnapSet{},
StatelessSepID: 0,
StatelessSepType: "",
Status: "ENABLED",
Tags: map[string]string{},
TechStatus: "STARTED",
TotalDiskSize: 1,
UpdatedBy: "",
UpdatedTime: 1677579436,
UserManaged: true,
VGPUs: []uint64{},
VINSConnected: 0,
VirtualImageID: 0,
},
EntryCount: 2,
}
func TestFilterByID(t *testing.T) {
@@ -158,8 +161,8 @@ func TestFilterByID(t *testing.T) {
actualEmpty := computes.FilterByID(0)
if len(actualEmpty) != 0 {
t.Fatal("expected empty, actual: ", len(actualEmpty))
if len(actualEmpty.Data) != 0 {
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
}
}
@@ -174,7 +177,7 @@ func TestFilterByName(t *testing.T) {
func TestFilterByStatus(t *testing.T) {
actual := computes.FilterByStatus("ENABLED")
for _, item := range actual {
for _, item := range actual.Data {
if item.Status != "ENABLED" {
t.Fatal("expected ENABLED status, found: ", item.Status)
}
@@ -202,11 +205,11 @@ func TestFilterFunc(t *testing.T) {
return ic.Registered == true
})
if len(actual) != 2 {
t.Fatal("expected 2 elements found, actual: ", len(actual))
if len(actual.Data) != 2 {
t.Fatal("expected 2 elements found, actual: ", len(actual.Data))
}
for _, item := range actual {
for _, item := range actual.Data {
if item.Registered != true {
t.Fatal("expected Registered to be true, actual: ", item.Registered)
}
@@ -216,26 +219,26 @@ func TestFilterFunc(t *testing.T) {
func TestSortingByCreatedTime(t *testing.T) {
actual := computes.SortByCreatedTime(false)
if actual[0].Name != "test" {
t.Fatal("expected 'test', found: ", actual[0].Name)
if actual.Data[0].Name != "test" {
t.Fatal("expected 'test', found: ", actual.Data[0].Name)
}
actual = computes.SortByCreatedTime(true)
if actual[0].Name != "compute_2" {
t.Fatal("expected 'compute_2', found: ", actual[0].Name)
if actual.Data[0].Name != "compute_2" {
t.Fatal("expected 'compute_2', found: ", actual.Data[0].Name)
}
}
func TestSortingByCPU(t *testing.T) {
actual := computes.SortByCPU(false)
if actual[0].CPU != 4 {
t.Fatal("expected 4 CPU cores, found: ", actual[0].CPU)
if actual.Data[0].CPU != 4 {
t.Fatal("expected 4 CPU cores, found: ", actual.Data[0].CPU)
}
actual = computes.SortByCPU(true)
if actual[0].CPU != 6 {
t.Fatal("expected 6 CPU cores, found: ", actual[0].CPU)
if actual.Data[0].CPU != 6 {
t.Fatal("expected 6 CPU cores, found: ", actual.Data[0].CPU)
}
}

View File

@@ -8,6 +8,46 @@ import (
// Request struct for get list available computes
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 name
// Required: false
RGName string `url:"rgName,omitempty" json:"rgName,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 IP address
// Required: false
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
// Find by external network name
// Required: false
ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"`
// Find by external network ID
// Required: false
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
// Include deleted computes
// Required: false
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
@@ -23,7 +63,7 @@ type ListRequest struct {
// List gets list of the available computes.
// Filtering based on status is possible
func (c Compute) List(ctx context.Context, req ListRequest) (ListComputes, error) {
func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, error) {
url := "/cloudapi/compute/list"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -38,5 +78,5 @@ func (c Compute) List(ctx context.Context, req ListRequest) (ListComputes, error
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -18,7 +18,7 @@ type ListDeletedRequest struct {
}
// ListDeleted gets list all deleted computes
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListComputes, error) {
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListComputes, error) {
url := "/cloudapi/compute/listDeleted"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -33,5 +33,5 @@ func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListC
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -673,6 +673,9 @@ type SnapshotExtend struct {
// Label
Label string `json:"label"`
// Reference ID
ReferenceID string `json:"referenceId"`
// Resource ID
ResID string `json:"resId"`
@@ -905,4 +908,10 @@ type InfoDisk struct {
}
// List information about computes
type ListComputes []ItemCompute
type ListComputes struct {
// Data
Data []ItemCompute `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -17,16 +17,16 @@ type ResizeRequest struct {
// New CPU count.
// Pass 0 if no change to CPU count is required
// Required: false
Force bool `url:"force,omitempty" json:"force,omitempty"`
CPU uint64 `url:"cpu,omitempty" json:"cpu,omitempty"`
// New RAM volume in MB.
// Pass 0 if no change to RAM volume is required
// Required: false
CPU uint64 `url:"cpu,omitempty" json:"cpu,omitempty"`
RAM uint64 `url:"ram,omitempty" json:"ram,omitempty"`
// Force compute resize
// Required: false
RAM uint64 `url:"ram,omitempty" json:"ram,omitempty"`
Force bool `url:"force,omitempty" json:"force,omitempty"`
}
// Resize resize compute instance

View File

@@ -12,7 +12,7 @@ import (
// - First argument -> prefix
// - Second argument -> indent
func (lc ListComputes) Serialize(params ...string) (serialization.Serialized, error) {
if len(lc) == 0 {
if lc.EntryCount == 0 {
return []byte{}, nil
}

View File

@@ -6,16 +6,16 @@ import "sort"
//
// If inverse param is set to true, the order is reversed.
func (lc ListComputes) SortByCPU(inverse bool) ListComputes {
if len(lc) < 2 {
if len(lc.Data) < 2 {
return lc
}
sort.Slice(lc, func(i, j int) bool {
sort.Slice(lc.Data, func(i, j int) bool {
if inverse {
return lc[i].CPU > lc[j].CPU
return lc.Data[i].CPU > lc.Data[j].CPU
}
return lc[i].CPU < lc[j].CPU
return lc.Data[i].CPU < lc.Data[j].CPU
})
return lc
@@ -25,16 +25,16 @@ func (lc ListComputes) SortByCPU(inverse bool) ListComputes {
//
// If inverse param is set to true, the order is reversed.
func (lc ListComputes) SortByRAM(inverse bool) ListComputes {
if len(lc) < 2 {
if len(lc.Data) < 2 {
return lc
}
sort.Slice(lc, func(i, j int) bool {
sort.Slice(lc.Data, func(i, j int) bool {
if inverse {
return lc[i].RAM > lc[j].RAM
return lc.Data[i].RAM > lc.Data[j].RAM
}
return lc[i].RAM < lc[j].RAM
return lc.Data[i].RAM < lc.Data[j].RAM
})
return lc
@@ -44,16 +44,16 @@ func (lc ListComputes) SortByRAM(inverse bool) ListComputes {
//
// If inverse param is set to true, the order is reversed.
func (lc ListComputes) SortByCreatedTime(inverse bool) ListComputes {
if len(lc) < 2 {
if len(lc.Data) < 2 {
return lc
}
sort.Slice(lc, func(i, j int) bool {
sort.Slice(lc.Data, func(i, j int) bool {
if inverse {
return lc[i].CreatedTime > lc[j].CreatedTime
return lc.Data[i].CreatedTime > lc.Data[j].CreatedTime
}
return lc[i].CreatedTime < lc[j].CreatedTime
return lc.Data[i].CreatedTime < lc.Data[j].CreatedTime
})
return lc
@@ -63,16 +63,16 @@ func (lc ListComputes) SortByCreatedTime(inverse bool) ListComputes {
//
// If inverse param is set to true, the order is reversed.
func (lc ListComputes) SortByUpdatedTime(inverse bool) ListComputes {
if len(lc) < 2 {
if len(lc.Data) < 2 {
return lc
}
sort.Slice(lc, func(i, j int) bool {
sort.Slice(lc.Data, func(i, j int) bool {
if inverse {
return lc[i].UpdatedTime > lc[j].UpdatedTime
return lc.Data[i].UpdatedTime > lc.Data[j].UpdatedTime
}
return lc[i].UpdatedTime < lc[j].UpdatedTime
return lc.Data[i].UpdatedTime < lc.Data[j].UpdatedTime
})
return lc
@@ -82,16 +82,16 @@ func (lc ListComputes) SortByUpdatedTime(inverse bool) ListComputes {
//
// If inverse param is set to true, the order is reversed.
func (lc ListComputes) SortByDeletedTime(inverse bool) ListComputes {
if len(lc) < 2 {
if len(lc.Data) < 2 {
return lc
}
sort.Slice(lc, func(i, j int) bool {
sort.Slice(lc.Data, func(i, j int) bool {
if inverse {
return lc[i].DeletedTime > lc[j].DeletedTime
return lc.Data[i].DeletedTime > lc.Data[j].DeletedTime
}
return lc[i].DeletedTime < lc[j].DeletedTime
return lc.Data[i].DeletedTime < lc.Data[j].DeletedTime
})
return lc