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.
81 lines
2.2 KiB
81 lines
2.2 KiB
|
4 days ago
|
package adrspools
|
||
|
|
|
||
|
|
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 address pool
|
||
|
|
type CreateRequest struct {
|
||
|
|
// ID of the access group
|
||
|
|
// Required: true
|
||
|
|
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||
|
|
|
||
|
|
// Description of the network
|
||
|
|
// Required: true
|
||
|
|
Description string `url:"description" json:"description" validate:"required"`
|
||
|
|
|
||
|
|
// Name of the network
|
||
|
|
// Required: true
|
||
|
|
Name string `url:"name" json:"name" validate:"required"`
|
||
|
|
|
||
|
|
// Network address type
|
||
|
|
// Required: true
|
||
|
|
NetAddressType string `url:"net_address_type" json:"net_address_type" validate:"required,addressPoolNetTypeValidator"`
|
||
|
|
|
||
|
|
// List of network addresses
|
||
|
|
// Required: false
|
||
|
|
NetAddresses []NetAddress `url:"net_addresses,omitempty" json:"net_addresses,omitempty" validate:"dive"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// NetAddress struct representing network address
|
||
|
|
type NetAddress struct {
|
||
|
|
// Network address type
|
||
|
|
// Required: true
|
||
|
|
NetAddressType string `url:"net_address_type" json:"net_address_type" validate:"required,addressPoolNetTypeValidator"`
|
||
|
|
|
||
|
|
// IP address
|
||
|
|
// Required: true
|
||
|
|
IPAddr string `url:"ip_addr" json:"ip_addr" validate:"required"`
|
||
|
|
|
||
|
|
// End of IP address range
|
||
|
|
// Required: false
|
||
|
|
IPAddrRangeEnd string `url:"ip_addr_range_end,omitempty" json:"ip_addr_range_end,omitempty"`
|
||
|
|
|
||
|
|
// IP prefix
|
||
|
|
// Required: false
|
||
|
|
IPPrefix string `url:"ip_prefix,omitempty" json:"ip_prefix,omitempty"`
|
||
|
|
|
||
|
|
// MAC address
|
||
|
|
// Required: false
|
||
|
|
MACAddr string `url:"mac_addr,omitempty" json:"mac_addr,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Create creates a address pool
|
||
|
|
func (i AddressPools) Create(ctx context.Context, req CreateRequest) (*NetworkAddressPool, error) {
|
||
|
|
err := validators.ValidateRequest(req)
|
||
|
|
if err != nil {
|
||
|
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||
|
|
}
|
||
|
|
|
||
|
|
url := "/sdn/address_pool/create"
|
||
|
|
|
||
|
|
res, err := i.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
info := NetworkAddressPool{}
|
||
|
|
|
||
|
|
err = json.Unmarshal(res, &info)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return &info, nil
|
||
|
|
}
|