This commit is contained in:
2023-03-14 14:45:51 +03:00
parent 42800ac4fe
commit f3a1a4c83f
202 changed files with 6199 additions and 155 deletions

View File

@@ -1,7 +1,7 @@
package cloudbroker
import (
"github.com/rudecs/decort-sdk/pkg/cloudbroker/account"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
)
// Accessing the Account method group

View File

@@ -1,7 +1,7 @@
// API Actor API for managing account
package account
import "github.com/rudecs/decort-sdk/interfaces"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to account
type Account struct {

View File

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

View File

@@ -0,0 +1,86 @@
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.UserGroupID == userGroupID {
return true
}
}
return false
}
return la.FilterFunc(predicate)
}
// FilterByCompany returns ListAccounts with specified Company.
func (la ListAccounts) FilterByCompany(company string) ListAccounts {
predicate := func(ia ItemAccount) bool {
return ia.Company == company
}
return la.FilterFunc(predicate)
}
// FilterByCreatedBy returns ListAccounts created by specified user.
func (la ListAccounts) FilterByCreatedBy(createdBy string) ListAccounts {
predicate := func(ia ItemAccount) bool {
return ia.CreatedBy == createdBy
}
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 _, item := range la {
if predicate(item) {
result = append(result, item)
}
}
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]
}

View File

@@ -0,0 +1,155 @@
package account
import (
"testing"
)
var accounts = ListAccounts{
ItemAccount{
Meta: []interface{}{},
InfoAccount: InfoAccount{
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "not_really_timofey_tkachev_1@decs3o",
},
},
CreatedTime: 1676878820,
DeletedTime: 0,
ID: 132847,
Name: "std_2",
Status: "CONFIRMED",
UpdatedTime: 1676645275,
},
},
ItemAccount{
Meta: []interface{}{},
InfoAccount: InfoAccount{
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "timofey_tkachev_1@decs3o",
},
},
CreatedTime: 1676645275,
DeletedTime: 1677723401,
ID: 132846,
Name: "std",
Status: "DELETED",
UpdatedTime: 1676645275,
},
},
ItemAccount{
Meta: []interface{}{},
InfoAccount: InfoAccount{
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "timofey_tkachev_1@decs3o",
},
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "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.UserGroupID == "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("DELETED")
if len(actual) != 2 {
t.Fatal("Expected 2 elements in slice, found: ", len(actual))
}
for _, item := range actual {
if item.Status != "DELETED" {
t.Fatal("expected DELETED, 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))
}
}

View 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)
}

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

View File

@@ -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 resource types in account

View File

@@ -1,7 +1,7 @@
// List of method groups for the admin
package cloudbroker
import "github.com/rudecs/decort-sdk/interfaces"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to CloudBroker groups
type CloudBroker struct {

View File

@@ -1,7 +1,7 @@
package cloudbroker
import (
"github.com/rudecs/decort-sdk/pkg/cloudbroker/compute"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
)
// Accessing the Compute method group

View File

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

View File

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

View File

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

View File

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

View File

@@ -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 set boot order

View File

@@ -1,7 +1,7 @@
// API Actor for managing Compute. This actor is a final API for admin to manage Compute
package compute
import "github.com/rudecs/decort-sdk/interfaces"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to compute
type Compute struct {

View 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]
}

View File

