v1.6.0-zeta

This commit is contained in:
2023-09-25 19:11:33 +03:00
parent 3e55195831
commit 78a4152471
33 changed files with 1166 additions and 39 deletions

View File

@@ -2,12 +2,24 @@ package extnet
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/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"`
}
// Request struct for create external network
type CreateRequest struct {
// External network name
@@ -70,6 +82,15 @@ type CreateRequest struct {
// 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
@@ -81,9 +102,31 @@ func (e ExtNet) Create(ctx context.Context, req CreateRequest) (uint64, error) {
}
}
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, req)
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}