v1.12.9
This commit is contained in:
112
pkg/sdn/logicalports/create.go
Normal file
112
pkg/sdn/logicalports/create.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package logicalports
|
||||
|
||||
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 logical port
|
||||
type CreateRequest struct {
|
||||
// ID of the logical port
|
||||
// Required: true
|
||||
LogicalPortID string `url:"logical_port_id" json:"logical_port_id" validate:"required"`
|
||||
|
||||
// ID of the version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
|
||||
// ID of the access group
|
||||
// Required: true
|
||||
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// Description
|
||||
// Required: true
|
||||
Description string `url:"description" json:"description" validate:"required"`
|
||||
|
||||
// Display name
|
||||
// Required: true
|
||||
DisplayName string `url:"display_name" json:"display_name" validate:"required"`
|
||||
|
||||
// Enabled. True or False
|
||||
// Required: true
|
||||
Enabled interface{} `url:"enabled" json:"enabled" validate:"required,isBool"`
|
||||
|
||||
// Is excluded from firewall. True or False
|
||||
// Required: true
|
||||
IsExcludedFromFirewall interface{} `url:"is_excluded_from_firewall" json:"is_excluded_from_firewall" validate:"required,isBool"`
|
||||
|
||||
// Hypervisor
|
||||
// Required: true
|
||||
Hypervisor string `url:"hypervisor" json:"hypervisor" validate:"required"`
|
||||
|
||||
// Port security. True or False
|
||||
// Required: true
|
||||
PortSecurity interface{} `url:"port_security" json:"port_security" validate:"required,isBool"`
|
||||
|
||||
// Segment ID
|
||||
// Required: true
|
||||
SegmentID string `url:"segment_id" json:"segment_id" validate:"required"`
|
||||
|
||||
// Adapter MAC
|
||||
// Required: false
|
||||
AdapterMAC string `url:"adapter_mac,omitempty" json:"adapter_mac,omitempty"`
|
||||
|
||||
// Unique identifier
|
||||
// Required: false
|
||||
UniqueIdentifier string `url:"unique_identifier,omitempty" json:"unique_identifier,omitempty"`
|
||||
|
||||
// Logical port addresses
|
||||
// Required: false
|
||||
LogicalPortAddresses []LogicalPortAddress `url:"logical_port_addresses,omitempty" json:"logical_port_addresses,omitempty" validate:"dive"`
|
||||
}
|
||||
|
||||
// LogicalPortAddressRequest struct representing logical port address
|
||||
type LogicalPortAddressRequest struct {
|
||||
// IP address
|
||||
// Required: true
|
||||
IP string `url:"ip" json:"ip" validate:"required"`
|
||||
|
||||
// IP type
|
||||
// Required: true
|
||||
IPType string `url:"ip_type" json:"ip_type" validate:"required,oneof=IPv4 IPv6"`
|
||||
|
||||
// Is primary. True or False
|
||||
// Required: true
|
||||
IsPrimary interface{} `url:"is_primary" json:"is_primary" validate:"required,isBool"`
|
||||
|
||||
// MAC address
|
||||
// Required: false
|
||||
MAC string `url:"mac,omitempty" json:"mac,omitempty"`
|
||||
|
||||
// Is discovered. True or False
|
||||
// Required: false
|
||||
IsDiscovered interface{} `url:"is_discovered,omitempty" json:"is_discovered,omitempty" validate:"omitempty,isBool"`
|
||||
}
|
||||
|
||||
// Create creates a logical port
|
||||
func (l LogicalPorts) Create(ctx context.Context, req CreateRequest) (*LogicalPort, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/logical_port/create"
|
||||
|
||||
res, err := l.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := LogicalPort{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
Reference in New Issue
Block a user