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.
53 lines
1.3 KiB
53 lines
1.3 KiB
|
4 days ago
|
package flips
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"encoding/json"
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||
|
|
)
|
||
|
|
|
||
|
|
type CreateRequest struct {
|
||
|
|
// Access Group ID
|
||
|
|
// Required: true
|
||
|
|
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||
|
|
|
||
|
|
// ID of an external network port
|
||
|
|
// Required: true
|
||
|
|
ExtNetPortID string `url:"external_network_port_id" json:"external_network_port_id" validate:"required"`
|
||
|
|
|
||
|
|
// ID of a logical network port
|
||
|
|
// Required: true
|
||
|
|
LogicalPortID string `url:"logical_port_id" json:"logical_port_id" validate:"required"`
|
||
|
|
|
||
|
|
// ID of a router
|
||
|
|
// Required: true
|
||
|
|
RouterID string `url:"router_id" json:"router_id" validate:"required"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Create creates a floating ip
|
||
|
|
func (fi FloatingIPs) Create(ctx context.Context, req CreateRequest) (*RecordFloatingIP, error) {
|
||
|
|
err := validators.ValidateRequest(req)
|
||
|
|
if err != nil {
|
||
|
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||
|
|
}
|
||
|
|
|
||
|
|
url := "/sdn/floating_ip/create"
|
||
|
|
|
||
|
|
res, err := fi.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
info := RecordFloatingIP{}
|
||
|
|
|
||
|
|
err = json.Unmarshal(res, &info)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return &info, nil
|
||
|
|
}
|