@@ -0,0 +1,247 @@
package compute
import (
"testing"
)
var computes = ListComputes{
ItemCompute{
Disks: []InfoDisk{
{
ID: 65191,
PCISlot: 6,
},
},
InfoCompute: InfoCompute{
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",
},
},
Arch: "X86_64",
BootOrder: []string{
"hd", "cdrom",
},
BootDiskSize: 0,
CloneReference: 0,
Clones: []uint64{},
ComputeCIID: 0,
CPUs: 4,
CreatedBy: "timofey_tkachev_1@decs3o",
CreatedTime: 1676975175,
CustomFields: map[string]interface{}{},
DeletedBy: "",
DeletedTime: 0,
Description: "",
Devices: nil,
Driver: "KVM_X86",
GID: 212,
GUID: 48500,
ID: 48500,
ImageID: 9884,
Interfaces: ListInterfaces{},
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: ListSnapshots{},
StatelessSEPID: 0,
StatelessSEPType: "",
Status: "ENABLED",
Tags: map[string]interface{}{},
TechStatus: "STOPPED",
TotalDiskSize: 2,
UpdatedBy: "",
UpdatedTime: 1677058904,
UserManaged: true,
VGPUs: []uint64{},
VINSConnected: 0,
VirtualImageID: 0,
},
},
ItemCompute{
Disks: []InfoDisk{
{
ID: 65248,
PCISlot: 6,
},
},
InfoCompute: InfoCompute{
ACL: []interface{}{},
AccountID: 132848,
AccountName: "std_broker",
AffinityLabel: "",
AffinityRules: []ItemRule{},
AffinityWeight: 0,
AntiAffinityRules: []ItemRule{},
Arch: "X86_64",
BootOrder: []string{
"hd", "cdrom",
},
BootDiskSize: 0,
CloneReference: 0,
Clones: []uint64{},
ComputeCIID: 0,
CPUs: 6,
CreatedBy: "timofey_tkachev_1@decs3o",
CreatedTime: 1677579436,
CustomFields: map[string]interface{}{},
DeletedBy: "",
DeletedTime: 0,
Description: "",
Devices: nil,
Driver: "KVM_X86",
GID: 212,
GUID: 48556,
ID: 48556,
ImageID: 9884,
Interfaces: ListInterfaces{},
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: ListSnapshots{},
StatelessSEPID: 0,
StatelessSEPType: "",
Status: "ENABLED",
Tags: map[string]interface{}{},
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("compute_2").FindOne()
if actual.Name != "compute_2" {
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].CPUs != 4{
t.Fatal("expected 4 CPU cores, found: ", actual[0].CPUs)
}
actual = computes.SortByCPU(true)
if actual[0].CPUs != 6 {
t.Fatal("expected 6 CPU cores, found: ", actual[0].CPUs)
}
}

View File

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

View File

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

View File

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

View 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)
}

View 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].CPUs > lc[j].CPUs
}
return lc[i].CPUs < lc[j].CPUs
})
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
}

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
package cloudbroker
import (
"github.com/rudecs/decort-sdk/pkg/cloudbroker/disks"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
)
// Accessing the Disks method group

View File

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

View File

@@ -1,7 +1,7 @@
// API Actor for managing Disk. This actor is a final API for admin to manage Disk
package disks
import "github.com/rudecs/decort-sdk/interfaces"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to disks
type Disks struct {

View File

@@ -0,0 +1,69 @@
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)
}
// FilterByImageID returns ListDisks with specified ImageID.
func (ld ListDisks) FilterByImageID(imageID uint64) ListDisks {
predicate := func(idisk ItemDisk) bool {
return idisk.ImageID == imageID
}
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]
}

View File

