v1.12.9
This commit is contained in:
57
pkg/sdn/routers/gwport/create.go
Normal file
57
pkg/sdn/routers/gwport/create.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package gwport
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// CreateRequest struct to create gateway port
|
||||
type CreateRequest struct {
|
||||
// ID of router
|
||||
// Required: true
|
||||
RouterID string `url:"router_id" json:"router_id" validate:"required"`
|
||||
|
||||
// ID of version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
|
||||
// Detailed description of the external network
|
||||
// Required: true
|
||||
Description string `url:"description" json:"description" validate:"required"`
|
||||
|
||||
// External network port ID
|
||||
// Required: true
|
||||
ExternalNetworkPortID string `url:"external_network_port_id" json:"external_network_port_id" validate:"required"`
|
||||
|
||||
// Whether is enabled
|
||||
// Required: true
|
||||
Enabled bool `url:"snat_enabled" json:"snat_enabled"`
|
||||
}
|
||||
|
||||
// Create creates a gateway port
|
||||
func (i GWPort) Create(ctx context.Context, req CreateRequest) (*GatewayPort, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/router/gateway_port/create"
|
||||
|
||||
res, err := i.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := GatewayPort{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
Reference in New Issue
Block a user