v12.8.0
This commit is contained in:
80
pkg/sdn/adrspools/create.go
Normal file
80
pkg/sdn/adrspools/create.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package adrspools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/constants"
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/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
|
||||
}
|
||||
Reference in New Issue
Block a user