@@ -0,0 +1,221 @@
package disks
import "testing"
var disks = ListDisks{
ItemDisk{
MachineID: 0,
MachineName: "",
RecordDisk: RecordDisk{
DeviceName: "vda",
SEPType: "",
InfoDisk: InfoDisk{
AccountID: 132847,
AccountName: "std_2",
ACL: map[string]interface{}{},
BootPartition: 0,
Computes: map[string]string{
"48500": "test",
},
CreatedTime: 1676975177,
DeletedTime: 0,
Description: "",
DestructionTime: 0,
DiskPath: "",
GID: 212,
GUID: 65191,
ID: 65191,
ImageID: 9884,
Images: []uint64{},
IOTune: IOTune{
TotalIOPSSec: 2000,
},
IQN: "",
Login: "",
Milestones: 363501,
Name: "bootdisk",
Order: 0,
Params: "",
ParentID: 0,
Password: "",
PCISlot: 6,
Pool: "vmstor",
PresentTo: []uint64{
27,
},
PurgeAttempts: 0,
PurgeTime: 0,
RealityDeviceNumber: 0,
ReferenceID: "sample",
ResID: "sample",
ResName: "sample",
Role: "",
SEPID: 2504,
Shareable: false,
SizeMax: 2,
SizeUsed: 2,
Snapshots: []ItemSnapshot{},
Status: "ASSIGNED",
TechStatus: "ALLOCATED",
Type: "B",
VMID: 48500,
},
},
},
ItemDisk{
MachineID: 0,
MachineName: "",
RecordDisk: RecordDisk{
DeviceName: "vda",
SEPType: "",
InfoDisk: InfoDisk{
AccountID: 132852,
AccountName: "std",
ACL: map[string]interface{}{},
BootPartition: 0,
Computes: map[string]string{
"48502": "stdvm2",
},
CreatedTime: 1676982606,
DeletedTime: 0,
Description: "",
DestructionTime: 0,
DiskPath: "",
GID: 212,
GUID: 65193,
ID: 65193,
ImageID: 9885,
Images: []uint64{},
IOTune: IOTune{
TotalIOPSSec: 2000,
},
IQN: "",
Login: "",
Milestones: 363516,
Name: "bootdisk",
Order: 0,
Params: "",
ParentID: 0,
Password: "",
PCISlot: 6,
Pool: "vmstor",
PresentTo: []uint64{
27,
27,
},
PurgeAttempts: 0,
PurgeTime: 0,
RealityDeviceNumber: 0,
ReferenceID: "sample",
ResID: "sample",
ResName: "sample",
Role: "",
SEPID: 2504,
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 TestFilterByImageID(t *testing.T) {
actual := disks.FilterByImageID(9885)
if len(actual) == 0 {
t.Fatal("No elements were found")
}
if actual[0].ImageID != 9885 {
t.Fatal("expected 9885 ImageID, found: ", actual[0].ImageID)
}
}
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)
}
}

View 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)
}

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

View File

@@ -1,7 +1,7 @@
package cloudbroker
import (
"github.com/rudecs/decort-sdk/pkg/cloudbroker/extnet"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
)
// Accessing the ExtNet method group

View File

@@ -1,7 +1,7 @@
// API Actor for configure and use external networks
package extnet
import "github.com/rudecs/decort-sdk/interfaces"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to extnet
type ExtNet struct {

View File

@@ -0,0 +1,51 @@
package extnet
// FilterByID returns ListExtNet with specified ID.
func (lenet ListExtNet) FilterByID(id uint64) ListExtNet {
predicate := func(iexnet ItemExtNet) bool {
return iexnet.ID == id
}
return lenet.FilterFunc(predicate)
}
// FilterByName returns ListExtNet with specified Name.
func (lenet ListExtNet) FilterByName(name string) ListExtNet {
predicate := func(iexnet ItemExtNet) bool {
return iexnet.Name == name
}
return lenet.FilterFunc(predicate)
}
// FilterByStatus returns ListExtNet with specified Status.
func (lenet ListExtNet) FilterByStatus(status string) ListExtNet {
predicate := func(iexnet ItemExtNet) bool {
return iexnet.Status == status
}
return lenet.FilterFunc(predicate)
}
// FilterFunc allows filtering ListExtNet based on a user-specified predicate.
func (lenet ListExtNet) FilterFunc(predicate func(ItemExtNet) bool) ListExtNet {
var result ListExtNet
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 ListExtNet) FindOne() ItemExtNet {
if len(lenet) == 0 {
return ItemExtNet{}
}
return lenet[0]
}

View File

@@ -0,0 +1,116 @@
package extnet
import "testing"
var extnets = ListExtNet{
ItemExtNet{
CKey: "",
Meta: []interface{}{},
CheckIPs: []string{},
Default: false,
DefaultQOS: QOS{},
Description: "",
FreeIPs: 0,
GID: 212,
GUID: 3,
ID: 3,
IPCIDR: "176.118.164.0/24",
Milestones: 1355466,
Name: "176.118.164.0/24",
NetworkID: 0,
OVSBridge: "",
PreReservationsNum: 0,
PriVNFDevID: 0,
SharedWith: []interface{}{},
Status: "ENABLED",
VLANID: 0,
VNFs: VNFs{},
},
ItemExtNet{
CKey: "",
Meta: []interface{}{},
CheckIPs: []string{},
Default: false,
DefaultQOS: QOS{},
Description: "",
FreeIPs: 0,
GID: 212,
GUID: 10,
ID: 10,
IPCIDR: "45.134.255.0/24",
Milestones: 2135543,
Name: "45.134.255.0/24",
NetworkID: 0,
OVSBridge: "",
PreReservationsNum: 0,
PriVNFDevID: 0,
SharedWith: []interface{}{},
Status: "ENABLED",
VLANID: 0,
VNFs: VNFs{},
},
ItemExtNet{
CKey: "",
Meta: []interface{}{},
CheckIPs: []string{},
Default: false,
DefaultQOS: QOS{},
Description: "",
FreeIPs: 0,
GID: 212,
GUID: 13,
ID: 13,
IPCIDR: "88.218.249.0/24",
Milestones: 1232134,
Name: "88.218.249.0/24",
NetworkID: 0,
OVSBridge: "",
PreReservationsNum: 0,
PriVNFDevID: 0,
SharedWith: []interface{}{},
Status: "DISABLED",
VLANID: 0,
VNFs: VNFs{},
},
}
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))
}
}

