You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
58 lines
1.4 KiB
|
4 days ago
|
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
|
||
|
|
}
|