v9.0.0
This commit is contained in:
44
pkg/cloudbroker/extnet/access_add.go
Normal file
44
pkg/cloudbroker/extnet/access_add.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// AccessAddRequest struct to grant access
|
||||
type AccessAddRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Account ID
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// AccessAdd grants access to external network for account ID
|
||||
func (e ExtNet) AccessAdd(ctx context.Context, req AccessAddRequest) ([]uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/accessAdd"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]uint64, 0)
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
44
pkg/cloudbroker/extnet/access_remove.go
Normal file
44
pkg/cloudbroker/extnet/access_remove.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// AccessRemoveRequest struct to remove access
|
||||
type AccessRemoveRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Account ID
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// AccessRemove removes access from external network for account ID
|
||||
func (e ExtNet) AccessRemove(ctx context.Context, req AccessRemoveRequest) ([]uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/accessRemove"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]uint64, 0)
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
138
pkg/cloudbroker/extnet/create.go
Normal file
138
pkg/cloudbroker/extnet/create.go
Normal file
@@ -0,0 +1,138 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
type Route struct {
|
||||
// Destination network
|
||||
Destination string `url:"destination" json:"destination" validate:"required"`
|
||||
|
||||
//Destination network mask in 255.255.255.255 format
|
||||
Netmask string `url:"netmask" json:"netmask" validate:"required"`
|
||||
|
||||
//Next hop host, IP address from ViNS ID free IP pool
|
||||
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||
}
|
||||
|
||||
// CreateRequest struct to create external network
|
||||
type CreateRequest struct {
|
||||
// External network name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid" json:"gid" validate:"required"`
|
||||
|
||||
// IP network CIDR
|
||||
// For example 192.168.0.0/24
|
||||
// Required: true
|
||||
IPCIDR string `url:"ipcidr" json:"ipcidr" validate:"required"`
|
||||
|
||||
// VLAN ID
|
||||
// Required: true
|
||||
VLANID uint64 `url:"vlanId" json:"vlanId" validate:"required"`
|
||||
|
||||
// External network gateway IP address
|
||||
// Required: false
|
||||
Gateway string `url:"gateway,omitempty" json:"gateway,omitempty"`
|
||||
|
||||
// List of DNS addresses
|
||||
// Required: false
|
||||
DNS []string `url:"dns,omitempty" json:"dns,omitempty"`
|
||||
|
||||
// List of NTP addresses
|
||||
// Required: false
|
||||
NTP []string `url:"ntp,omitempty" json:"ntp,omitempty"`
|
||||
|
||||
// IPs to check network availability
|
||||
// Required: false
|
||||
CheckIPs []string `url:"checkIps,omitempty" json:"checkIps,omitempty"`
|
||||
|
||||
// If true - platform DHCP server will not be created
|
||||
// Required: false
|
||||
Virtual bool `url:"virtual,omitempty" json:"virtual,omitempty"`
|
||||
|
||||
// Optional description
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
|
||||
// Start of IP range to be explicitly included
|
||||
// Required: false
|
||||
StartIP string `url:"startIP,omitempty" json:"startIP,omitempty"`
|
||||
|
||||
// End of IP range to be explicitly included
|
||||
// Required: false
|
||||
EndIP string `url:"endIP,omitempty" json:"endIP,omitempty"`
|
||||
|
||||
// IP to create VNFDev with
|
||||
// Required: false
|
||||
VNFDevIP string `url:"vnfdevIP,omitempty" json:"vnfdevIP,omitempty"`
|
||||
|
||||
// Number of pre created reservations
|
||||
// Required: false
|
||||
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
||||
|
||||
// OpenvSwith bridge name for ExtNet connection
|
||||
// Required: false
|
||||
OVSBridge string `url:"ovsBridge,omitempty" json:"ovsBridge,omitempty"`
|
||||
|
||||
// List of static routes, each item must have destination, netmask, and gateway fields
|
||||
// Required: false
|
||||
Routes []Route `url:"-" json:"routes,omitempty" validate:"omitempty,dive"`
|
||||
}
|
||||
|
||||
type wrapperCreateRequest struct {
|
||||
CreateRequest
|
||||
Routes []string `url:"routes,omitempty"`
|
||||
}
|
||||
|
||||
// Create creates new external network into platform
|
||||
func (e ExtNet) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
var routes []string
|
||||
|
||||
if len(req.Routes) != 0 {
|
||||
routes = make([]string, 0, len(req.Routes))
|
||||
|
||||
for r := range req.Routes {
|
||||
b, err := json.Marshal(req.Routes[r])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
routes = append(routes, string(b))
|
||||
}
|
||||
} else {
|
||||
routes = []string{}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateRequest{
|
||||
CreateRequest: req,
|
||||
Routes: routes,
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/create"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
50
pkg/cloudbroker/extnet/default_qos_update.go
Normal file
50
pkg/cloudbroker/extnet/default_qos_update.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DefaultQOSUpdateRequest struct for update QOS
|
||||
type DefaultQOSUpdateRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Internal traffic, kbit
|
||||
// Required: false
|
||||
IngressRate uint64 `url:"ingress_rate,omitempty" json:"ingress_rate,omitempty"`
|
||||
|
||||
// Internal traffic burst, kbit
|
||||
// Required: false
|
||||
IngressBurst uint64 `url:"ingress_burst,omitempty" json:"ingress_burst,omitempty"`
|
||||
|
||||
// External traffic rate, kbit
|
||||
// Required: false
|
||||
EgressRate uint64 `url:"egress_rate,omitempty" json:"egress_rate,omitempty"`
|
||||
}
|
||||
|
||||
// DefaultQOSUpdate updates default qos values
|
||||
func (e ExtNet) DefaultQOSUpdate(ctx context.Context, req DefaultQOSUpdateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/defaultQosUpdate"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudbroker/extnet/destroy.go
Normal file
38
pkg/cloudbroker/extnet/destroy.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DestroyRequest struct for destroy
|
||||
type DestroyRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Destroy destroys external network
|
||||
func (e ExtNet) Destroy(ctx context.Context, req DestroyRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/destroy"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudbroker/extnet/device_deploy.go
Normal file
38
pkg/cloudbroker/extnet/device_deploy.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DeviceDeployRequest struct to deploy network device
|
||||
type DeviceDeployRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// DeviceDeploy deploys network device for external network (make not virtual, "physical")
|
||||
func (e ExtNet) DeviceDeploy(ctx context.Context, req DeviceDeployRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/deviceDeploy"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudbroker/extnet/device_migrate.go
Normal file
42
pkg/cloudbroker/extnet/device_migrate.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DeviceMigrateRequest struct for migrate VNF
|
||||
type DeviceMigrateRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Target stack ID to migrate to
|
||||
// Required: false
|
||||
StackID uint64 `url:"stackId,omitempty" json:"stackId,omitempty"`
|
||||
}
|
||||
|
||||
// DeviceMigrate migrates external network VNF device
|
||||
func (e ExtNet) DeviceMigrate(ctx context.Context, req DeviceMigrateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/deviceMigrate"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudbroker/extnet/device_remove.go
Normal file
38
pkg/cloudbroker/extnet/device_remove.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DeviceRemoveRequest struct to remove network device
|
||||
type DeviceRemoveRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// DeviceRemove removes network device of external network (make it virtual, not "physical")
|
||||
func (e ExtNet) DeviceRemove(ctx context.Context, req DeviceRemoveRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/deviceRemove"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudbroker/extnet/device_restart.go
Normal file
38
pkg/cloudbroker/extnet/device_restart.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DeviceRestartRequest struct for restart VNF device
|
||||
type DeviceRestartRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// DeviceRestart restarts external network VNF device
|
||||
func (e ExtNet) DeviceRestart(ctx context.Context, req DeviceRestartRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/deviceRestart"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudbroker/extnet/disable.go
Normal file
38
pkg/cloudbroker/extnet/disable.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DisableRequest struct to disable external network
|
||||
type DisableRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Disable disables external network
|
||||
func (e ExtNet) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/disable"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudbroker/extnet/dns_apply.go
Normal file
42
pkg/cloudbroker/extnet/dns_apply.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DNSApplyRequest struct to set new DNS
|
||||
type DNSApplyRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// List of DNS to apply
|
||||
// Required: false
|
||||
DNSList []string `url:"dns_list,omitempty" json:"dns_list,omitempty"`
|
||||
}
|
||||
|
||||
// DNSApply sets new DNS
|
||||
func (e ExtNet) DNSApply(ctx context.Context, req DNSApplyRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/dnsApply"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudbroker/extnet/enable.go
Normal file
38
pkg/cloudbroker/extnet/enable.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// EnableRequest struct to enable external network
|
||||
type EnableRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Enable enables external networks
|
||||
func (e ExtNet) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/enable"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
16
pkg/cloudbroker/extnet/extnet.go
Normal file
16
pkg/cloudbroker/extnet/extnet.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// API Actor for configure and use external networks
|
||||
package extnet
|
||||
|
||||
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
|
||||
|
||||
// Structure for creating request to extnet
|
||||
type ExtNet struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for extnet endpoints
|
||||
func New(client interfaces.Caller) *ExtNet {
|
||||
return &ExtNet{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
53
pkg/cloudbroker/extnet/filter.go
Normal file
53
pkg/cloudbroker/extnet/filter.go
Normal file
@@ -0,0 +1,53 @@
|
||||
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.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(lenet.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemExtNet
|
||||
// If none was found, returns an empty struct.
|
||||
func (lenet ListExtNet) FindOne() ItemExtNet {
|
||||
if len(lenet.Data) == 0 {
|
||||
return ItemExtNet{}
|
||||
}
|
||||
|
||||
return lenet.Data[0]
|
||||
}
|
||||
118
pkg/cloudbroker/extnet/filter_test.go
Normal file
118
pkg/cloudbroker/extnet/filter_test.go
Normal file
@@ -0,0 +1,118 @@
|
||||
package extnet
|
||||
|
||||
import "testing"
|
||||
|
||||
var extnets = ListExtNet{
|
||||
Data: []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{},
|
||||
},
|
||||
{
|
||||
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{},
|
||||
},
|
||||
{
|
||||
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.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
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.Data) != 3 {
|
||||
t.Fatal("expected 3 elements, found: ", len(actual.Data))
|
||||
}
|
||||
}
|
||||
46
pkg/cloudbroker/extnet/get.go
Normal file
46
pkg/cloudbroker/extnet/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get information about external network
|
||||
type GetRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets external network details as a RecordExtNet struct
|
||||
func (e ExtNet) Get(ctx context.Context, req GetRequest) (*RecordExtNet, error) {
|
||||
res, err := e.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordExtNet{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets external network details as an array of bytes
|
||||
func (e ExtNet) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/get"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
24
pkg/cloudbroker/extnet/get_default.go
Normal file
24
pkg/cloudbroker/extnet/get_default.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// GetDefault get default external network ID
|
||||
func (e ExtNet) GetDefault(ctx context.Context) (uint64, error) {
|
||||
url := "/cloudbroker/extnet/getDefault"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
19
pkg/cloudbroker/extnet/ids.go
Normal file
19
pkg/cloudbroker/extnet/ids.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package extnet
|
||||
|
||||
// IDs gets array of ExtNetIDs from ListExtNet struct
|
||||
func (le ListExtNet) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(le.Data))
|
||||
for _, e := range le.Data {
|
||||
res = append(res, e.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of StaticRouteIDs from ListStaticRoutes struct
|
||||
func (lsr ListStaticRoutes) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lsr.Data))
|
||||
for _, sr := range lsr.Data {
|
||||
res = append(res, sr.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
42
pkg/cloudbroker/extnet/ips_exclude.go
Normal file
42
pkg/cloudbroker/extnet/ips_exclude.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// IPsExcludeRequest struct to exclude list of IPs
|
||||
type IPsExcludeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// List of IPs for exclude from external network
|
||||
// Required: true
|
||||
IPs []string `url:"ips" json:"ips" validate:"min=1"`
|
||||
}
|
||||
|
||||
// IPsExclude excludes list of IPs from external network pool
|
||||
func (e ExtNet) IPsExclude(ctx context.Context, req IPsExcludeRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/ipsExclude"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
46
pkg/cloudbroker/extnet/ips_exclude_range.go
Normal file
46
pkg/cloudbroker/extnet/ips_exclude_range.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// IPsExcludeRangeRequest struct to exclude range of IPs
|
||||
type IPsExcludeRangeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Starting IP
|
||||
// Required: true
|
||||
IPStart string `url:"ip_start" json:"ip_start" validate:"required"`
|
||||
|
||||
// Ending IP
|
||||
// Required: true
|
||||
IPEnd string `url:"ip_end" json:"ip_end" validate:"required"`
|
||||
}
|
||||
|
||||
// IPsExcludeRange excludes range of IPs from external network pool
|
||||
func (e ExtNet) IPsExcludeRange(ctx context.Context, req IPsExcludeRangeRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/ipsExcludeRange"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudbroker/extnet/ips_include.go
Normal file
42
pkg/cloudbroker/extnet/ips_include.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// IPsIncludeRequest struct to include list of IPs
|
||||
type IPsIncludeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// List of IPs for include to external network
|
||||
// Required: true
|
||||
IPs []string `url:"ips" json:"ips" validate:"min=1"`
|
||||
}
|
||||
|
||||
// IPsInclude includes list of IPs to external network pool
|
||||
func (e ExtNet) IPsInclude(ctx context.Context, req IPsIncludeRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/ipsInclude"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
46
pkg/cloudbroker/extnet/ips_include_range.go
Normal file
46
pkg/cloudbroker/extnet/ips_include_range.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// IPsIncludeRangeRequest struct to include range of IPs
|
||||
type IPsIncludeRangeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Starting IP
|
||||
// Required: true
|
||||
IPStart string `url:"ip_start" json:"ip_start" validate:"required"`
|
||||
|
||||
// Ending IP
|
||||
// Required: true
|
||||
IPEnd string `url:"ip_end" json:"ip_end" validate:"required"`
|
||||
}
|
||||
|
||||
// IPsIncludeRange includes range of IPs to external network pool
|
||||
func (e ExtNet) IPsIncludeRange(ctx context.Context, req IPsIncludeRangeRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/ipsIncludeRange"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
83
pkg/cloudbroker/extnet/list.go
Normal file
83
pkg/cloudbroker/extnet/list.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of external network
|
||||
type ListRequest struct {
|
||||
// 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"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of all available external networks as a ListExtNet struct
|
||||
func (e ExtNet) List(ctx context.Context, req ListRequest) (*ListExtNet, error) {
|
||||
|
||||
res, err := e.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListExtNet{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of all available external networks as an array of bytes
|
||||
func (e ExtNet) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/list"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
240
pkg/cloudbroker/extnet/models.go
Normal file
240
pkg/cloudbroker/extnet/models.go
Normal file
@@ -0,0 +1,240 @@
|
||||
package extnet
|
||||
|
||||
// QOS
|
||||
type QOS struct {
|
||||
// ERate
|
||||
ERate uint64 `json:"eRate"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// InBurst
|
||||
InBurst uint64 `json:"inBurst"`
|
||||
|
||||
// InRate
|
||||
InRate uint64 `json:"inRate"`
|
||||
}
|
||||
|
||||
// Main information about reservations
|
||||
type ItemReservation struct {
|
||||
// Client type
|
||||
ClientType string `json:"clientType"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// IP
|
||||
IP string `json:"ip"`
|
||||
|
||||
// MAC
|
||||
MAC string `json:"mac"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// Virtual machine ID
|
||||
VMID uint64 `json:"vmId"`
|
||||
|
||||
// Domain name
|
||||
DomainName string `json:"domainname"`
|
||||
|
||||
// Hostname
|
||||
Hostname string `json:"hostname"`
|
||||
}
|
||||
|
||||
// List reservations
|
||||
type ListReservations []ItemReservation
|
||||
|
||||
// VNFs
|
||||
type VNFs struct {
|
||||
DHCP int `json:"dhcp"`
|
||||
}
|
||||
|
||||
// Main information about external network
|
||||
type ItemExtNet struct {
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Meta
|
||||
Meta []interface{} `json:"_meta"`
|
||||
|
||||
// CheckIPs
|
||||
CheckIPs []string `json:"checkIps"`
|
||||
|
||||
// Default
|
||||
Default bool `json:"default"`
|
||||
|
||||
// Default QOS
|
||||
DefaultQOS QOS `json:"defaultQos"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Free IPs number
|
||||
FreeIPs int64 `json:"freeIps"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// IPCIDR
|
||||
IPCIDR string `json:"ipcidr"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Network ID
|
||||
NetworkID uint64 `json:"networkId"`
|
||||
|
||||
// OVSBridge
|
||||
OVSBridge string `json:"ovsBridge"`
|
||||
|
||||
// PreReservationsNum
|
||||
PreReservationsNum uint64 `json:"preReservationsNum"`
|
||||
|
||||
// PriVNFDevID
|
||||
PriVNFDevID uint64 `json:"priVnfDevId"`
|
||||
|
||||
// List of shared with
|
||||
SharedWith []interface{} `json:"sharedWith"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// VLAN ID
|
||||
VLANID uint64 `json:"vlanId"`
|
||||
|
||||
// VNFs
|
||||
VNFs VNFs `json:"vnfs"`
|
||||
}
|
||||
|
||||
// List external networks
|
||||
type ListExtNet struct {
|
||||
// Data
|
||||
Data []ItemExtNet `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Detailed information about external network
|
||||
type RecordExtNet struct {
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Meta
|
||||
Meta []interface{} `json:"_meta"`
|
||||
|
||||
// CheckIPs
|
||||
CheckIPs []string `json:"checkIps"`
|
||||
|
||||
// Default
|
||||
Default bool `json:"default"`
|
||||
|
||||
// Default QOS
|
||||
DefaultQOS QOS `json:"defaultQos"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// List DNS
|
||||
DNS []string `json:"dns"`
|
||||
|
||||
// List excludes
|
||||
Excluded ListReservations `json:"excluded"`
|
||||
|
||||
// Free IPs number
|
||||
FreeIPs int64 `json:"free_ips"`
|
||||
|
||||
// Gateway
|
||||
Gateway string `json:"gateway"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// IPCIDR
|
||||
IPCIDR string `json:"ipcidr"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Network
|
||||
Network string `json:"network"`
|
||||
|
||||
// Network ID
|
||||
NetworkID uint64 `json:"networkId"`
|
||||
|
||||
// OVSBridge
|
||||
OVSBridge string `json:"ovsBridge"`
|
||||
|
||||
// PreReservationsNum
|
||||
PreReservationsNum uint64 `json:"preReservationsNum"`
|
||||
|
||||
// Prefix
|
||||
Prefix uint64 `json:"prefix"`
|
||||
|
||||
// PriVNFDevID
|
||||
PriVNFDevID uint64 `json:"priVnfDevId"`
|
||||
|
||||
// List reservations
|
||||
Reservations ListReservations `json:"reservations"`
|
||||
|
||||
// List of shared with
|
||||
SharedWith []interface{} `json:"sharedWith"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// VLAN ID
|
||||
VLANID uint64 `json:"vlanId"`
|
||||
|
||||
// VNFs
|
||||
VNFs VNFs `json:"vnfs"`
|
||||
}
|
||||
|
||||
// List of static routes
|
||||
type ListStaticRoutes struct {
|
||||
// Data
|
||||
Data []ItemRoutes `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Detailed information about Routes
|
||||
type ItemRoutes struct {
|
||||
//Compute Id
|
||||
ComputeIds []uint64 `json:"computeIds"`
|
||||
|
||||
// Destination network
|
||||
Destination string `json:"destination"`
|
||||
|
||||
//Next hop host, IP address from ViNS ID free IP pool
|
||||
Gateway string `json:"gateway"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
//Destination network mask in 255.255.255.255 format
|
||||
Netmask string `json:"netmask"`
|
||||
}
|
||||
42
pkg/cloudbroker/extnet/ntp_apply.go
Normal file
42
pkg/cloudbroker/extnet/ntp_apply.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// NTPApplyRequest struct for set new NTP
|
||||
type NTPApplyRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// List of NTP to apply
|
||||
// Required: false
|
||||
NTPList []string `url:"ntp_list,omitempty" json:"ntp_list,omitempty"`
|
||||
}
|
||||
|
||||
// NTPApply sets new NTP
|
||||
func (e ExtNet) NTPApply(ctx context.Context, req NTPApplyRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/ntpApply"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
24
pkg/cloudbroker/extnet/raise_down.go
Normal file
24
pkg/cloudbroker/extnet/raise_down.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// RaiseDown starting all extnets vnfdevs in "DOWN" tech status
|
||||
func (e ExtNet) RaiseDown(ctx context.Context) (bool, error) {
|
||||
url := "/cloudbroker/extnet/raiseDown"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
43
pkg/cloudbroker/extnet/serialize.go
Normal file
43
pkg/cloudbroker/extnet/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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.Data) == 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)
|
||||
}
|
||||
38
pkg/cloudbroker/extnet/set_default.go
Normal file
38
pkg/cloudbroker/extnet/set_default.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// SetDefaultRequest struct to set external network as default
|
||||
type SetDefaultRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// SetDefault sets external network as default for platform
|
||||
func (e ExtNet) SetDefault(ctx context.Context, req SetDefaultRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/setDefault"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
46
pkg/cloudbroker/extnet/static_route_access_grant.go
Normal file
46
pkg/cloudbroker/extnet/static_route_access_grant.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// StaticRouteAccessGrantRequest struct to grant access to static route to Compute/ViNS
|
||||
type StaticRouteAccessGrantRequest struct {
|
||||
// ExtNet ID to grant access
|
||||
// Required: true
|
||||
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||
|
||||
// Route ID to grant access, can be found in staticRouteList
|
||||
// Required: true
|
||||
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||
|
||||
// List of Compute IDs to grant access to this route
|
||||
// Required: false
|
||||
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||
}
|
||||
|
||||
// StaticRouteAccessGrant grants access to static route to Compute/ViNS
|
||||
func (v ExtNet) StaticRouteAccessGrant(ctx context.Context, req StaticRouteAccessGrantRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/staticRouteAccessGrant"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
46
pkg/cloudbroker/extnet/static_route_access_revoke.go
Normal file
46
pkg/cloudbroker/extnet/static_route_access_revoke.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// StaticRouteAccessRevokeRequest struct to revoke access to static route to Compute/ViNS
|
||||
type StaticRouteAccessRevokeRequest struct {
|
||||
// ExtNet ID to revoke access
|
||||
// Required: true
|
||||
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||
|
||||
// Route ID to revoke access, can be found in staticRouteList
|
||||
// Required: true
|
||||
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||
|
||||
// List of Compute IDs to revoke access to this route
|
||||
// Required: false
|
||||
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||
}
|
||||
|
||||
// StaticRouteAccessRevoke revokes access to static route to Compute/ViNS
|
||||
func (v ExtNet) StaticRouteAccessRevoke(ctx context.Context, req StaticRouteAccessRevokeRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/staticRouteAccessRevoke"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
54
pkg/cloudbroker/extnet/static_route_add.go
Normal file
54
pkg/cloudbroker/extnet/static_route_add.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// StaticRouteAddRequest struct to add static route
|
||||
type StaticRouteAddRequest struct {
|
||||
// ExtNet ID to add static route
|
||||
// Required: true
|
||||
ExtNetId uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||
|
||||
// Destination network
|
||||
// Required: true
|
||||
Destination string `url:"destination" json:"destination" validate:"required"`
|
||||
|
||||
// Destination network mask in 255.255.255.255 format
|
||||
// Required: true
|
||||
Netmask string `url:"netmask" json:"netmask" validate:"required"`
|
||||
|
||||
// Next hop host, IP address from ViNS ID free IP pool
|
||||
// Required: true
|
||||
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||
|
||||
// List of Compute IDs which have access to this route
|
||||
// Required: false
|
||||
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||
}
|
||||
|
||||
// StaticRouteAdd adds new static route to ViNS
|
||||
func (v ExtNet) StaticRouteAdd(ctx context.Context, req StaticRouteAddRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/staticRouteAdd"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudbroker/extnet/static_route_del.go
Normal file
42
pkg/cloudbroker/extnet/static_route_del.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// StaticRouteDelRequest struct to remove static route from ViNS
|
||||
type StaticRouteDelRequest struct {
|
||||
// ExtNet ID to remove static route from
|
||||
// Required: true
|
||||
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||
|
||||
// Route ID to remove, can be found in staticRouteList
|
||||
// Required: true
|
||||
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||
}
|
||||
|
||||
// StaticRouteDel removes static route from ViNS
|
||||
func (v ExtNet) StaticRouteDel(ctx context.Context, req StaticRouteDelRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/staticRouteDel"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
40
pkg/cloudbroker/extnet/static_route_list.go
Normal file
40
pkg/cloudbroker/extnet/static_route_list.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// StaticRouteListRequest struct for static route list
|
||||
type StaticRouteListRequest struct {
|
||||
// ExtNet ID to show list of static routes
|
||||
// Required: true
|
||||
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||
}
|
||||
|
||||
// StaticRouteList shows list of static routes for ViNS
|
||||
func (v ExtNet) StaticRouteList(ctx context.Context, req StaticRouteListRequest) (*ListStaticRoutes, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/staticRouteList"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListStaticRoutes{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
46
pkg/cloudbroker/extnet/update.go
Normal file
46
pkg/cloudbroker/extnet/update.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// UpdateRequest struct to update external network
|
||||
type UpdateRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// New external network name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// New external network description
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
}
|
||||
|
||||
// Update updates external network parameters
|
||||
func (e ExtNet) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/update"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user