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.
78 lines
2.0 KiB
78 lines
2.0 KiB
|
4 days ago
|
package extnet
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"encoding/json"
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||
|
|
)
|
||
|
|
|
||
|
|
// PortAddRequest struct for add port to extnet
|
||
|
|
type PortAddRequest struct {
|
||
|
|
// ID of external network
|
||
|
|
// Required: true
|
||
|
|
ExtNetID string `url:"external_network_id" json:"external_network_id" validate:"required"`
|
||
|
|
|
||
|
|
// Access group ID
|
||
|
|
// Required: true
|
||
|
|
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||
|
|
|
||
|
|
// ID of version
|
||
|
|
// Required: true
|
||
|
|
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||
|
|
|
||
|
|
// Description of the port addition operation
|
||
|
|
// Required: true
|
||
|
|
Comment string `url:"comment" json:"comment" validate:"required"`
|
||
|
|
|
||
|
|
// User-friendly name for the external network
|
||
|
|
// Required: true
|
||
|
|
DisplayName string `url:"display_name" json:"display_name" validate:"required"`
|
||
|
|
|
||
|
|
// Whether the network is enabled
|
||
|
|
// Required: true
|
||
|
|
Enabled bool `url:"enabled" json:"enabled"`
|
||
|
|
|
||
|
|
// IPv4
|
||
|
|
// Required: false
|
||
|
|
IPv4 string `url:"ipv4,omitempty" json:"ipv4,omitempty"`
|
||
|
|
|
||
|
|
// IPv6
|
||
|
|
// Required: false
|
||
|
|
IPv6 string `url:"ipv6,omitempty" json:"ipv6,omitempty"`
|
||
|
|
|
||
|
|
// IPv6 Config
|
||
|
|
// Required: false
|
||
|
|
IPv6Config *IPv6ConfigRequest `url:"-" json:"ipv6_config,omitempty"`
|
||
|
|
|
||
|
|
// MAC address
|
||
|
|
// Required: false
|
||
|
|
MAC string `url:"mac,omitempty" json:"mac,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddPort added a port an external network
|
||
|
|
func (e ExtNet) AddPort(ctx context.Context, req PortAddRequest) (*ExternalNetworkAddPortsResponce, error) {
|
||
|
|
err := validators.ValidateRequest(req)
|
||
|
|
if err != nil {
|
||
|
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||
|
|
}
|
||
|
|
|
||
|
|
url := "/sdn/external_network/port_add"
|
||
|
|
|
||
|
|
res, err := e.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
info := ExternalNetworkAddPortsResponce{}
|
||
|
|
|
||
|
|
err = json.Unmarshal(res, &info)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return &info, nil
|
||
|
|
}
|