View 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 ListExtNet) 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)
}

View File

@@ -1,6 +1,6 @@
package cloudbroker
import "github.com/rudecs/decort-sdk/pkg/cloudbroker/grid"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/grid"
// Accessing the Grid method group
func (cb *CloudBroker) Grid() *grid.Grid {

View File

@@ -0,0 +1,51 @@
package grid
// FilterByID returns ListGrids with specified ID.
func (lg ListGrids) FilterByID(id uint64) ListGrids {
predicate := func(rg RecordGrid) bool {
return rg.ID == id
}
return lg.FilterFunc(predicate)
}
// FilterByName returns ListGrids with specified Name.
func (lg ListGrids) FilterByName(name string) ListGrids {
predicate := func(rg RecordGrid) bool {
return rg.Name == name
}
return lg.FilterFunc(predicate)
}
// FilterByLocationCode returns ListGrids with specified LocationCode.
func (lg ListGrids) FilterByLocationCode(locationCode string) ListGrids {
predicate := func(rg RecordGrid) bool {
return rg.LocationCode == locationCode
}
return lg.FilterFunc(predicate)
}
// FilterFunc allows filtering ListGrids based on a user-specified predicate.
func (lg ListGrids) FilterFunc(predicate func(RecordGrid) bool) ListGrids {
var result ListGrids
for _, item := range lg {
if predicate(item) {
result = append(result, item)
}
}
return result
}
// FindOne returns first found RecordGrid.
// If none was found, returns an empty struct.
func (lg ListGrids) FindOne() RecordGrid {
if len(lg) == 0 {
return RecordGrid{}
}
return lg[0]
}

View File

@@ -2,7 +2,7 @@
package grid
import (
"github.com/rudecs/decort-sdk/interfaces"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
)
// Structure for creating request to grid

View File

@@ -0,0 +1,43 @@
package grid
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 (lg ListGrids) Serialize(params ...string) (serialization.Serialized, error) {
if len(lg) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(lg, prefix, indent)
}
return json.Marshal(lg)
}
// 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 (rg RecordGrid) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(rg, prefix, indent)
}
return json.Marshal(rg)
}

View File

@@ -1,7 +1,7 @@
package cloudbroker
import (
"github.com/rudecs/decort-sdk/pkg/cloudbroker/image"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/image"
)
// Accessing the Image method group

View File

@@ -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 CD-ROM image

View File

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

View File

