v1.2.1
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/account"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
)
|
||||
|
||||
// Accessing the Account method group
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to account
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for adding permission to access to account for a user
|
||||
|
||||
68
pkg/cloudapi/account/filter.go
Normal file
68
pkg/cloudapi/account/filter.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package account
|
||||
|
||||
// FilterByID returns ListAccounts with specified ID.
|
||||
func (la ListAccounts) FilterByID(id uint64) ListAccounts {
|
||||
predicate := func(ia ItemAccount) bool {
|
||||
return ia.ID == id
|
||||
}
|
||||
|
||||
return la.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListAccounts with specified Name.
|
||||
func (la ListAccounts) FilterByName(name string) ListAccounts {
|
||||
predicate := func(ia ItemAccount) bool {
|
||||
return ia.Name == name
|
||||
}
|
||||
|
||||
return la.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListAccounts with specified Status.
|
||||
func (la ListAccounts) FilterByStatus(status string) ListAccounts {
|
||||
predicate := func(ia ItemAccount) bool {
|
||||
return ia.Status == status
|
||||
}
|
||||
|
||||
return la.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByUserGroupID returns ListAccounts with specified UserGroupID.
|
||||
func (la ListAccounts) FilterByUserGroupID(userGroupID string) ListAccounts {
|
||||
predicate := func(ia ItemAccount) bool {
|
||||
acl := ia.ACL
|
||||
|
||||
for _, item := range acl {
|
||||
if item.UgroupID == userGroupID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return la.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListAccounts based on a user-specified predicate.
|
||||
func (la ListAccounts) FilterFunc(predicate func(ItemAccount) bool) ListAccounts {
|
||||
var result ListAccounts
|
||||
|
||||
for _, acc := range la {
|
||||
if predicate(acc) {
|
||||
result = append(result, acc)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemAccount.
|
||||
// If none was found, returns an empty struct.
|
||||
func (la ListAccounts) FindOne() ItemAccount {
|
||||
if len(la) == 0 {
|
||||
return ItemAccount{}
|
||||
}
|
||||
|
||||
return la[0]
|
||||
}
|
||||
146
pkg/cloudapi/account/filter_test.go
Normal file
146
pkg/cloudapi/account/filter_test.go
Normal file
@@ -0,0 +1,146 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var accounts = ListAccounts{
|
||||
ItemAccount{
|
||||
ACL: []RecordACL{
|
||||
{
|
||||
IsExplicit: true,
|
||||
GUID: "",
|
||||
Rights: "CXDRAU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UgroupID: "timofey_tkachev_1@decs3o",
|
||||
},
|
||||
},
|
||||
CreatedTime: 1676645275,
|
||||
DeletedTime: 0,
|
||||
ID: 132846,
|
||||
Name: "std",
|
||||
Status: "CONFIRMED",
|
||||
UpdatedTime: 1676645275,
|
||||
},
|
||||
ItemAccount{
|
||||
ACL: []RecordACL{
|
||||
{
|
||||
IsExplicit: true,
|
||||
GUID: "",
|
||||
Rights: "CXDRAU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UgroupID: "not_really_timofey_tkachev_1@decs3o",
|
||||
},
|
||||
},
|
||||
CreatedTime: 1676878820,
|
||||
DeletedTime: 0,
|
||||
ID: 132847,
|
||||
Name: "std_2",
|
||||
Status: "CONFIRMED",
|
||||
UpdatedTime: 1676645275,
|
||||
},
|
||||
ItemAccount{
|
||||
ACL: []RecordACL{
|
||||
{
|
||||
IsExplicit: true,
|
||||
GUID: "",
|
||||
Rights: "CXDRAU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UgroupID: "timofey_tkachev_1@decs3o",
|
||||
},
|
||||
{
|
||||
IsExplicit: true,
|
||||
GUID: "",
|
||||
Rights: "CXDRAU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UgroupID: "second_account@decs3o",
|
||||
},
|
||||
},
|
||||
CreatedTime: 1676883850,
|
||||
DeletedTime: 1676883899,
|
||||
ID: 132848,
|
||||
Name: "std_broker",
|
||||
Status: "DELETED",
|
||||
UpdatedTime: 1676878820,
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := accounts.FilterByID(132846).FindOne()
|
||||
|
||||
if actual.ID != 132846 {
|
||||
t.Fatal("actual: ", actual.ID, " > expected: 132846")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByUserGroupId(t *testing.T) {
|
||||
actual := accounts.FilterByUserGroupID("second_account@decs3o").FindOne()
|
||||
|
||||
for _, item := range actual.ACL {
|
||||
if item.UgroupID == "second_account@decs3o" {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
t.Fatal("second_account@decs3o has not been found. expected 1 found")
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := accounts.FilterByName("std_broker").FindOne()
|
||||
|
||||
if actual.Name != "std_broker" {
|
||||
t.Fatal("actual: ", actual.Name, " >> expected: std_broker")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := accounts.FilterByStatus("CONFIRMED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("Expected 2 elements in slice, found: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.Status != "CONFIRMED" {
|
||||
t.Fatal("expected CONFIRMED, found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := accounts.FilterFunc(func(ia ItemAccount) bool {
|
||||
return ia.DeletedTime == 0
|
||||
})
|
||||
|
||||
for _, item := range actual {
|
||||
if item.DeletedTime != 0 {
|
||||
t.Fatal("Expected DeletedTime = 0, found: ", item.DeletedTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortingByCreatedTime(t *testing.T) {
|
||||
actual := accounts.SortByCreatedTime(false)
|
||||
|
||||
if actual[0].Name != "std" {
|
||||
t.Fatal("Expected account std as earliest, found: ", actual[0].Name)
|
||||
}
|
||||
|
||||
actual = accounts.SortByCreatedTime(true)
|
||||
|
||||
if actual[0].Name != "std_broker" {
|
||||
t.Fatal("Expected account std_broker as latest, found: ", actual[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterEmpty(t *testing.T) {
|
||||
actual := accounts.FilterByID(0)
|
||||
|
||||
if len(actual) != 0 {
|
||||
t.Fatal("Expected 0 found, actual: ", len(actual))
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for calculate the currently consumed cloud units of the specified type for all cloudspaces and resource groups in the account
|
||||
|
||||
43
pkg/cloudapi/account/serialize.go
Normal file
43
pkg/cloudapi/account/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (la ListAccounts) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(la) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(la, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(la)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ia ItemAccount) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ia, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ia)
|
||||
}
|
||||
60
pkg/cloudapi/account/sorting.go
Normal file
60
pkg/cloudapi/account/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package account
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListAccounts by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts {
|
||||
if len(la) < 2 {
|
||||
return la
|
||||
}
|
||||
|
||||
sort.Slice(la, func(i, j int) bool {
|
||||
if inverse {
|
||||
return la[i].CreatedTime > la[j].CreatedTime
|
||||
}
|
||||
|
||||
return la[i].CreatedTime < la[j].CreatedTime
|
||||
})
|
||||
|
||||
return la
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListAccounts by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (la ListAccounts) SortByUpdatedTime(inverse bool) ListAccounts {
|
||||
if len(la) < 2 {
|
||||
return la
|
||||
}
|
||||
|
||||
sort.Slice(la, func(i, j int) bool {
|
||||
if inverse {
|
||||
return la[i].UpdatedTime > la[j].UpdatedTime
|
||||
}
|
||||
|
||||
return la[i].UpdatedTime < la[j].UpdatedTime
|
||||
})
|
||||
|
||||
return la
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListAccounts by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (la ListAccounts) SortByDeletedTime(inverse bool) ListAccounts {
|
||||
if len(la) < 2 {
|
||||
return la
|
||||
}
|
||||
|
||||
sort.Slice(la, func(i, j int) bool {
|
||||
if inverse {
|
||||
return la[i].DeletedTime > la[j].DeletedTime
|
||||
}
|
||||
|
||||
return la[i].DeletedTime < la[j].DeletedTime
|
||||
})
|
||||
|
||||
return la
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update user access rights
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cloudapi
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/bservice"
|
||||
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
|
||||
|
||||
// Accessing the BService method group
|
||||
func (ca *CloudAPI) BService() *bservice.BService {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// API Actor for managing Compute Group. This actor is a final API for endusers to manage Compute Group
|
||||
package bservice
|
||||
|
||||
import "github.com/rudecs/decort-sdk/interfaces"
|
||||
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to bservice
|
||||
type BService struct {
|
||||
|
||||
69
pkg/cloudapi/bservice/filter.go
Normal file
69
pkg/cloudapi/bservice/filter.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package bservice
|
||||
|
||||
// FilterByID returns ListBasicServices with specified ID.
|
||||
func (lbs ListBasicServices) FilterByID(id uint64) ListBasicServices {
|
||||
predicate := func(ibs ItemBasicService) bool {
|
||||
return ibs.ID == id
|
||||
}
|
||||
|
||||
return lbs.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListBasicServices with specified Name.
|
||||
func (lbs ListBasicServices) FilterByName(name string) ListBasicServices {
|
||||
predicate := func(ibs ItemBasicService) bool {
|
||||
return ibs.Name == name
|
||||
}
|
||||
|
||||
return lbs.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByRGID returns ListBasicServices with specified RGID.
|
||||
func (lbs ListBasicServices) FilterByRGID(rgID uint64) ListBasicServices {
|
||||
predicate := func(ibs ItemBasicService) bool {
|
||||
return ibs.RGID == rgID
|
||||
}
|
||||
|
||||
return lbs.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListBasicServices with specified Status.
|
||||
func (lbs ListBasicServices) FilterByStatus(status string) ListBasicServices {
|
||||
predicate := func(ibs ItemBasicService) bool {
|
||||
return ibs.Status == status
|
||||
}
|
||||
|
||||
return lbs.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByTechStatus returns ListBasicServices with specified TechStatus.
|
||||
func (lbs ListBasicServices) FilterByTechStatus(techStatus string) ListBasicServices {
|
||||
predicate := func(ibs ItemBasicService) bool {
|
||||
return ibs.TechStatus == techStatus
|
||||
}
|
||||
|
||||
return lbs.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListResourceGroups based on a user-specified predicate.
|
||||
func (lbs ListBasicServices) FilterFunc(predicate func(ItemBasicService) bool) ListBasicServices {
|
||||
var result ListBasicServices
|
||||
|
||||
for _, item := range lbs {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemBasicService
|
||||
// If none was found, returns an empty struct.
|
||||
func (lbs ListBasicServices) FindOne() ItemBasicService {
|
||||
if len(lbs) == 0 {
|
||||
return ItemBasicService{}
|
||||
}
|
||||
|
||||
return lbs[0]
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for resize the group
|
||||
|
||||
43
pkg/cloudapi/bservice/serialize.go
Normal file
43
pkg/cloudapi/bservice/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lbs ListBasicServices) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lbs) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lbs, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lbs)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ibs ItemBasicService) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ibs, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ibs)
|
||||
}
|
||||
60
pkg/cloudapi/bservice/sorting.go
Normal file
60
pkg/cloudapi/bservice/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package bservice
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListBasicServices by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lbs ListBasicServices) SortByCreatedTime(inverse bool) ListBasicServices {
|
||||
if len(lbs) < 2 {
|
||||
return lbs
|
||||
}
|
||||
|
||||
sort.Slice(lbs, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lbs[i].CreatedTime > lbs[j].CreatedTime
|
||||
}
|
||||
|
||||
return lbs[i].CreatedTime < lbs[j].CreatedTime
|
||||
})
|
||||
|
||||
return lbs
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListBasicServices by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lbs ListBasicServices) SortByUpdatedTime(inverse bool) ListBasicServices {
|
||||
if len(lbs) < 2 {
|
||||
return lbs
|
||||
}
|
||||
|
||||
sort.Slice(lbs, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lbs[i].UpdatedTime > lbs[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lbs[i].UpdatedTime < lbs[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lbs
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListBasicServices by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lbs ListBasicServices) SortByDeletedTime(inverse bool) ListBasicServices {
|
||||
if len(lbs) < 2 {
|
||||
return lbs
|
||||
}
|
||||
|
||||
sort.Slice(lbs, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lbs[i].DeletedTime > lbs[j].DeletedTime
|
||||
}
|
||||
|
||||
return lbs[i].DeletedTime < lbs[j].DeletedTime
|
||||
})
|
||||
|
||||
return lbs
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to CloudAPI groups
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/compute"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
)
|
||||
|
||||
// Accessing the Compute method group
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add affinity rule
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for remove affinity rule
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add anti affinity rule
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for remove anti affinity rule
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to compute
|
||||
|
||||
74
pkg/cloudapi/compute/filter.go
Normal file
74
pkg/cloudapi/compute/filter.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package compute
|
||||
|
||||
// FilterByID returns ListComputes with specified ID.
|
||||
func (lc ListComputes) FilterByID(id uint64) ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
return ic.ID == id
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListComputes with specified Name.
|
||||
func (lc ListComputes) FilterByName(name string) ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
return ic.Name == name
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListComputes with specified Status.
|
||||
func (lc ListComputes) FilterByStatus(status string) ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
return ic.Status == status
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByTechStatus returns ListComputes with specified TechStatus.
|
||||
func (lc ListComputes) FilterByTechStatus(techStatus string) ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
return ic.TechStatus == techStatus
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDiskID return ListComputes with specified DiskID.
|
||||
func (lc ListComputes) FilterByDiskID(diskID uint64) ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
for _, disk := range ic.Disks {
|
||||
if disk.ID == diskID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemCompute
|
||||
// If none was found, returns an empty struct.
|
||||
func (lc ListComputes) FindOne() ItemCompute {
|
||||
if len(lc) == 0 {
|
||||
return ItemCompute{}
|
||||
}
|
||||
|
||||
return lc[0]
|
||||
}
|
||||
241
pkg/cloudapi/compute/filter_test.go
Normal file
241
pkg/cloudapi/compute/filter_test.go
Normal file
@@ -0,0 +1,241 @@
|
||||
package compute
|
||||
|
||||
import "testing"
|
||||
|
||||
var computes = ListComputes{
|
||||
ItemCompute{
|
||||
ACL: []interface{}{},
|
||||
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",
|
||||
},
|
||||
},
|
||||
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,
|
||||
},
|
||||
ItemCompute{
|
||||
ACL: []interface{}{},
|
||||
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,
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := computes.FilterByID(48500).FindOne()
|
||||
|
||||
if actual.ID != 48500 {
|
||||
t.Fatal("expected ID 48500, found: ", actual.ID)
|
||||
}
|
||||
|
||||
actualEmpty := computes.FilterByID(0)
|
||||
|
||||
if len(actualEmpty) != 0 {
|
||||
t.Fatal("expected empty, actual: ", len(actualEmpty))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := computes.FilterByName("test").FindOne()
|
||||
|
||||
if actual.Name != "test" {
|
||||
t.Fatal("expected compute with name 'test', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := computes.FilterByStatus("ENABLED")
|
||||
|
||||
for _, item := range actual {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected ENABLED status, found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByTechStatus(t *testing.T) {
|
||||
actual := computes.FilterByTechStatus("STARTED").FindOne()
|
||||
|
||||
if actual.ID != 48556 {
|
||||
t.Fatal("expected 48556 with STARTED techStatus, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByDiskID(t *testing.T) {
|
||||
actual := computes.FilterByDiskID(65248).FindOne()
|
||||
|
||||
if actual.ID != 48556 {
|
||||
t.Fatal("expected 48556 with DiskID 65248, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := computes.FilterFunc(func(ic ItemCompute) bool {
|
||||
return ic.Registered == true
|
||||
})
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 elements found, actual: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.Registered != true {
|
||||
t.Fatal("expected Registered to be true, actual: ", item.Registered)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortingByCreatedTime(t *testing.T) {
|
||||
actual := computes.SortByCreatedTime(false)
|
||||
|
||||
if actual[0].Name != "test" {
|
||||
t.Fatal("expected 'test', found: ", actual[0].Name)
|
||||
}
|
||||
|
||||
actual = computes.SortByCreatedTime(true)
|
||||
if actual[0].Name != "compute_2" {
|
||||
t.Fatal("expected 'compute_2', found: ", actual[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)
|
||||
}
|
||||
|
||||
actual = computes.SortByCPU(true)
|
||||
|
||||
if actual[0].CPU != 6 {
|
||||
t.Fatal("expected 6 CPU cores, found: ", actual[0].CPU)
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for attach network
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add port forward rule
|
||||
|
||||
43
pkg/cloudapi/compute/serialize.go
Normal file
43
pkg/cloudapi/compute/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lc ListComputes) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lc) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lc, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lc)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ic ItemCompute) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ic, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ic)
|
||||
}
|
||||
98
pkg/cloudapi/compute/sorting.go
Normal file
98
pkg/cloudapi/compute/sorting.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package compute
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCPU sorts ListComputes by the CPU core amount in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lc ListComputes) SortByCPU(inverse bool) ListComputes {
|
||||
if len(lc) < 2 {
|
||||
return lc
|
||||
}
|
||||
|
||||
sort.Slice(lc, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lc[i].CPU > lc[j].CPU
|
||||
}
|
||||
|
||||
return lc[i].CPU < lc[j].CPU
|
||||
})
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
// SortByRAM sorts ListComputes by the RAM amount in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lc ListComputes) SortByRAM(inverse bool) ListComputes {
|
||||
if len(lc) < 2 {
|
||||
return lc
|
||||
}
|
||||
|
||||
sort.Slice(lc, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lc[i].RAM > lc[j].RAM
|
||||
}
|
||||
|
||||
return lc[i].RAM < lc[j].RAM
|
||||
})
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
// SortByCreatedTime sorts ListComputes by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lc ListComputes) SortByCreatedTime(inverse bool) ListComputes {
|
||||
if len(lc) < 2 {
|
||||
return lc
|
||||
}
|
||||
|
||||
sort.Slice(lc, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lc[i].CreatedTime > lc[j].CreatedTime
|
||||
}
|
||||
|
||||
return lc[i].CreatedTime < lc[j].CreatedTime
|
||||
})
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListComputes by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lc ListComputes) SortByUpdatedTime(inverse bool) ListComputes {
|
||||
if len(lc) < 2 {
|
||||
return lc
|
||||
}
|
||||
|
||||
sort.Slice(lc, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lc[i].UpdatedTime > lc[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lc[i].UpdatedTime < lc[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListComputes by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lc ListComputes) SortByDeletedTime(inverse bool) ListComputes {
|
||||
if len(lc) < 2 {
|
||||
return lc
|
||||
}
|
||||
|
||||
sort.Slice(lc, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lc[i].DeletedTime > lc[j].DeletedTime
|
||||
}
|
||||
|
||||
return lc[i].DeletedTime < lc[j].DeletedTime
|
||||
})
|
||||
|
||||
return lc
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for grant access to compute
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update user access
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/computeci"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/computeci"
|
||||
)
|
||||
|
||||
// Accessing the ComputeCI method group
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package computeci
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to computeci
|
||||
|
||||
51
pkg/cloudapi/computeci/filter.go
Normal file
51
pkg/cloudapi/computeci/filter.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package computeci
|
||||
|
||||
// FilterByID returns ListComputeCI with specified ID.
|
||||
func (lci ListComputeCI) FilterByID(id uint64) ListComputeCI {
|
||||
predicate := func(ic ItemComputeCI) bool {
|
||||
return ic.ID == id
|
||||
}
|
||||
|
||||
return lci.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListComputeCI with specified Name.
|
||||
func (lci ListComputeCI) FilterByName(name string) ListComputeCI {
|
||||
predicate := func(ic ItemComputeCI) bool {
|
||||
return ic.Name == name
|
||||
}
|
||||
|
||||
return lci.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListComputeCI with specified Status.
|
||||
func (lci ListComputeCI) FilterByStatus(status string) ListComputeCI {
|
||||
predicate := func(ic ItemComputeCI) bool {
|
||||
return ic.Status == status
|
||||
}
|
||||
|
||||
return lci.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListComputeCI based on a user-specified predicate.
|
||||
func (lci ListComputeCI) FilterFunc(predicate func(ItemComputeCI) bool) ListComputeCI {
|
||||
var result ListComputeCI
|
||||
|
||||
for _, item := range lci {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemComputeCI
|
||||
// If none was found, returns an empty struct.
|
||||
func (lci ListComputeCI) FindOne() ItemComputeCI {
|
||||
if len(lci) == 0 {
|
||||
return ItemComputeCI{}
|
||||
}
|
||||
|
||||
return lci[0]
|
||||
}
|
||||
43
pkg/cloudapi/computeci/serialize.go
Normal file
43
pkg/cloudapi/computeci/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package computeci
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lci ListComputeCI) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lci) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lci, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lci)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ic ItemComputeCI) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ic, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ic)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/disks"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
|
||||
)
|
||||
|
||||
// Accessing the Disks method group
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create disk
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to disks
|
||||
|
||||
60
pkg/cloudapi/disks/filter.go
Normal file
60
pkg/cloudapi/disks/filter.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package disks
|
||||
|
||||
// FilterByID returns ListDisks with specified ID.
|
||||
func (ld ListDisks) FilterByID(id uint64) ListDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
return idisk.ID == id
|
||||
}
|
||||
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListDisks with specified Name.
|
||||
func (ld ListDisks) FilterByName(name string) ListDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
return idisk.Name == name
|
||||
}
|
||||
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListDisks with specified Status.
|
||||
func (ld ListDisks) FilterByStatus(status string) ListDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
return idisk.Status == status
|
||||
}
|
||||
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByTechStatus returns ListDisks with specified TechStatus.
|
||||
func (ld ListDisks) FilterByTechStatus(techStatus string) ListDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
return idisk.TechStatus == techStatus
|
||||
}
|
||||
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemDisk
|
||||
// If none was found, returns an empty struct.
|
||||
func (ld ListDisks) FindOne() ItemDisk {
|
||||
if len(ld) == 0 {
|
||||
return ItemDisk{}
|
||||
}
|
||||
|
||||
return ld[0]
|
||||
}
|
||||
177
pkg/cloudapi/disks/filter_test.go
Normal file
177
pkg/cloudapi/disks/filter_test.go
Normal file
@@ -0,0 +1,177 @@
|
||||
package disks
|
||||
|
||||
import "testing"
|
||||
|
||||
var disks = ListDisks{
|
||||
ItemDisk{
|
||||
MachineID: 0,
|
||||
MachineName: "",
|
||||
DeviceName: "vda",
|
||||
AccountID: 132847,
|
||||
AccountName: "std_2",
|
||||
ACL: map[string]interface{}{},
|
||||
Computes: map[string]string{
|
||||
"48500": "test",
|
||||
},
|
||||
CreatedTime: 1676975177,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
GID: 212,
|
||||
ID: 65191,
|
||||
ImageID: 9884,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
},
|
||||
Name: "bootdisk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
PCISlot: 6,
|
||||
Pool: "vmstor",
|
||||
PresentTo: []uint64{
|
||||
27,
|
||||
},
|
||||
PurgeTime: 0,
|
||||
ResID: "sample",
|
||||
ResName: "sample",
|
||||
Role: "",
|
||||
Shareable: false,
|
||||
SizeMax: 2,
|
||||
SizeUsed: 2,
|
||||
Snapshots: []ItemSnapshot{},
|
||||
Status: "ASSIGNED",
|
||||
TechStatus: "ALLOCATED",
|
||||
Type: "B",
|
||||
VMID: 48500,
|
||||
},
|
||||
ItemDisk{
|
||||
MachineID: 0,
|
||||
MachineName: "",
|
||||
DeviceName: "vda",
|
||||
AccountID: 132852,
|
||||
AccountName: "std",
|
||||
ACL: map[string]interface{}{},
|
||||
Computes: map[string]string{
|
||||
"48502": "stdvm2",
|
||||
},
|
||||
CreatedTime: 1676982606,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
DestructionTime: 0,
|
||||
GID: 212,
|
||||
ID: 65193,
|
||||
ImageID: 9885,
|
||||
Images: []uint64{},
|
||||
IOTune: IOTune{
|
||||
TotalIOPSSec: 2000,
|
||||
},
|
||||
Name: "bootdisk",
|
||||
Order: 0,
|
||||
Params: "",
|
||||
ParentID: 0,
|
||||
PCISlot: 6,
|
||||
Pool: "vmstor",
|
||||
PresentTo: []uint64{
|
||||
27,
|
||||
27,
|
||||
},
|
||||
PurgeTime: 0,
|
||||
ResID: "sample",
|
||||
ResName: "sample",
|
||||
Role: "",
|
||||
Shareable: false,
|
||||
SizeMax: 4,
|
||||
SizeUsed: 4,
|
||||
Snapshots: []ItemSnapshot{},
|
||||
Status: "ASSIGNED",
|
||||
TechStatus: "ALLOCATED",
|
||||
Type: "B",
|
||||
VMID: 48502,
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := disks.FilterByID(65193)
|
||||
|
||||
if len(actual) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
actualItem := actual.FindOne()
|
||||
|
||||
if actualItem.ID != 65193 {
|
||||
t.Fatal("expected ID 65193, found: ", actualItem.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := disks.FilterByName("bootdisk")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 elements, found: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.Name != "bootdisk" {
|
||||
t.Fatal("expected 'bootdisk' name, found: ", item.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := disks.FilterByStatus("ASSIGNED")
|
||||
|
||||
if len(actual) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.Status != "ASSIGNED" {
|
||||
t.Fatal("expected 'ASSIGNED' status, found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByTechStatus(t *testing.T) {
|
||||
actual := disks.FilterByTechStatus("ALLOCATED")
|
||||
|
||||
if len(actual) == 0 {
|
||||
t.Fatal("No elements were found")
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.TechStatus != "ALLOCATED" {
|
||||
t.Fatal("expected 'ALLOCATED' techStatus, found: ", item.TechStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := disks.FilterFunc(func(id ItemDisk) bool {
|
||||
return len(id.PresentTo) == 2
|
||||
})
|
||||
|
||||
if len(actual) == 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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortByCreatedTime(t *testing.T) {
|
||||
actual := disks.SortByCreatedTime(false)
|
||||
|
||||
if actual[0].ID != 65191 {
|
||||
t.Fatal("expected ID 65191, found: ", actual[0].ID)
|
||||
}
|
||||
|
||||
actual = disks.SortByCreatedTime(true)
|
||||
|
||||
if actual[0].ID != 65193 {
|
||||
t.Fatal("expected ID 65193, found: ", actual[0].ID)
|
||||
}
|
||||
}
|
||||
43
pkg/cloudapi/disks/serialize.go
Normal file
43
pkg/cloudapi/disks/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ld ListDisks) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(ld) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ld, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ld)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (idisk ItemDisk) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(idisk, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(idisk)
|
||||
}
|
||||
60
pkg/cloudapi/disks/sorting.go
Normal file
60
pkg/cloudapi/disks/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package disks
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListDisks by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListDisks) SortByCreatedTime(inverse bool) ListDisks {
|
||||
if len(ld) < 2 {
|
||||
return ld
|
||||
}
|
||||
|
||||
sort.Slice(ld, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ld[i].CreatedTime > ld[j].CreatedTime
|
||||
}
|
||||
|
||||
return ld[i].CreatedTime < ld[j].CreatedTime
|
||||
})
|
||||
|
||||
return ld
|
||||
}
|
||||
|
||||
// SortByDestructionTime sorts ListDisks by the DestructionTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListDisks) SortByDestructionTime(inverse bool) ListDisks {
|
||||
if len(ld) < 2 {
|
||||
return ld
|
||||
}
|
||||
|
||||
sort.Slice(ld, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ld[i].DestructionTime > ld[j].DestructionTime
|
||||
}
|
||||
|
||||
return ld[i].DestructionTime < ld[j].DestructionTime
|
||||
})
|
||||
|
||||
return ld
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListDisks by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ld ListDisks) SortByDeletedTime(inverse bool) ListDisks {
|
||||
if len(ld) < 2 {
|
||||
return ld
|
||||
}
|
||||
|
||||
sort.Slice(ld, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ld[i].DeletedTime > ld[j].DeletedTime
|
||||
}
|
||||
|
||||
return ld[i].DeletedTime < ld[j].DeletedTime
|
||||
})
|
||||
|
||||
return ld
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/extnet"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
|
||||
)
|
||||
|
||||
// Accessing the ExtNet method group
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to extnet
|
||||
|
||||
51
pkg/cloudapi/extnet/filter.go
Normal file
51
pkg/cloudapi/extnet/filter.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package extnet
|
||||
|
||||
// FilterByID returns ListExtNets with specified ID.
|
||||
func (lenet ListExtNets) FilterByID(id uint64) ListExtNets {
|
||||
predicate := func(iexnet ItemExtNet) bool {
|
||||
return iexnet.ID == id
|
||||
}
|
||||
|
||||
return lenet.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListExtNets with specified Name.
|
||||
func (lenet ListExtNets) FilterByName(name string) ListExtNets {
|
||||
predicate := func(iexnet ItemExtNet) bool {
|
||||
return iexnet.Name == name
|
||||
}
|
||||
|
||||
return lenet.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListExtNets with specified Status.
|
||||
func (lenet ListExtNets) FilterByStatus(status string) ListExtNets {
|
||||
predicate := func(iexnet ItemExtNet) bool {
|
||||
return iexnet.Status == status
|
||||
}
|
||||
|
||||
return lenet.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListExtNets based on a user-specified predicate.
|
||||
func (lenet ListExtNets) FilterFunc(predicate func(ItemExtNet) bool) ListExtNets {
|
||||
var result ListExtNets
|
||||
|
||||
for _, item := range lenet {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemExtNet
|
||||
// If none was found, returns an empty struct.
|
||||
func (lenet ListExtNets) FindOne() ItemExtNet {
|
||||
if len(lenet) == 0 {
|
||||
return ItemExtNet{}
|
||||
}
|
||||
|
||||
return lenet[0]
|
||||
}
|
||||
65
pkg/cloudapi/extnet/filter_test.go
Normal file
65
pkg/cloudapi/extnet/filter_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package extnet
|
||||
|
||||
import "testing"
|
||||
|
||||
var extnets = ListExtNets{
|
||||
ItemExtNet{
|
||||
ID: 3,
|
||||
IPCIDR: "176.118.164.0/24",
|
||||
Name: "176.118.164.0/24",
|
||||
Status: "ENABLED",
|
||||
},
|
||||
ItemExtNet{
|
||||
ID: 10,
|
||||
IPCIDR: "45.134.255.0/24",
|
||||
Name: "45.134.255.0/24",
|
||||
Status: "ENABLED",
|
||||
},
|
||||
ItemExtNet{
|
||||
ID: 13,
|
||||
IPCIDR: "88.218.249.0/24",
|
||||
Name: "88.218.249.0/24",
|
||||
Status: "DISABLED",
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := extnets.FilterByID(10).FindOne()
|
||||
|
||||
if actual.ID != 10 {
|
||||
t.Fatal("expected ID 10, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
name := "88.218.249.0/24"
|
||||
actual := extnets.FilterByName(name).FindOne()
|
||||
|
||||
if actual.Name != name {
|
||||
t.Fatal("expected ", name, " found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := extnets.FilterByStatus("ENABLED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := extnets.FilterFunc(func(ien ItemExtNet) bool {
|
||||
return ien.IPCIDR == ien.Name
|
||||
})
|
||||
|
||||
if len(actual) != 3 {
|
||||
t.Fatal("expected 3 elements, found: ", len(actual))
|
||||
}
|
||||
}
|
||||
43
pkg/cloudapi/extnet/serialize.go
Normal file
43
pkg/cloudapi/extnet/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lenet ListExtNets) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lenet) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lenet, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lenet)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ienet ItemExtNet) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ienet, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ienet)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/flipgroup"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup"
|
||||
)
|
||||
|
||||
// Accessing the FLIPGroup method group
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create FLIPGroup
|
||||
|
||||
96
pkg/cloudapi/flipgroup/filter.go
Normal file
96
pkg/cloudapi/flipgroup/filter.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package flipgroup
|
||||
|
||||
// FilterByID returns ListFLIPGroups with specified ID.
|
||||
func (lfg ListFLIPGroups) FilterByID(id uint64) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.ID == id
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByAccountID returns ListFLIPGroups with specified AccountID.
|
||||
func (lfg ListFLIPGroups) FilterByAccountID(accountID uint64) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.AccountID == accountID
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByRGID returns ListFLIPGroups with specified RGID.
|
||||
func (lfg ListFLIPGroups) FilterByRGID(rgID uint64) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.RGID == rgID
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListFLIPGroups with specified Name.
|
||||
func (lfg ListFLIPGroups) FilterByName(name string) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.Name == name
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListFLIPGroups with specified Status.
|
||||
func (lfg ListFLIPGroups) FilterByStatus(status string) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.Status == status
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByCreatedBy returns ListFLIPGroups created by specified user.
|
||||
func (lfg ListFLIPGroups) FilterByCreatedBy(createdBy string) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.CreatedBy == createdBy
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByUpdatedBy returns ListFLIPGroups updated by specified user.
|
||||
func (lfg ListFLIPGroups) FilterByUpdatedBy(updatedBy string) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.UpdatedBy == updatedBy
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDeletedBy returns ListFLIPGroups deleted by specified user.
|
||||
func (lfg ListFLIPGroups) FilterByDeletedBy(deletedBy string) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.DeletedBy == deletedBy
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListFLIPGroups based on a user-specified predicate.
|
||||
func (lfg ListFLIPGroups) FilterFunc(predicate func(ItemFLIPGroup) bool) ListFLIPGroups {
|
||||
var result ListFLIPGroups
|
||||
|
||||
for _, item := range lfg {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemFLIPGroup
|
||||
// If none was found, returns an empty struct.
|
||||
func (lfg ListFLIPGroups) FindOne() ItemFLIPGroup {
|
||||
if len(lfg) == 0 {
|
||||
return ItemFLIPGroup{}
|
||||
}
|
||||
|
||||
return lfg[0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package flipgroup
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to FLIPGroup
|
||||
|
||||
43
pkg/cloudapi/flipgroup/serialize.go
Normal file
43
pkg/cloudapi/flipgroup/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package flipgroup
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lfg ListFLIPGroups) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lfg) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lfg, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lfg)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ifg ItemFLIPGroup) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ifg, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ifg)
|
||||
}
|
||||
60
pkg/cloudapi/flipgroup/sorting.go
Normal file
60
pkg/cloudapi/flipgroup/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package flipgroup
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListFLIPGroups by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lfg ListFLIPGroups) SortByCreatedTime(inverse bool) ListFLIPGroups {
|
||||
if len(lfg) < 2 {
|
||||
return lfg
|
||||
}
|
||||
|
||||
sort.Slice(lfg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lfg[i].CreatedTime > lfg[j].CreatedTime
|
||||
}
|
||||
|
||||
return lfg[i].CreatedTime < lfg[j].CreatedTime
|
||||
})
|
||||
|
||||
return lfg
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListFLIPGroups by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lfg ListFLIPGroups) SortByUpdatedTime(inverse bool) ListFLIPGroups {
|
||||
if len(lfg) < 2 {
|
||||
return lfg
|
||||
}
|
||||
|
||||
sort.Slice(lfg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lfg[i].UpdatedTime > lfg[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lfg[i].UpdatedTime < lfg[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lfg
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListFLIPGroups by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lfg ListFLIPGroups) SortByDeletedTime(inverse bool) ListFLIPGroups {
|
||||
if len(lfg) < 2 {
|
||||
return lfg
|
||||
}
|
||||
|
||||
sort.Slice(lfg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lfg[i].DeletedTime > lfg[j].DeletedTime
|
||||
}
|
||||
|
||||
return lfg[i].DeletedTime < lfg[j].DeletedTime
|
||||
})
|
||||
|
||||
return lfg
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/image"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/image"
|
||||
)
|
||||
|
||||
// Accessing the Image method group
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create image
|
||||
|
||||
60
pkg/cloudapi/image/filter.go
Normal file
60
pkg/cloudapi/image/filter.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package image
|
||||
|
||||
// FilterByID returns ListImages with specified ID.
|
||||
func (li ListImages) FilterByID(id uint64) ListImages {
|
||||
predicate := func(ii ItemImage) bool {
|
||||
return ii.ID == id
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListImages with specified Name.
|
||||
func (li ListImages) FilterByName(name string) ListImages {
|
||||
predicate := func(ii ItemImage) bool {
|
||||
return ii.Name == name
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListImages with specified Status.
|
||||
func (li ListImages) FilterByStatus(status string) ListImages {
|
||||
predicate := func(ii ItemImage) bool {
|
||||
return ii.Status == status
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByBootType returns ListImages with specified BootType.
|
||||
func (li ListImages) FilterByBootType(bootType string) ListImages {
|
||||
predicate := func(ii ItemImage) bool {
|
||||
return ii.BootType == bootType
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListImages based on a user-specified predicate.
|
||||
func (li ListImages) FilterFunc(predicate func(ItemImage) bool) ListImages {
|
||||
var result ListImages
|
||||
|
||||
for _, item := range li {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemImage
|
||||
// If none was found, returns an empty struct.
|
||||
func (li ListImages) FindOne() ItemImage {
|
||||
if len(li) == 0 {
|
||||
return ItemImage{}
|
||||
}
|
||||
|
||||
return li[0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to image
|
||||
|
||||
43
pkg/cloudapi/image/serialize.go
Normal file
43
pkg/cloudapi/image/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (li ListImages) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(li) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(li, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(li)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ii ItemImage) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ii, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ii)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/k8ci"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/k8ci"
|
||||
)
|
||||
|
||||
// Accessing the K8CI method group
|
||||
|
||||
42
pkg/cloudapi/k8ci/filter.go
Normal file
42
pkg/cloudapi/k8ci/filter.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package k8ci
|
||||
|
||||
// FilterByID returns ListK8CI with specified ID.
|
||||
func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.RecordK8CI.ID == id
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListK8CI with specified Name.
|
||||
func (lkc ListK8CI) FilterByName(name string) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.RecordK8CI.Name == name
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListK8CI based on a user-specified predicate.
|
||||
func (lkc ListK8CI) FilterFunc(predicate func(ItemK8CI) bool) ListK8CI {
|
||||
var result ListK8CI
|
||||
|
||||
for _, item := range lkc {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemK8CI
|
||||
// If none was found, returns an empty struct.
|
||||
func (lkc ListK8CI) FindOne() ItemK8CI {
|
||||
if len(lkc) == 0 {
|
||||
return ItemK8CI{}
|
||||
}
|
||||
|
||||
return lkc[0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to K8CI
|
||||
|
||||
43
pkg/cloudapi/k8ci/serialize.go
Normal file
43
pkg/cloudapi/k8ci/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lkc ListK8CI) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lkc) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lkc, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lkc)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ikc ItemK8CI) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ikc, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ikc)
|
||||
}
|
||||
22
pkg/cloudapi/k8ci/sorting.go
Normal file
22
pkg/cloudapi/k8ci/sorting.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package k8ci
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListK8CI by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lkc ListK8CI) SortByCreatedTime(inverse bool) ListK8CI {
|
||||
if len(lkc) < 2 {
|
||||
return lkc
|
||||
}
|
||||
|
||||
sort.Slice(lkc, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lkc[i].CreatedTime > lkc[j].CreatedTime
|
||||
}
|
||||
|
||||
return lkc[i].CreatedTime < lkc[j].CreatedTime
|
||||
})
|
||||
|
||||
return lkc
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/k8s"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||
)
|
||||
|
||||
// Accessing the K8S method group
|
||||
|
||||
96
pkg/cloudapi/k8s/filter.go
Normal file
96
pkg/cloudapi/k8s/filter.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package k8s
|
||||
|
||||
// FilterByID returns ListK8SClusters with specified ID.
|
||||
func (lkc ListK8SClusters) FilterByID(id uint64) ListK8SClusters {
|
||||
predicate := func(ikc ItemK8SCluster) bool {
|
||||
return ikc.ID == id
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListK8SClusters with specified Name.
|
||||
func (lkc ListK8SClusters) FilterByName(name string) ListK8SClusters {
|
||||
predicate := func(ikc ItemK8SCluster) bool {
|
||||
return ikc.Name == name
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByAccountID returns ListK8SClusters with specified AccountID.
|
||||
func (lkc ListK8SClusters) FilterByAccountID(accountID uint64) ListK8SClusters {
|
||||
predicate := func(ikc ItemK8SCluster) bool {
|
||||
return ikc.AccountID == accountID
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByRGID returns ListK8SClusters with specified RGID.
|
||||
func (lkc ListK8SClusters) FilterByRGID(rgID uint64) ListK8SClusters {
|
||||
predicate := func(ikc ItemK8SCluster) bool {
|
||||
return ikc.RGID == rgID
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListK8SClusters with specified Status.
|
||||
func (lkc ListK8SClusters) FilterByStatus(status string) ListK8SClusters {
|
||||
predicate := func(ikc ItemK8SCluster) bool {
|
||||
return ikc.Status == status
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByTechStatus returns ListK8SClusters with specified TechStatus.
|
||||
func (lkc ListK8SClusters) FilterByTechStatus(techStatus string) ListK8SClusters {
|
||||
predicate := func(ikc ItemK8SCluster) bool {
|
||||
return ikc.TechStatus == techStatus
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByCreatedBy returns ListK8SClusters created by specified user.
|
||||
func (lkc ListK8SClusters) FilterByCreatedBy(createdBy string) ListK8SClusters {
|
||||
predicate := func(ikc ItemK8SCluster) bool {
|
||||
return ikc.CreatedBy == createdBy
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDeletedBy returns ListK8SClusters deleted by specified user.
|
||||
func (lkc ListK8SClusters) FilterByDeletedBy(deletedBy string) ListK8SClusters {
|
||||
predicate := func(ikc ItemK8SCluster) bool {
|
||||
return ikc.DeletedBy == deletedBy
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListK8SClusters based on a user-specified predicate.
|
||||
func (lkc ListK8SClusters) FilterFunc(predicate func(ItemK8SCluster) bool) ListK8SClusters {
|
||||
var result ListK8SClusters
|
||||
|
||||
for _, item := range lkc {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemK8SCluster
|
||||
// If none was found, returns an empty struct.
|
||||
func (lkc ListK8SClusters) FindOne() ItemK8SCluster {
|
||||
if len(lkc) == 0 {
|
||||
return ItemK8SCluster{}
|
||||
}
|
||||
|
||||
return lkc[0]
|
||||
}
|
||||
188
pkg/cloudapi/k8s/filter_test.go
Normal file
188
pkg/cloudapi/k8s/filter_test.go
Normal file
@@ -0,0 +1,188 @@
|
||||
package k8s
|
||||
|
||||
import "testing"
|
||||
|
||||
var k8sItems = ListK8SClusters{
|
||||
ItemK8SCluster{
|
||||
AccountID: 1,
|
||||
AccountName: "test_1",
|
||||
ACL: []interface{}{},
|
||||
BServiceID: 1,
|
||||
CIID: 1,
|
||||
Config: nil,
|
||||
CreatedBy: "test_user",
|
||||
CreatedTime: 132454563,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
ExtNetID: 1,
|
||||
GID: 0,
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
LBID: 1,
|
||||
Milestones: 999999,
|
||||
Name: "k8s_1",
|
||||
RGID: 1,
|
||||
RGName: "rg_1",
|
||||
Status: "ENABLED",
|
||||
TechStatus: "STARTED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINSID: 0,
|
||||
},
|
||||
ItemK8SCluster{
|
||||
AccountID: 2,
|
||||
AccountName: "test_2",
|
||||
ACL: []interface{}{},
|
||||
BServiceID: 2,
|
||||
CIID: 2,
|
||||
Config: nil,
|
||||
CreatedBy: "test_user",
|
||||
CreatedTime: 132454638,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
ExtNetID: 2,
|
||||
GID: 0,
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
LBID: 2,
|
||||
Milestones: 999999,
|
||||
Name: "k8s_2",
|
||||
RGID: 2,
|
||||
RGName: "rg_2",
|
||||
Status: "ENABLED",
|
||||
TechStatus: "STARTED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINSID: 0,
|
||||
},
|
||||
ItemK8SCluster{
|
||||
AccountID: 3,
|
||||
AccountName: "test_3",
|
||||
ACL: []interface{}{},
|
||||
BServiceID: 3,
|
||||
CIID: 3,
|
||||
Config: nil,
|
||||
CreatedBy: "test_user",
|
||||
CreatedTime: 132454682,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
ExtNetID: 3,
|
||||
GID: 0,
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
LBID: 3,
|
||||
Milestones: 999999,
|
||||
Name: "k8s_3",
|
||||
RGID: 3,
|
||||
RGName: "rg_3",
|
||||
Status: "DISABLED",
|
||||
TechStatus: "STOPPED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINSID: 0,
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := k8sItems.FilterByID(1).FindOne()
|
||||
|
||||
if actual.ID != 1 {
|
||||
t.Fatal("expected 1 ID, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := k8sItems.FilterByName("k8s_3").FindOne()
|
||||
|
||||
if actual.Name != "k8s_3" {
|
||||
t.Fatal("expected Name 'k8s_3', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByAccountID(t *testing.T) {
|
||||
actual := k8sItems.FilterByAccountID(2).FindOne()
|
||||
|
||||
if actual.AccountID != 2 {
|
||||
t.Fatal("expected AccountID 2, found: ", actual.AccountID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByRGID(t *testing.T) {
|
||||
actual := k8sItems.FilterByRGID(3).FindOne()
|
||||
|
||||
if actual.RGID != 3 {
|
||||
t.Fatal("expected RGID 3, found: ", actual.RGID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := k8sItems.FilterByStatus("ENABLED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByTechStatus(t *testing.T) {
|
||||
actual := k8sItems.FilterByTechStatus("STARTED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.TechStatus != "STARTED" {
|
||||
t.Fatal("expected TechStatus 'STARTED', found: ", item.TechStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByCreatedBy(t *testing.T) {
|
||||
actual := k8sItems.FilterByCreatedBy("test_user")
|
||||
|
||||
if len(actual) != 3 {
|
||||
t.Fatal("expected 3 found, actual: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.CreatedBy != "test_user" {
|
||||
t.Fatal("expected CreatedBy 'test_user', found: ", item.CreatedBy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByDeletedBy(t *testing.T) {
|
||||
actual := k8sItems.FilterByDeletedBy("test_user")
|
||||
|
||||
if len(actual) != 0 {
|
||||
t.Fatal("expected 0 found, actual: ", len(actual))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := k8sItems.FilterFunc(func(iks ItemK8SCluster) bool {
|
||||
return iks.AccountName == "test_2"
|
||||
}).
|
||||
FindOne()
|
||||
|
||||
if actual.AccountName != "test_2" {
|
||||
t.Fatal("expected AccountName 'test_2', found: ", actual.AccountName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortByCreatedTime(t *testing.T) {
|
||||
actual := k8sItems.SortByCreatedTime(false)
|
||||
|
||||
if actual[0].CreatedTime != 132454563 || actual[2].CreatedTime != 132454682 {
|
||||
t.Fatal("expected ascending sort, seems to be inversed")
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to K8S
|
||||
|
||||
43
pkg/cloudapi/k8s/serialize.go
Normal file
43
pkg/cloudapi/k8s/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lkc ListK8SClusters) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lkc) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lkc, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lkc)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ikc ItemK8SCluster) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ikc, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ikc)
|
||||
}
|
||||
60
pkg/cloudapi/k8s/sorting.go
Normal file
60
pkg/cloudapi/k8s/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package k8s
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListK8SClusters by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lkc ListK8SClusters) SortByCreatedTime(inverse bool) ListK8SClusters {
|
||||
if len(lkc) < 2 {
|
||||
return lkc
|
||||
}
|
||||
|
||||
sort.Slice(lkc, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lkc[i].CreatedTime > lkc[j].CreatedTime
|
||||
}
|
||||
|
||||
return lkc[i].CreatedTime < lkc[j].CreatedTime
|
||||
})
|
||||
|
||||
return lkc
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListK8SClusters by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lkc ListK8SClusters) SortByUpdatedTime(inverse bool) ListK8SClusters {
|
||||
if len(lkc) < 2 {
|
||||
return lkc
|
||||
}
|
||||
|
||||
sort.Slice(lkc, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lkc[i].UpdatedTime > lkc[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lkc[i].UpdatedTime < lkc[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lkc
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListK8SClusters by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lkc ListK8SClusters) SortByDeletedTime(inverse bool) ListK8SClusters {
|
||||
if len(lkc) < 2 {
|
||||
return lkc
|
||||
}
|
||||
|
||||
sort.Slice(lkc, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lkc[i].DeletedTime > lkc[j].DeletedTime
|
||||
}
|
||||
|
||||
return lkc[i].DeletedTime < lkc[j].DeletedTime
|
||||
})
|
||||
|
||||
return lkc
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package cloudapi
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmppc"
|
||||
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/kvmppc"
|
||||
|
||||
// Accessing the KVMPPC method group
|
||||
func (ca *CloudAPI) KVMPPC() *kvmppc.KVMPPC {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package kvmppc
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to KVMPPC
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/kvmx86"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/kvmx86"
|
||||
)
|
||||
|
||||
// Accessing the KVMX86 method group
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package kvmx86
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to KVMX86
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cloudapi
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/lb"
|
||||
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
||||
|
||||
// Accessing the LB method group
|
||||
func (ca *CloudAPI) LB() *lb.LB {
|
||||
|
||||
60
pkg/cloudapi/lb/filter.go
Normal file
60
pkg/cloudapi/lb/filter.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package lb
|
||||
|
||||
// FilterByID returns ListLB with specified ID.
|
||||
func (ll ListLB) FilterByID(id uint64) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.ID == id
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListLB with specified Name.
|
||||
func (ll ListLB) FilterByName(name string) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.Name == name
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByExtNetID returns ListLB with specified ExtNetID.
|
||||
func (ll ListLB) FilterByExtNetID(extNetID uint64) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.ExtNetID == extNetID
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByImageID returns ListLB with specified ImageID.
|
||||
func (ll ListLB) FilterByImageID(imageID uint64) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.ImageID == imageID
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemLoadBalancer
|
||||
// If none was found, returns an empty struct.
|
||||
func (ll ListLB) FindOne() ItemLoadBalancer {
|
||||
if len(ll) == 0 {
|
||||
return ItemLoadBalancer{}
|
||||
}
|
||||
|
||||
return ll[0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to load balancer
|
||||
|
||||
43
pkg/cloudapi/lb/serialize.go
Normal file
43
pkg/cloudapi/lb/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ll ListLB) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(ll) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ll, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ll)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ill ItemLoadBalancer) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ill, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ill)
|
||||
}
|
||||
60
pkg/cloudapi/lb/sorting.go
Normal file
60
pkg/cloudapi/lb/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package lb
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListLB by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
|
||||
if len(ll) < 2 {
|
||||
return ll
|
||||
}
|
||||
|
||||
sort.Slice(ll, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ll[i].CreatedTime > ll[j].CreatedTime
|
||||
}
|
||||
|
||||
return ll[i].CreatedTime < ll[j].CreatedTime
|
||||
})
|
||||
|
||||
return ll
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListLB by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
|
||||
if len(ll) < 2 {
|
||||
return ll
|
||||
}
|
||||
|
||||
sort.Slice(ll, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ll[i].UpdatedTime > ll[j].UpdatedTime
|
||||
}
|
||||
|
||||
return ll[i].UpdatedTime < ll[j].UpdatedTime
|
||||
})
|
||||
|
||||
return ll
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListLB by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ll ListLB) SortByDeletedTime(inverse bool) ListLB {
|
||||
if len(ll) < 2 {
|
||||
return ll
|
||||
}
|
||||
|
||||
sort.Slice(ll, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ll[i].DeletedTime > ll[j].DeletedTime
|
||||
}
|
||||
|
||||
return ll[i].DeletedTime < ll[j].DeletedTime
|
||||
})
|
||||
|
||||
return ll
|
||||
}
|
||||
42
pkg/cloudapi/locations/filter.go
Normal file
42
pkg/cloudapi/locations/filter.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package locations
|
||||
|
||||
// FilterByID returns ListLocations with specified ID.
|
||||
func (ll ListLocations) FilterByID(id uint64) ListLocations {
|
||||
predicate := func(il ItemLocation) bool {
|
||||
return il.ID == id
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListLocations with specified Name.
|
||||
func (ll ListLocations) FilterByName(name string) ListLocations {
|
||||
predicate := func(il ItemLocation) bool {
|
||||
return il.Name == name
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListLocations based on a user-specified predicate.
|
||||
func (ll ListLocations) FilterFunc(predicate func(ItemLocation) bool) ListLocations {
|
||||
var result ListLocations
|
||||
|
||||
for _, item := range ll {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemLocation
|
||||
// If none was found, returns an empty struct.
|
||||
func (ll ListLocations) FindOne() ItemLocation {
|
||||
if len(ll) == 0 {
|
||||
return ItemLocation{}
|
||||
}
|
||||
|
||||
return ll[0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package locations
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to locations
|
||||
|
||||
43
pkg/cloudapi/locations/serialize.go
Normal file
43
pkg/cloudapi/locations/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package locations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ll ListLocations) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(ll) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ll, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ll)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (il ItemLocation) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(il, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(il)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package cloudapi
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/locations"
|
||||
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/locations"
|
||||
|
||||
// Accessing the Locations method group
|
||||
func (ca *CloudAPI) Locations() *locations.Locations {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cloudapi
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/rg"
|
||||
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
|
||||
|
||||
// Accessing the RG method group
|
||||
func (ca *CloudAPI) RG() *rg.RG {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for grant access to resource group
|
||||
|
||||
78
pkg/cloudapi/rg/filter.go
Normal file
78
pkg/cloudapi/rg/filter.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package rg
|
||||
|
||||
// FilterByID returns ListResourceGroups with specified ID.
|
||||
func (lrg ListResourceGroups) FilterByID(id uint64) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.ID == id
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListResourceGroups with specified Name.
|
||||
func (lrg ListResourceGroups) FilterByName(name string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.Name == name
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByCreatedBy return ListResourceGroups created by specified user.
|
||||
func (lrg ListResourceGroups) FilterByCreatedBy(createdBy string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.CreatedBy == createdBy
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListResourceGroups with specified Status.
|
||||
func (lrg ListResourceGroups) FilterByStatus(status string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.Status == status
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByLockStatus return ListResourceGroups with specified LockStatus.
|
||||
func (lrg ListResourceGroups) FilterByLockStatus(lockStatus string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.LockStatus == lockStatus
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDefNetType returns ListResourceGroups with specified DefNetType.
|
||||
func (lrg ListResourceGroups) FilterByDefNetType(defNetType string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.DefNetType == defNetType
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListResourceGroups based on a user-specified predicate.
|
||||
func (lrg ListResourceGroups) FilterFunc(predicate func(irg ItemResourceGroup) bool) ListResourceGroups {
|
||||
var result ListResourceGroups
|
||||
|
||||
for _, rgItem := range lrg {
|
||||
if predicate(rgItem) {
|
||||
result = append(result, rgItem)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemResourceGroup.
|
||||
// If none was found, returns an empty struct.
|
||||
func (lrg ListResourceGroups) FindOne() ItemResourceGroup {
|
||||
if len(lrg) == 0 {
|
||||
return ItemResourceGroup{}
|
||||
}
|
||||
|
||||
return lrg[0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to resource group
|
||||
|
||||
43
pkg/cloudapi/rg/serialize.go
Normal file
43
pkg/cloudapi/rg/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lrg ListResourceGroups) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lrg) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lrg, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lrg)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (irg ItemResourceGroup) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(irg, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(irg)
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for set default network
|
||||
|
||||
60
pkg/cloudapi/rg/sorting.go
Normal file
60
pkg/cloudapi/rg/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package rg
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListResourceGroups by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByCreatedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg[i].CreatedTime > lrg[j].CreatedTime
|
||||
}
|
||||
|
||||
return lrg[i].CreatedTime < lrg[j].CreatedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListResourceGroups by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByUpdatedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg[i].UpdatedTime > lrg[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lrg[i].UpdatedTime < lrg[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListResourceGroups by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByDeletedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg[i].DeletedTime > lrg[j].DeletedTime
|
||||
}
|
||||
|
||||
return lrg[i].DeletedTime < lrg[j].DeletedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/sizes"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/sizes"
|
||||
)
|
||||
|
||||
// Accessing the Sizes method group
|
||||
|
||||
42
pkg/cloudapi/sizes/filter.go
Normal file
42
pkg/cloudapi/sizes/filter.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package sizes
|
||||
|
||||
// FilterByID returns ListSizes with specified ID.
|
||||
func (ls ListSizes) FilterByID(id uint64) ListSizes {
|
||||
predicate := func(is ItemSize) bool {
|
||||
return is.ID == id
|
||||
}
|
||||
|
||||
return ls.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListSizes with specified Name.
|
||||
func (ls ListSizes) FilterByName(name string) ListSizes {
|
||||
predicate := func(is ItemSize) bool {
|
||||
return is.Name == name
|
||||
}
|
||||
|
||||
return ls.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListSizes based on a user-specified predicate.
|
||||
func (ls ListSizes) FilterFunc(predicate func(ItemSize) bool) ListSizes {
|
||||
var result ListSizes
|
||||
|
||||
for _, item := range ls {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemSize
|
||||
// If none was found, returns an empty struct.
|
||||
func (ls ListSizes) FindOne() ItemSize {
|
||||
if len(ls) == 0 {
|
||||
return ItemSize{}
|
||||
}
|
||||
|
||||
return ls[0]
|
||||
}
|
||||
43
pkg/cloudapi/sizes/serialize.go
Normal file
43
pkg/cloudapi/sizes/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package sizes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ls ListSizes) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(ls) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ls, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ls)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (is ItemSize) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(is, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(is)
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
package sizes
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creatig request to sizes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/tasks"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/tasks"
|
||||
)
|
||||
|
||||
// Accessing the Tasks method group
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to tasks
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/vins"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
)
|
||||
|
||||
// Accessing the VINS method group
|
||||
|
||||
78
pkg/cloudapi/vins/filter.go
Normal file
78
pkg/cloudapi/vins/filter.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package vins
|
||||
|
||||
// FilterByID returns ListVINS with specified ID.
|
||||
func (lv ListVINS) FilterByID(id uint64) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.ID == id
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListVINS with specified Name.
|
||||
func (lv ListVINS) FilterByName(name string) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.Name == name
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByAccountID returns ListVINS with specified AccountID.
|
||||
func (lv ListVINS) FilterByAccountID(accountID uint64) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.AccountID == accountID
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByCreatedBy returns ListVINS created by specified user.
|
||||
func (lv ListVINS) FilterByCreatedBy(createdBy string) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.CreatedBy == createdBy
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByUpdatedBy returns ListVINS updated by specified user.
|
||||
func (lv ListVINS) FilterByUpdatedBy(updatedBy string) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.UpdatedBy == updatedBy
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDeletedBy returns ListVINS deleted by specified user.
|
||||
func (lv ListVINS) FilterByDeletedBy(deletedBy string) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.DeletedBy == deletedBy
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListVINS based on a user-specified predicate.
|
||||
func (lv ListVINS) FilterFunc(predicate func(ItemVINS) bool) ListVINS {
|
||||
var result ListVINS
|
||||
|
||||
for _, item := range lv {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemVINS
|
||||
// If none was found, returns an empty struct.
|
||||
func (lv ListVINS) FindOne() ItemVINS {
|
||||
if len(lv) == 0 {
|
||||
return ItemVINS{}
|
||||
}
|
||||
|
||||
return lv[0]
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for IP reserve
|
||||
|
||||
43
pkg/cloudapi/vins/serialize.go
Normal file
43
pkg/cloudapi/vins/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lv ListVINS) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lv) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lv, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lv)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (iv ItemVINS) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(iv, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(iv)
|
||||
}
|
||||
60
pkg/cloudapi/vins/sorting.go
Normal file
60
pkg/cloudapi/vins/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package vins
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListVINS by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lv ListVINS) SortByCreatedTime(inverse bool) ListVINS {
|
||||
if len(lv) < 2 {
|
||||
return lv
|
||||
}
|
||||
|
||||
sort.Slice(lv, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lv[i].CreatedTime > lv[j].CreatedTime
|
||||
}
|
||||
|
||||
return lv[i].CreatedTime < lv[j].CreatedTime
|
||||
})
|
||||
|
||||
return lv
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListVINS by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lv ListVINS) SortByUpdatedTime(inverse bool) ListVINS {
|
||||
if len(lv) < 2 {
|
||||
return lv
|
||||
}
|
||||
|
||||
sort.Slice(lv, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lv[i].UpdatedTime > lv[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lv[i].UpdatedTime < lv[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lv
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListVINS by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lv ListVINS) SortByDeletedTime(inverse bool) ListVINS {
|
||||
if len(lv) < 2 {
|
||||
return lv
|
||||
}
|
||||
|
||||
sort.Slice(lv, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lv[i].DeletedTime > lv[j].DeletedTime
|
||||
}
|
||||
|
||||
return lv[i].DeletedTime < lv[j].DeletedTime
|
||||
})
|
||||
|
||||
return lv
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to VINS
|
||||
|
||||
Reference in New Issue
Block a user