v1.5.0-gamma
This commit is contained in:
@@ -31,21 +31,23 @@ func (lenet ListExtNets) FilterByStatus(status string) ListExtNets {
|
||||
func (lenet ListExtNets) FilterFunc(predicate func(ItemExtNet) bool) ListExtNets {
|
||||
var result ListExtNets
|
||||
|
||||
for _, item := range lenet {
|
||||
for _, item := range lenet.Data {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemExtNet
|
||||
// If none was found, returns an empty struct.
|
||||
func (lenet ListExtNets) FindOne() ItemExtNet {
|
||||
if len(lenet) == 0 {
|
||||
if lenet.EntryCount == 0 {
|
||||
return ItemExtNet{}
|
||||
}
|
||||
|
||||
return lenet[0]
|
||||
return lenet.Data[0]
|
||||
}
|
||||
|
||||
@@ -3,23 +3,25 @@ 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",
|
||||
Data: []ItemExtNet{
|
||||
{
|
||||
ID: 3,
|
||||
IPCIDR: "176.118.164.0/24",
|
||||
Name: "176.118.164.0/24",
|
||||
Status: "ENABLED",
|
||||
},
|
||||
{
|
||||
ID: 10,
|
||||
IPCIDR: "45.134.255.0/24",
|
||||
Name: "45.134.255.0/24",
|
||||
Status: "ENABLED",
|
||||
},
|
||||
{
|
||||
ID: 13,
|
||||
IPCIDR: "88.218.249.0/24",
|
||||
Name: "88.218.249.0/24",
|
||||
Status: "DISABLED",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -43,11 +45,11 @@ func TestFilterByName(t *testing.T) {
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := extnets.FilterByStatus("ENABLED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
||||
}
|
||||
@@ -59,7 +61,7 @@ func TestFilterFunc(t *testing.T) {
|
||||
return ien.IPCIDR == ien.Name
|
||||
})
|
||||
|
||||
if len(actual) != 3 {
|
||||
t.Fatal("expected 3 elements, found: ", len(actual))
|
||||
if len(actual.Data) != 3 {
|
||||
t.Fatal("expected 3 elements, found: ", len(actual.Data))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,34 @@ import (
|
||||
|
||||
// Request struct for get list external network
|
||||
type ListRequest struct {
|
||||
// Filter by account ID
|
||||
// Find by account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by network ip address
|
||||
// Required: false
|
||||
Network string `url:"network,omitempty" json:"network,omitempty"`
|
||||
|
||||
// Find by vlan ID
|
||||
// Required: false
|
||||
VLANID uint64 `url:"vlanId,omitempty" json:"vlanId,omitempty"`
|
||||
|
||||
// Find by vnfDevices ID
|
||||
// Required: false
|
||||
VNFDevID uint64 `url:"vnfDevId,omitempty" json:"vnfDevId,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -22,7 +46,7 @@ type ListRequest struct {
|
||||
}
|
||||
|
||||
// List gets list all available external networks
|
||||
func (e ExtNet) List(ctx context.Context, req ListRequest) (ListExtNets, error) {
|
||||
func (e ExtNet) List(ctx context.Context, req ListRequest) (*ListExtNets, error) {
|
||||
url := "/cloudapi/extnet/list"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -37,5 +61,5 @@ func (e ExtNet) List(ctx context.Context, req ListRequest) (ListExtNets, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -25,7 +25,11 @@ type ItemExtNetExtend struct {
|
||||
}
|
||||
|
||||
// List of information about external network
|
||||
type ListExtNets []ItemExtNet
|
||||
type ListExtNets struct {
|
||||
Data []ItemExtNet `json:"data"`
|
||||
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// List of extend information about external network
|
||||
type ListExtNetExtends []ItemExtNetExtend
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lenet ListExtNets) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lenet) == 0 {
|
||||
if lenet.EntryCount == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user