@@ -0,0 +1,69 @@
package image
// FilterById returns ListImages with specified ID.
func (li ListImages) FilterById(id uint64) ListImages {
predicate := func(ri RecordImage) bool {
return ri.ID == id
}
return li.FilterFunc(predicate)
}
// FilterByName returns ListImages with specified Name.
func (li ListImages) FilterByName(name string) ListImages {
predicate := func(ri RecordImage) bool {
return ri.Name == name
}
return li.FilterFunc(predicate)
}
// FilterByStatus returns ListImages with specified Status.
func (li ListImages) FilterByStatus(status string) ListImages {
predicate := func(ri RecordImage) bool {
return ri.Status == status
}
return li.FilterFunc(predicate)
}
// FilterByTechStatus returns ListImages with specified TechStatus.
func (li ListImages) FilterByTechStatus(techStatus string) ListImages {
predicate := func(ri RecordImage) bool {
return ri.TechStatus == techStatus
}
return li.FilterFunc(predicate)
}
// FilterByBootType returns ListImages with specified BootType.
func (li ListImages) FilterByBootType(bootType string) ListImages {
predicate := func(ri RecordImage) bool {
return ri.BootType == bootType
}
return li.FilterFunc(predicate)
}
// FilterFunc allows filtering ListImages based on a user-specified predicate.
func (li ListImages) FilterFunc(predicate func(RecordImage) bool) ListImages {
var result ListImages
for _, item := range li {
if predicate(item) {
result = append(result, item)
}
}
return result
}
// FindOne returns first found RecordImage
// If none was found, returns an empty struct.
func (li ListImages) FindOne() RecordImage {
if len(li) == 0 {
return RecordImage{}
}
return li[0]
}

View File

@@ -1,7 +1,7 @@
// Lists all the images. A image is a template which can be used to deploy machines
package image
import "github.com/rudecs/decort-sdk/interfaces"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to image
type Image struct {

View 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 (ri RecordImage) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(ri, prefix, indent)
}
return json.Marshal(ri)
}

View File

@@ -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 sync create image

View File

@@ -1,7 +1,7 @@
package cloudbroker
import (
"github.com/rudecs/decort-sdk/pkg/cloudbroker/k8ci"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/k8ci"
)
// Accessing the K8CI method group

View File

@@ -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 K8CI instance

View File

@@ -0,0 +1,78 @@
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)
}
// FilterByStatus returns ListK8CI with specified Status.
func (lkc ListK8CI) FilterByStatus(status string) ListK8CI {
predicate := func(ikc ItemK8CI) bool {
return ikc.Status == status
}
return lkc.FilterFunc(predicate)
}
// FilterByWorkerImageID returns ListK8CI with specified WorkerImageID.
func (lkc ListK8CI) FilterByWorkerImageID(workerImageID uint64) ListK8CI {
predicate := func(ikc ItemK8CI) bool {
return ikc.WorkerImageID == workerImageID
}
return lkc.FilterFunc(predicate)
}
// FilterByLBImageID returns ListK8CI with specified LBImageID.
func (lkc ListK8CI) FilterByLBImageID(lbImageID uint64) ListK8CI {
predicate := func(ikc ItemK8CI) bool {
return ikc.LBImageID == lbImageID
}
return lkc.FilterFunc(predicate)
}
// FilterByMasterImageID returns ListK8CI with specified MasterImageID.
func (lkc ListK8CI) FilterByMasterImageID(masterImageID uint64) ListK8CI {
predicate := func(ikc ItemK8CI) bool {
return ikc.MasterImageID == masterImageID
}
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]
}

View File

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

View 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)
}

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

View File

@@ -1,7 +1,7 @@
package cloudbroker
import (
"github.com/rudecs/decort-sdk/pkg/cloudbroker/k8s"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
)
// Accessing the K8S method group

View File

