v1.0.0
This commit is contained in:
54
pkg/cloudbroker/extnet/access_add.go
Normal file
54
pkg/cloudbroker/extnet/access_add.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for grant access
|
||||
type AccessAddRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
|
||||
// Account ID
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (erq AccessAddRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if erq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessAdd grant access to external network for account ID
|
||||
func (e ExtNet) AccessAdd(ctx context.Context, req AccessAddRequest) ([]uint64, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, 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
|
||||
}
|
||||
54
pkg/cloudbroker/extnet/access_remove.go
Normal file
54
pkg/cloudbroker/extnet/access_remove.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for remove access
|
||||
type AccessRemoveRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
|
||||
// Account ID
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (erq AccessRemoveRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if erq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessRemove remove access from external network for account ID
|
||||
func (e ExtNet) AccessRemove(ctx context.Context, req AccessRemoveRequest) ([]uint64, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, 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
|
||||
}
|
||||
114
pkg/cloudbroker/extnet/create.go
Normal file
114
pkg/cloudbroker/extnet/create.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for create external network
|
||||
type CreateRequest struct {
|
||||
// External network name
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid"`
|
||||
|
||||
// IP network CIDR
|
||||
// For example 192.168.0.0/24
|
||||
// Required: true
|
||||
IPCIDR string `url:"ipcidr"`
|
||||
|
||||
// External network gateway IP address
|
||||
// Required: true
|
||||
Gateway string `url:"gateway"`
|
||||
|
||||
// VLAN ID
|
||||
// Required: true
|
||||
VLANID uint64 `url:"vlanId"`
|
||||
|
||||
// List of DNS addresses
|
||||
// Required: false
|
||||
DNS []string `url:"dns,omitempty"`
|
||||
|
||||
// List of NTP addresses
|
||||
// Required: false
|
||||
NTP []string `url:"ntp,omitempty"`
|
||||
|
||||
// IPs to check network availability
|
||||
// Required: false
|
||||
CheckIPs []string `url:"checkIps,omitempty"`
|
||||
|
||||
// If true - platform DHCP server will not be created
|
||||
// Required: false
|
||||
Virtual bool `url:"virtual,omitempty"`
|
||||
|
||||
// Optional description
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty"`
|
||||
|
||||
// Start of IP range to be explicitly included
|
||||
// Required: false
|
||||
StartIP string `url:"startIP,omitempty"`
|
||||
|
||||
// End of IP range to be explicitly included
|
||||
// Required: false
|
||||
EndIP string `url:"endIP,omitempty"`
|
||||
|
||||
// IP to create VNFDev with
|
||||
// Required: false
|
||||
VNFDevIP string `url:"vnfdevIP,omitempty"`
|
||||
|
||||
// Number of pre created reservations
|
||||
// Required: false
|
||||
PreReservationsNum uint64 `url:"preReservationsNum,omitempty"`
|
||||
|
||||
// OpenvSwith bridge name for ExtNet connection
|
||||
// Required: false
|
||||
OVSBridge string `url:"ovsBridge,omitempty"`
|
||||
}
|
||||
|
||||
func (erq CreateRequest) validate() error {
|
||||
if erq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if erq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if erq.IPCIDR == "" {
|
||||
return errors.New("validation-error: field IPCIDR must be set")
|
||||
}
|
||||
if erq.Gateway == "" {
|
||||
return errors.New("validation-error: field Gateway must be set")
|
||||
}
|
||||
if erq.VLANID == 0 {
|
||||
return errors.New("validation-error: field VLANID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates new external network into platform
|
||||
func (e ExtNet) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/create"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
57
pkg/cloudbroker/extnet/default_qos_update.go
Normal file
57
pkg/cloudbroker/extnet/default_qos_update.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for update QOS
|
||||
type DefaultQOSUpdateRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
|
||||
// Internal traffic, kbit
|
||||
// Required: false
|
||||
IngressRate uint64 `url:"ingress_rate,omitempty"`
|
||||
|
||||
// Internal traffic burst, kbit
|
||||
// Required: false
|
||||
IngressBurst uint64 `url:"ingress_burst,omitempty"`
|
||||
|
||||
// External traffic rate, kbit
|
||||
// Required: false
|
||||
EgressRate uint64 `url:"egress_rate,omitempty"`
|
||||
}
|
||||
|
||||
func (erq DefaultQOSUpdateRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DefaultQOSUpdate updates default qos values
|
||||
func (e ExtNet) DefaultQOSUpdate(ctx context.Context, req DefaultQOSUpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
45
pkg/cloudbroker/extnet/destroy.go
Normal file
45
pkg/cloudbroker/extnet/destroy.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for destroy
|
||||
type DestroyRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
}
|
||||
|
||||
func (erq DestroyRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Destroy destroys external network
|
||||
func (e ExtNet) Destroy(ctx context.Context, req DestroyRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
45
pkg/cloudbroker/extnet/device_deploy.go
Normal file
45
pkg/cloudbroker/extnet/device_deploy.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for deploy network device
|
||||
type DeviceDeployRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
}
|
||||
|
||||
func (erq DeviceDeployRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeviceDeploy deploys network device for external network (make not virtual, "physical")
|
||||
func (e ExtNet) DeviceDeploy(ctx context.Context, req DeviceDeployRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
45
pkg/cloudbroker/extnet/device_migrate.go
Normal file
45
pkg/cloudbroker/extnet/device_migrate.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for migrate VNF
|
||||
type DeviceMigrateRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
}
|
||||
|
||||
func (erq DeviceMigrateRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeviceMigrate migrate external network VNF device
|
||||
func (e ExtNet) DeviceMigrate(ctx context.Context, req DeviceMigrateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
45
pkg/cloudbroker/extnet/device_remove.go
Normal file
45
pkg/cloudbroker/extnet/device_remove.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for remove network device
|
||||
type DeviceRemoveRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
}
|
||||
|
||||
func (erq DeviceRemoveRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeviceRemove removes network device of external network (make it virtual, not "physical")
|
||||
func (e ExtNet) DeviceRemove(ctx context.Context, req DeviceRemoveRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
45
pkg/cloudbroker/extnet/device_restart.go
Normal file
45
pkg/cloudbroker/extnet/device_restart.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for restart VNF device
|
||||
type DeviceRestartRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
}
|
||||
|
||||
func (erq DeviceRestartRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeviceRestart restarts external network VNF device
|
||||
func (e ExtNet) DeviceRestart(ctx context.Context, req DeviceRestartRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
45
pkg/cloudbroker/extnet/disable.go
Normal file
45
pkg/cloudbroker/extnet/disable.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for disable external network
|
||||
type DisableRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
}
|
||||
|
||||
func (erq DisableRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disable disables external network
|
||||
func (e ExtNet) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
49
pkg/cloudbroker/extnet/dns_apply.go
Normal file
49
pkg/cloudbroker/extnet/dns_apply.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for set new DNS
|
||||
type DNSApplyRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
|
||||
// List of DNS to apply
|
||||
// Required: false
|
||||
DNSList []string `url:"dns_list,omitempty"`
|
||||
}
|
||||
|
||||
func (erq DNSApplyRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DNSApply sets new DNS
|
||||
func (e ExtNet) DNSApply(ctx context.Context, req DNSApplyRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
45
pkg/cloudbroker/extnet/enable.go
Normal file
45
pkg/cloudbroker/extnet/enable.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for enable external network
|
||||
type EnableRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
}
|
||||
|
||||
func (erq EnableRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Enable enables external networks
|
||||
func (e ExtNet) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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 "github.com/rudecs/decort-sdk/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,
|
||||
}
|
||||
}
|
||||
47
pkg/cloudbroker/extnet/get.go
Normal file
47
pkg/cloudbroker/extnet/get.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get information about external network
|
||||
type GetRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
}
|
||||
|
||||
func (erq GetRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get gets external network details
|
||||
func (e ExtNet) Get(ctx context.Context, req GetRequest) (*RecordExtNet, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/get"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordExtNet{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
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
|
||||
}
|
||||
52
pkg/cloudbroker/extnet/ips_exclude.go
Normal file
52
pkg/cloudbroker/extnet/ips_exclude.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for exclude list IPs
|
||||
type IPsExcludeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
|
||||
// List of IPs for exclude from external network
|
||||
// Required: true
|
||||
IPs []string `url:"ips"`
|
||||
}
|
||||
|
||||
func (erq IPsExcludeRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if len(erq.IPs) == 0 {
|
||||
return errors.New("validation-error: field IPs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IPsExclude exclude list IPs from external network pool
|
||||
func (e ExtNet) IPsExclude(ctx context.Context, req IPsExcludeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
59
pkg/cloudbroker/extnet/ips_exclude_range.go
Normal file
59
pkg/cloudbroker/extnet/ips_exclude_range.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for exclude range of IPs
|
||||
type IPsExcludeRangeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
|
||||
// Starting IP
|
||||
// Required: true
|
||||
IPStart string `url:"ip_start"`
|
||||
|
||||
// Ending IP
|
||||
// Required: true
|
||||
IPEnd string `url:"ip_end"`
|
||||
}
|
||||
|
||||
func (erq IPsExcludeRangeRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if erq.IPStart == "" {
|
||||
return errors.New("validation-error: field IPStart must be set")
|
||||
}
|
||||
if erq.IPEnd == "" {
|
||||
return errors.New("validation-error: field IPEnd must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IPsExcludeRange exclude range of IPs from external network pool
|
||||
func (e ExtNet) IPsExcludeRange(ctx context.Context, req IPsExcludeRangeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/extnet/ips_include.go
Normal file
52
pkg/cloudbroker/extnet/ips_include.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for include list IPs
|
||||
type IPsIncludeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
|
||||
// List of IPs for include to external network
|
||||
// Required: true
|
||||
IPs []string `url:"ips"`
|
||||
}
|
||||
|
||||
func (erq IPsIncludeRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if len(erq.IPs) == 0 {
|
||||
return errors.New("validation-error: field IPs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IPsInclude include list IPs to external network pool
|
||||
func (e ExtNet) IPsInclude(ctx context.Context, req IPsIncludeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
59
pkg/cloudbroker/extnet/ips_include_range.go
Normal file
59
pkg/cloudbroker/extnet/ips_include_range.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for include range of IPs
|
||||
type IPsIncludeRangeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
|
||||
// Starting IP
|
||||
// Required: true
|
||||
IPStart string `url:"ip_start"`
|
||||
|
||||
// Ending IP
|
||||
// Required: true
|
||||
IPEnd string `url:"ip_end"`
|
||||
}
|
||||
|
||||
func (erq IPsIncludeRangeRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if erq.IPStart == "" {
|
||||
return errors.New("validation-error: field IPStart must be set")
|
||||
}
|
||||
if erq.IPEnd == "" {
|
||||
return errors.New("validation-error: field IPEnd must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IPsIncludeRange include range of IPs to external network pool
|
||||
func (e ExtNet) IPsIncludeRange(ctx context.Context, req IPsIncludeRangeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
41
pkg/cloudbroker/extnet/list.go
Normal file
41
pkg/cloudbroker/extnet/list.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list external network
|
||||
type ListRequest struct {
|
||||
// Filter by account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list all available external networks
|
||||
func (e ExtNet) List(ctx context.Context, req ListRequest) (ListExtNet, error) {
|
||||
url := "/cloudbroker/extnet/list"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListExtNet{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
147
pkg/cloudbroker/extnet/models.go
Normal file
147
pkg/cloudbroker/extnet/models.go
Normal file
@@ -0,0 +1,147 @@
|
||||
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 uint64 `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 []ItemExtNet
|
||||
|
||||
// Detailed information about external network
|
||||
type RecordExtNet struct {
|
||||
// Main information about external network
|
||||
ItemExtNet
|
||||
|
||||
// CheckIPs
|
||||
CheckIPs []string `json:"checkIPs"`
|
||||
|
||||
// List DNS
|
||||
DNS []string `json:"dns"`
|
||||
|
||||
// List excludes
|
||||
Excluded []string `json:"excluded"`
|
||||
|
||||
// Gateway
|
||||
Gateway string `json:"gateway"`
|
||||
|
||||
// Network
|
||||
Network string `json:"network"`
|
||||
|
||||
// Prefix
|
||||
Prefix uint64 `json:"prefix"`
|
||||
|
||||
// List reservations
|
||||
Reservations ListReservations `json:"reservations"`
|
||||
}
|
||||
49
pkg/cloudbroker/extnet/ntp_apply.go
Normal file
49
pkg/cloudbroker/extnet/ntp_apply.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for set new NTP
|
||||
type NTPApplyRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
|
||||
// List of NTP to apply
|
||||
// Required: false
|
||||
NTPList []string `url:"ntp_list,omitempty"`
|
||||
}
|
||||
|
||||
func (erq NTPApplyRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NTPApply sets new NTP
|
||||
func (e ExtNet) NTPApply(ctx context.Context, req NTPApplyRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
45
pkg/cloudbroker/extnet/set_default.go
Normal file
45
pkg/cloudbroker/extnet/set_default.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for set external network as default
|
||||
type SetDefaultRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
}
|
||||
|
||||
func (erq SetDefaultRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetDefault sets external network as default for platform
|
||||
func (e ExtNet) SetDefault(ctx context.Context, req SetDefaultRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
53
pkg/cloudbroker/extnet/update.go
Normal file
53
pkg/cloudbroker/extnet/update.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for update external network
|
||||
type UpdateRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
|
||||
// New external network name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty"`
|
||||
|
||||
// New external network description
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (erq UpdateRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update updates external network parameters
|
||||
func (e ExtNet) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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