1.6.0-delta
This commit is contained in:
@@ -2,12 +2,24 @@ package vins
|
||||
|
||||
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 VINS in account
|
||||
type CreateInAccountRequest struct {
|
||||
// VINS name
|
||||
@@ -33,6 +45,15 @@ type CreateInAccountRequest struct {
|
||||
// Number of pre created reservations
|
||||
// Required: false
|
||||
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,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 wrapperCreateRequestInAcc struct {
|
||||
CreateInAccountRequest
|
||||
Routes []string `url:"routes,omitempty"`
|
||||
}
|
||||
|
||||
// CreateInAccount creates VINS in account level
|
||||
@@ -44,9 +65,31 @@ func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (
|
||||
}
|
||||
}
|
||||
|
||||
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 := wrapperCreateRequestInAcc{
|
||||
CreateInAccountRequest: req,
|
||||
Routes: routes,
|
||||
}
|
||||
|
||||
url := "/cloudapi/vins/createInAccount"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -37,6 +38,15 @@ type CreateInRGRequest struct {
|
||||
// Number of pre created reservations
|
||||
// Required: false
|
||||
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,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 wrapperCreateRequestInRG struct {
|
||||
CreateInRGRequest
|
||||
Routes []string `url:"routes,omitempty"`
|
||||
}
|
||||
|
||||
// CreateInRG creates VINS in resource group level
|
||||
@@ -48,9 +58,31 @@ func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, er
|
||||
}
|
||||
}
|
||||
|
||||
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 := wrapperCreateRequestInRG{
|
||||
CreateInRGRequest: req,
|
||||
Routes: routes,
|
||||
}
|
||||
|
||||
url := "/cloudapi/vins/createInRG"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -252,6 +252,9 @@ type ItemVNFInterface struct {
|
||||
// Default GW
|
||||
DefGW string `json:"defGw"`
|
||||
|
||||
// Enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// FLIPGroup ID
|
||||
FLIPGroupID uint64 `json:"flipgroupId"`
|
||||
|
||||
@@ -378,6 +381,9 @@ type RecordNAT struct {
|
||||
// Pure virtual
|
||||
PureVirtual bool `json:"pureVirtual"`
|
||||
|
||||
// Routes
|
||||
Routes ListRoutes `json:"routes"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
@@ -443,6 +449,9 @@ type RecordGW struct {
|
||||
// Pure virtual
|
||||
PureVirtual bool `json:"pureVirtual"`
|
||||
|
||||
// Routes
|
||||
Routes ListRoutes `json:"routes"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
@@ -530,6 +539,9 @@ type RecordDHCP struct {
|
||||
// Pure virtual
|
||||
PureVirtual bool `json:"pureVirtual"`
|
||||
|
||||
// Routes
|
||||
Routes ListRoutes `json:"routes"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
@@ -567,6 +579,39 @@ type RecordDHCPConfig struct {
|
||||
Reservations ListReservations `json:"reservations"`
|
||||
}
|
||||
|
||||
// List of static routes
|
||||
type ListStaticRoutes struct {
|
||||
// Data
|
||||
Data []ItemRoutes `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// List of Routes
|
||||
type ListRoutes []ItemRoutes
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// Detailed information about VINS
|
||||
type RecordVINS struct {
|
||||
// Main information about VNF device
|
||||
|
||||
42
pkg/cloudapi/vins/staticRouteList.go
Normal file
42
pkg/cloudapi/vins/staticRouteList.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for static route list
|
||||
type StaticRouteListRequest struct {
|
||||
// ViNS ID to show list of static routes
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||
}
|
||||
|
||||
// Show list of static routes for ViNS
|
||||
func (v VINS) StaticRouteList(ctx context.Context, req StaticRouteListRequest) (*ListStaticRoutes, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/vins/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
|
||||
}
|
||||
48
pkg/cloudapi/vins/static_route_access_grant.go
Normal file
48
pkg/cloudapi/vins/static_route_access_grant.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for grant access to static route to Compute/ViNS
|
||||
type StaticRouteAccessGrantRequest struct {
|
||||
// ViNS ID to grant access
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId" 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"`
|
||||
}
|
||||
|
||||
// Grant access to static route to Compute/ViNS
|
||||
func (v VINS) StaticRouteAccessGrant(ctx context.Context, req StaticRouteAccessGrantRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/vins/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
|
||||
}
|
||||
48
pkg/cloudapi/vins/static_route_access_revoke.go
Normal file
48
pkg/cloudapi/vins/static_route_access_revoke.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for revoke access to static route to Compute/ViNS
|
||||
type StaticRouteAccessRevokeRequest struct {
|
||||
// ViNS ID to revoke access
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId" 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"`
|
||||
}
|
||||
|
||||
// Revoke access to static route to Compute/ViNS
|
||||
func (v VINS) StaticRouteAccessRevoke(ctx context.Context, req StaticRouteAccessRevokeRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/vins/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
|
||||
}
|
||||
56
pkg/cloudapi/vins/static_route_add.go
Normal file
56
pkg/cloudapi/vins/static_route_add.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add static route
|
||||
type StaticRouteAddRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId" 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 add new static route to ViNS
|
||||
func (v VINS) StaticRouteAdd(ctx context.Context, req StaticRouteAddRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/vins/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
|
||||
}
|
||||
44
pkg/cloudapi/vins/static_route_del.go
Normal file
44
pkg/cloudapi/vins/static_route_del.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for remove static route from ViNS
|
||||
type StaticRouteDelRequest struct {
|
||||
// ViNS ID to remove static route from
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||
|
||||
// Route ID to remove, can be found in staticRouteList
|
||||
// Required: true
|
||||
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||
}
|
||||
|
||||
// Remove static route from ViNS
|
||||
func (v VINS) StaticRouteDel(ctx context.Context, req StaticRouteDelRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/vins/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
|
||||
}
|
||||
Reference in New Issue
Block a user