@@ -0,0 +1,96 @@
package k8s
// FilterByID returns ListK8S with specified ID.
func (lkc ListK8S) FilterByID(id uint64) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.ID == id
}
return lkc.FilterFunc(predicate)
}
// FilterByName returns ListK8S with specified Name.
func (lkc ListK8S) FilterByName(name string) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.Name == name
}
return lkc.FilterFunc(predicate)
}
// FilterByAccountID returns ListK8S with specified AccountID.
func (lkc ListK8S) FilterByAccountID(accountID uint64) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.AccountID == accountID
}
return lkc.FilterFunc(predicate)
}
// FilterByRGID returns ListK8S with specified RGID.
func (lkc ListK8S) FilterByRGID(rgID uint64) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.RGID == rgID
}
return lkc.FilterFunc(predicate)
}
// FilterByStatus returns ListK8S with specified Status.
func (lkc ListK8S) FilterByStatus(status string) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.Status == status
}
return lkc.FilterFunc(predicate)
}
// FilterByTechStatus returns ListK8S with specified TechStatus.
func (lkc ListK8S) FilterByTechStatus(techStatus string) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.TechStatus == techStatus
}
return lkc.FilterFunc(predicate)
}
// FilterByCreatedBy returns ListK8S created by specified user.
func (lkc ListK8S) FilterByCreatedBy(createdBy string) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.CreatedBy == createdBy
}
return lkc.FilterFunc(predicate)
}
// FilterByDeletedBy returns ListK8S deleted by specified user.
func (lkc ListK8S) FilterByDeletedBy(deletedBy string) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.DeletedBy == deletedBy
}
return lkc.FilterFunc(predicate)
}
// FilterFunc allows filtering ListK8S based on a user-specified predicate.
func (lkc ListK8S) FilterFunc(predicate func(ItemK8S) bool) ListK8S {
var result ListK8S
for _, item := range lkc {
if predicate(item) {
result = append(result, item)
}
}
return result
}
// FindOne returns first found ItemK8S
// If none was found, returns an empty struct.
func (lkc ListK8S) FindOne() ItemK8S {
if len(lkc) == 0 {
return ItemK8S{}
}
return lkc[0]
}

View File

@@ -0,0 +1,197 @@
package k8s
import "testing"
var k8sItems = ListK8S{
ItemK8S{
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",
ServiceAccount: ServiceAccount{},
SSHKey: "sample_key",
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
WorkersGroup: []RecordK8SGroup{},
},
ItemK8S{
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",
ServiceAccount: ServiceAccount{},
SSHKey: "sample_key",
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
WorkersGroup: []RecordK8SGroup{},
},
ItemK8S{
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",
ServiceAccount: ServiceAccount{},
SSHKey: "sample_key",
Status: "DISABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
WorkersGroup: []RecordK8SGroup{},
},
}
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 ItemK8S) 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")
}
}

View File

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

View 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 ListK8S) 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 ItemK8S) 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)
}

View File

@@ -0,0 +1,60 @@
package k8s
import "sort"
// SortByCreatedTime sorts ListK8S by the CreatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lkc ListK8S) SortByCreatedTime(inverse bool) ListK8S {
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 ListK8S by the UpdatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lkc ListK8S) SortByUpdatedTime(inverse bool) ListK8S {
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 ListK8S by the DeletedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lkc ListK8S) SortByDeletedTime(inverse bool) ListK8S {
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
}

View File

@@ -1,6 +1,6 @@
package cloudbroker
import "github.com/rudecs/decort-sdk/pkg/cloudbroker/kvmppc"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/kvmppc"
// Accessing the KVMPPC method group
func (cb *CloudBroker) KVMPPC() *kvmppc.KVMPPC {

View File

@@ -1,7 +1,7 @@
// API to manage KVM PowerPC compute instances (PPC VMs)
package kvmppc
import "github.com/rudecs/decort-sdk/interfaces"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to KVMPPC
type KVMPPC struct {

View File

@@ -1,7 +1,7 @@
package cloudbroker
import (
"github.com/rudecs/decort-sdk/pkg/cloudbroker/kvmx86"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/kvmx86"
)
// Accessing the KVMX86 method group

View File

@@ -1,7 +1,7 @@
// API to manage KVM x86 compute instances (x86 VMs)
package kvmx86
import "github.com/rudecs/decort-sdk/interfaces"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to KVMX86
type KVMX86 struct {

View File

@@ -1,6 +1,6 @@
package cloudbroker
import "github.com/rudecs/decort-sdk/pkg/cloudbroker/lb"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
// Accessing the LB method group
func (cb *CloudBroker) LB() *lb.LB {

View File

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

View File

@@ -0,0 +1,60 @@
package lb
// FilterByID returns ListLB with specified ID.
func (ll ListLB) FilterByID(id uint64) ListLB {
predicate := func(rlb RecordLB) bool {
return rlb.ID == id
}
return ll.FilterFunc(predicate)
}
// FilterByName returns ListLB with specified Name.
func (ll ListLB) FilterByName(name string) ListLB {
predicate := func(rlb RecordLB) bool {
return rlb.Name == name
}
return ll.FilterFunc(predicate)
}
// FilterByExtNetID returns ListLB with specified ExtNetID.
func (ll ListLB) FilterByExtNetID(extNetID uint64) ListLB {
predicate := func(rlb RecordLB) bool {
return rlb.ExtNetID == extNetID
}
return ll.FilterFunc(predicate)
}
// FilterByImageID returns ListLB with specified ImageID.
func (ll ListLB) FilterByImageID(imageID uint64) ListLB {
predicate := func(rlb RecordLB) bool {
return rlb.ImageID == imageID
}
return ll.FilterFunc(predicate)
}
// FilterFunc allows filtering ListLB based on a user-specified predicate.
func (ll ListLB) FilterFunc(predicate func(RecordLB) bool) ListLB {
var result ListLB
for _, item := range ll {
if predicate(item) {
result = append(result, item)
}
}
return result
}
// FindOne returns first found RecordLB
// If none was found, returns an empty struct.
func (ll ListLB) FindOne() RecordLB {
if len(ll) == 0 {
return RecordLB{}
}
return ll[0]
}

View File

@@ -1,7 +1,7 @@
// API to manage load balancer instance
package lb
import "github.com/rudecs/decort-sdk/interfaces"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to load balancer
type LB struct {

View 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 (rlb RecordLB) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(rlb, prefix, indent)
}
return json.Marshal(rlb)
}

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

View File

@@ -1,6 +1,6 @@
package cloudbroker
import "github.com/rudecs/decort-sdk/pkg/cloudbroker/rg"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
// Accessing the RG method group
func (cb *CloudBroker) RG() *rg.RG {

View File

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

View File

@@ -0,0 +1,87 @@
package rg
// FilterByID returns ListRG with specified ID.
func (lrg ListRG) FilterByID(id uint64) ListRG {
predicate := func(irg ItemRG) bool {
return irg.ID == id
}
return lrg.FilterFunc(predicate)
}
// FilterByName returns ListRG with specified Name.
func (lrg ListRG) FilterByName(name string) ListRG {
predicate := func(irg ItemRG) bool {
return irg.Name == name
}
return lrg.FilterFunc(predicate)
}
// FilterByCreatedBy return ListRG created by specified user.
func (lrg ListRG) FilterByCreatedBy(createdBy string) ListRG {
predicate := func(irg ItemRG) bool {
return irg.CreatedBy == createdBy
}
return lrg.FilterFunc(predicate)
}
// FilterByStatus returns ListRG with specified Status.
func (lrg ListRG) FilterByStatus(status string) ListRG {
predicate := func(irg ItemRG) bool {
return irg.Status == status
}
return lrg.FilterFunc(predicate)
}
// FilterByLockStatus return ListRG with specified LockStatus.
func (lrg ListRG) FilterByLockStatus(lockStatus string) ListRG {
predicate := func(irg ItemRG) bool {
return irg.LockStatus == lockStatus
}
return lrg.FilterFunc(predicate)
}
// FilterByDefNetType returns ListRG with specified DefNetType.
func (lrg ListRG) FilterByDefNetType(defNetType string) ListRG {
predicate := func(irg ItemRG) bool {
return irg.DefNetType == defNetType
}
return lrg.FilterFunc(predicate)
}
// FilterByDefNetID returns ListRG with specified DefNetID.
func (lrg ListRG) FilterByDefNetID(defNetID int64) ListRG {
predicate := func(irg ItemRG) bool {
return irg.DefNetID == defNetID
}
return lrg.FilterFunc(predicate)
}
// FilterFunc allows filtering ListRG based on a user-specified predicate.
func (lrg ListRG) FilterFunc(predicate func(ItemRG) bool) ListRG {
var result ListRG
for _, item := range lrg {
if predicate(item) {
result = append(result, item)
}
}
return result
}
// FindOne returns first found ItemRG.
// If none was found, returns an empty struct.
func (lrg ListRG) FindOne() ItemRG {
if len(lrg) == 0 {
return ItemRG{}
}
return lrg[0]
}

View File

@@ -138,7 +138,7 @@ type ItemRG struct {
CreatedTime uint64 `json:"createdTime"`
// DefNet ID
DefNetID uint64 `json:"def_net_id"`
DefNetID int64 `json:"def_net_id"`
// DefNet type
DefNetType string `json:"def_net_type"`

View File

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

View 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 ListRG) 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 ItemRG) 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)
}

View File

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

View File

@@ -0,0 +1,60 @@
package rg
import "sort"
// SortByCreatedTime sorts ListRG by the CreatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lrg ListRG) SortByCreatedTime(inverse bool) ListRG {
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 ListRG by the UpdatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lrg ListRG) SortByUpdatedTime(inverse bool) ListRG {
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 ListRG by the DeletedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lrg ListRG) SortByDeletedTime(inverse bool) ListRG {
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
}

View File

@@ -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 resource types in account

View File

@@ -1,6 +1,6 @@
package cloudbroker
import "github.com/rudecs/decort-sdk/pkg/cloudbroker/sep"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/sep"
// Accessing the SEP method group
func (cb *CloudBroker) SEP() *sep.SEP {

View File

@@ -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 edit config fields

View File

@@ -0,0 +1,69 @@
package sep
// FilterByID returns ListSEP with specified ID.
func (lsep ListSEP) FilterByID(id uint64) ListSEP {
predicate := func(rsep RecordSEP) bool {
return rsep.ID == id
}
return lsep.FilterFunc(predicate)
}
// FilterByName returns ListSEP with specified Name.
func (lsep ListSEP) FilterByName(name string) ListSEP {
predicate := func(rsep RecordSEP) bool {
return rsep.Name == name
}
return lsep.FilterFunc(predicate)
}
// FilterByObjStatus returns ListSEP with specified ObjStatus.
func (lsep ListSEP) FilterByObjStatus(objStatus string) ListSEP {
predicate := func(rsep RecordSEP) bool {
return rsep.ObjStatus == objStatus
}
return lsep.FilterFunc(predicate)
}
// FilterByTechStatus returns ListSEP with specified TechStatus.
func (lsep ListSEP) FilterByTechStatus(techStatus string) ListSEP {
predicate := func(rsep RecordSEP) bool {
return rsep.TechStatus == techStatus
}
return lsep.FilterFunc(predicate)
}
// FilterByType returns ListSEP with specified Type.
func (lsep ListSEP) FilterByType(sepType string) ListSEP {
predicate := func(rsep RecordSEP) bool {
return rsep.Type == sepType
}
return lsep.FilterFunc(predicate)
}
// FilterFunc allows filtering ListSEP based on user-specified predicate.
func (lsep ListSEP) FilterFunc(predicate func(RecordSEP) bool) ListSEP {
var result ListSEP
for _, item := range lsep {
if predicate(item) {
result = append(result, item)
}
}
return result
}
// FindOne returns first found RecordSEP
// If none was found, returns an empty struct.
func (lsep ListSEP) FindOne() RecordSEP {
if len(lsep) == 0 {
return RecordSEP{}
}
return lsep[0]
}

View File

@@ -2,7 +2,7 @@
package sep
import (
"github.com/rudecs/decort-sdk/interfaces"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
)
// Structure for creating request to storage endpoint provider

View File

@@ -0,0 +1,43 @@
package sep
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 (lsep ListSEP) Serialize(params ...string) (serialization.Serialized, error) {
if len(lsep) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(lsep, prefix, indent)
}
return json.Marshal(lsep)
}
// 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 (rsep RecordSEP) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(rsep, prefix, indent)
}
return json.Marshal(rsep)
}

View File

@@ -1,7 +1,7 @@
package cloudbroker
import (
"github.com/rudecs/decort-sdk/pkg/cloudbroker/tasks"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/tasks"
)
// Accessing the tasks method group

View File

@@ -1,7 +1,7 @@
// User API tasks interface
package tasks
import "github.com/rudecs/decort-sdk/interfaces"
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to tasks
type Tasks struct {

View File

@@ -1,7 +1,7 @@
package cloudbroker
import (
"github.com/rudecs/decort-sdk/pkg/cloudbroker/vins"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
)
// Accessing the VINS method group

View 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]
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
"strings"
"github.com/rudecs/decort-sdk/internal/validators"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for IP reserve

View 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)
}

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

View File

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