v12.8.0
This commit is contained in:
729
pkg/sdn/extnet/create.go
Normal file
729
pkg/sdn/extnet/create.go
Normal file
@@ -0,0 +1,729 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/constants"
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
// CreateRequest struct for creating account
|
||||
type CreateRequest struct {
|
||||
// Name of the bridge network
|
||||
// Required: true
|
||||
BridgeNetworkName string `url:"bridge_network_name" json:"bridge_network_name" validate:"required"`
|
||||
|
||||
// Detailed description of the external network
|
||||
// Required: true
|
||||
Description string `url:"description" json:"description" 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"`
|
||||
|
||||
// List of hypervisor names
|
||||
// Required: true
|
||||
Hypervisors []string `url:"hypervisors" json:"hypervisors" validate:"required"`
|
||||
|
||||
// List of external network ports
|
||||
// Required: false
|
||||
ExternalNetworkPorts []ExternalNetworkPortRequest `url:"-" json:"external_network_ports,omitempty"`
|
||||
|
||||
// IPv4 default gateway address
|
||||
// Required: false
|
||||
DefaultGatewayIPv4 string `url:"default_gateway_ipv4,omitempty" json:"default_gateway_ipv4,omitempty"`
|
||||
|
||||
// IPv6 default gateway address
|
||||
// Required: false
|
||||
DefaultGatewayIPv6 string `url:"default_gateway_ipv6,omitempty" json:"default_gateway_ipv6,omitempty"`
|
||||
|
||||
// IPv4 subnet in CIDR notation (Either subnet_v4 or subnet_v6 must be specified)
|
||||
// Required: false
|
||||
SubnetV4 string `url:"subnet_v4,omitempty" json:"subnet_v4,omitempty"`
|
||||
|
||||
// IPv6 subnet in CIDR notation (Either subnet_v4 or subnet_v6 must be specified)
|
||||
// Required: false
|
||||
SubnetV6 string `url:"subnet_v6,omitempty" json:"subnet_v6,omitempty"`
|
||||
|
||||
// VLAN tag identifier
|
||||
// Required: false
|
||||
VLANTag string `url:"vlan_tag,omitempty" json:"vlan_tag,omitempty" validate:"omitempty,trunkTags"`
|
||||
}
|
||||
|
||||
type ExternalNetworkPortRequest struct {
|
||||
// Access group ID
|
||||
// Required: true
|
||||
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// Access group name
|
||||
// Required: false
|
||||
AccessGroupName string `url:"access_group_name,omitempty" json:"access_group_name,omitempty"`
|
||||
|
||||
// Comment for the external network port
|
||||
// Required: true
|
||||
Comment string `url:"comment" json:"comment" validate:"required"`
|
||||
|
||||
// User-friendly name for the external network port
|
||||
// Required: true
|
||||
DisplayName string `url:"display_name" json:"display_name" validate:"required"`
|
||||
|
||||
// Whether the network pork 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: true
|
||||
MAC string `url:"mac" json:"mac" validate:"required"`
|
||||
|
||||
// Router gateway port
|
||||
// Required: false
|
||||
RouterGatewayPort *RouterGatewayPortRequest `url:"-" json:"router_gateway_port,omitempty"`
|
||||
|
||||
// Floating IP
|
||||
// Required: false
|
||||
FloatingIP *FloatingIPRequest `url:"-" json:"floating_ip,omitempty"`
|
||||
}
|
||||
|
||||
type IPv6ConfigRequest struct {
|
||||
//Address Mode (Slaac or DhcpV6Stateful)
|
||||
// Required: true
|
||||
AddressMode string `url:"address_mode" json:"address_mode" validate:"required"`
|
||||
|
||||
// If true, the port will periodically send RA packets.
|
||||
// Required: true
|
||||
EnablePeriodicRa bool `url:"enable_periodic_ra" json:"enable_periodic_ra"`
|
||||
|
||||
// The number of waiting seconds between sending periodic RA
|
||||
// Required: true
|
||||
IntervalRa int64 `url:"interval_ra" json:"interval_ra" validate:"required"`
|
||||
|
||||
// The Default Router Preference (PRF) indicates whether this router should be preferred over other default routers.
|
||||
// high, low, medium
|
||||
// Required: true
|
||||
RouterPreference string `url:"router_preference" json:"router_preference" validate:"required"`
|
||||
}
|
||||
|
||||
type RouterGatewayPortRequest struct {
|
||||
// Created at
|
||||
// Required: true
|
||||
CreatedAt time.Time `url:"created_at" json:"created_at" validate:"required"`
|
||||
|
||||
// Description
|
||||
// Required: true
|
||||
Description string `url:"description" json:"description" validate:"required"`
|
||||
|
||||
// Port id
|
||||
// Required: true
|
||||
ID string `url:"id" json:"id" validate:"required"`
|
||||
|
||||
// User-friendly name for the external network port
|
||||
// Required: true
|
||||
RouterDisplayName string `url:"router_display_name" json:"router_display_name" validate:"required"`
|
||||
|
||||
// Router ID
|
||||
// Required: true
|
||||
RouterID string `url:"router_id" json:"router_id" validate:"required"`
|
||||
|
||||
// SNAT Enabled
|
||||
// Required: true
|
||||
SNATEnabled bool `url:"snat_enabled" json:"snat_enabled"`
|
||||
|
||||
// Updated at
|
||||
// Required: true
|
||||
UpdatedAt time.Time `url:"updated_at" json:"updated_at" validate:"required"`
|
||||
}
|
||||
|
||||
type FloatingIPRequest struct {
|
||||
// Access group ID
|
||||
// Required: true
|
||||
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// Access group name
|
||||
// Required: true
|
||||
AccessGroupName string `url:"access_group_name" json:"access_group_name" validate:"required"`
|
||||
|
||||
// Created at
|
||||
// Required: true
|
||||
CreatedAt time.Time `url:"created_at" json:"created_at" validate:"required"`
|
||||
|
||||
// External network port
|
||||
// Required: true
|
||||
ExternalNetworkPort string `url:"external_network_port" json:"external_network_port" validate:"required"`
|
||||
|
||||
// ID of the Floating IP
|
||||
// Required: true
|
||||
ID string `url:"id" json:"id" validate:"required"`
|
||||
|
||||
// Logical port
|
||||
// Required: false
|
||||
LogicalPort *LogicalPortRequest `url:"-" json:"logical_port,omitempty"`
|
||||
|
||||
// Router
|
||||
// Required: true
|
||||
Router *RouterRequest `url:"-" json:"router" validate:"required"`
|
||||
|
||||
// Updated at
|
||||
// Required: true
|
||||
UpdatedAt time.Time `url:"updated_at" json:"updated_at" validate:"required"`
|
||||
|
||||
// ID of version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
}
|
||||
|
||||
type LogicalPortRequest struct {
|
||||
// Logical Port ID
|
||||
// Required: true
|
||||
ID string `url:"id" json:"id" validate:"required"`
|
||||
|
||||
// Access group ID
|
||||
// Required: true
|
||||
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// Access group name
|
||||
// Required: true
|
||||
AccessGroupName string `url:"access_group_name" json:"access_group_name" validate:"required"`
|
||||
|
||||
// MAC of adapter
|
||||
// Required: true
|
||||
AdapterMAC string `url:"adapter_mac" json:"adapter_mac" validate:"required"`
|
||||
|
||||
// Address detection
|
||||
// Required: true
|
||||
AddressDetection bool `url:"address_detection" json:"address_detection" validate:"required"`
|
||||
|
||||
// Description
|
||||
// Required: true
|
||||
Description string `url:"description" json:"description" validate:"required"`
|
||||
|
||||
// Created at
|
||||
// Required: false
|
||||
CreatedAt time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
|
||||
|
||||
// User-friendly name for router
|
||||
// Required: true
|
||||
RouterDisplayName string `url:"router_display_name" json:"router_display_name" validate:"required"`
|
||||
|
||||
// Whether the logical pork is enabled
|
||||
// Required: true
|
||||
Enabled bool `url:"enabled" json:"enabled"`
|
||||
|
||||
// External Network ID
|
||||
// Required: false
|
||||
ExternalNetworkID string `url:"external_network_id,omitempty" json:"external_network_id,omitempty"`
|
||||
|
||||
// Hypervisor
|
||||
// Required: true
|
||||
Hypervisor string `url:"hypervisor" json:"hypervisor" validate:"required"`
|
||||
|
||||
// User-friendly name for hypervisor
|
||||
// Required: false
|
||||
HypervisorDisplayName string `url:"hypervisor_display_name,omitempty" json:"hypervisor_display_name,omitempty"`
|
||||
|
||||
// Live Migration Target Hv
|
||||
// Required: true
|
||||
LiveMigrationTargetHV string `url:"live_migration_target_hv" json:"live_migration_target_hv" validate:"required"`
|
||||
|
||||
// Status
|
||||
// Required: true
|
||||
Status *StatusRequest `url:"-" json:"status" validate:"required"`
|
||||
|
||||
// Port bindings
|
||||
// Required: true
|
||||
Bindings *PortBindingsRequest `url:"-" json:"bindings" validate:"required"`
|
||||
|
||||
// Unique Identifier
|
||||
// Required: true
|
||||
UniqueIDentifier string `url:"unique_identifier" json:"unique_identifier" validate:"required"`
|
||||
|
||||
// Updated at
|
||||
// Required: true
|
||||
UpdatedAt time.Time `url:"updated_at" json:"updated_at" validate:"required"`
|
||||
|
||||
// ID of version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
}
|
||||
|
||||
type StatusRequest struct {
|
||||
// Common
|
||||
// Required: true
|
||||
Common string `url:"common" json:"common" validate:"required"`
|
||||
|
||||
// Hypervisors status
|
||||
// Required: false
|
||||
Hypervisors []HypervisorStatusRequest `url:"-" json:"hypervisors,omitempty"`
|
||||
}
|
||||
|
||||
type PortBindingsRequest struct {
|
||||
// Binding ID
|
||||
// Required: true
|
||||
ID string `url:"id" json:"id" validate:"required"`
|
||||
|
||||
// User-friendly name for segment
|
||||
// Required: true
|
||||
SegmentDisplayName string `url:"segment_display_name" json:"segment_display_name" validate:"required"`
|
||||
|
||||
// Segment ID
|
||||
// Required: true
|
||||
SegmentID string `url:"segment_id" json:"segment_id" validate:"required"`
|
||||
|
||||
// Port security
|
||||
// Required: true
|
||||
PortSecurity bool `url:"port_security" json:"port_security" validate:"required"`
|
||||
|
||||
// Address detection
|
||||
// Required: true
|
||||
AddressDetection bool `url:"address_detection" json:"address_detection" validate:"required"`
|
||||
|
||||
// Is Exclude From Firewall
|
||||
// Required: true
|
||||
IsExcludedFromFirewall bool `url:"is_excluded_from_firewall" json:"is_excluded_from_firewall" validate:"required"`
|
||||
|
||||
// ID of version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
|
||||
// Created at
|
||||
// Required: true
|
||||
CreatedAt time.Time `url:"created_at" json:"created_at" validate:"required"`
|
||||
|
||||
// Updated at
|
||||
// Required: true
|
||||
UpdatedAt time.Time `url:"updated_at" json:"updated_at" validate:"required"`
|
||||
|
||||
// Logical port addresses
|
||||
// Required: true
|
||||
LogicalPortAddresses []LogicalPortAddressRequest `url:"-" json:"logical_port_addresses" validate:"required"`
|
||||
}
|
||||
|
||||
type HypervisorStatusRequest struct {
|
||||
// Status
|
||||
// Required: true
|
||||
Status string `url:"status" json:"status" validate:"required"`
|
||||
|
||||
// Name of hypervisor
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// User-friendly name for the hypervisor
|
||||
// Required: true
|
||||
DisplayName string `url:"display_name" json:"display_name" validate:"required"`
|
||||
|
||||
// Hypervisor status
|
||||
// Required: true
|
||||
HypervisorStatus string `url:"hypervisor_status" json:"hypervisor_status" validate:"required"`
|
||||
|
||||
// Synced at
|
||||
// Required: true
|
||||
SyncedAt time.Time `url:"synced_at" json:"synced_at" validate:"required"`
|
||||
}
|
||||
|
||||
type LogicalPortAddressRequest struct {
|
||||
// IP of port
|
||||
// Required: true
|
||||
IP string `url:"ip" json:"ip" validate:"required"`
|
||||
|
||||
// IP type (IPv4 or IPv6)
|
||||
// Required: true
|
||||
IPType string `url:"ip_type" json:"ip_type" validate:"required"`
|
||||
|
||||
// Is discovered
|
||||
// Required: false
|
||||
IsDiscovered bool `url:"is_discovered,omitempty" json:"is_discovered,omitempty"`
|
||||
|
||||
// Is discovered
|
||||
// Required: true
|
||||
IsPrimary bool `url:"is_primary" json:"is_primary" validate:"required"`
|
||||
|
||||
// MAC
|
||||
// Required: false
|
||||
MAC string `url:"mac,omitempty" json:"mac,omitempty"`
|
||||
|
||||
// ID
|
||||
// Required: true
|
||||
ID string `url:"id" json:"id" validate:"required"`
|
||||
|
||||
// Logical port id
|
||||
// Required: true
|
||||
LogicalPortID string `url:"logical_port_id" json:"logical_port_id" validate:"required"`
|
||||
|
||||
// Assigned at
|
||||
// Required: false
|
||||
AssignedAt time.Time `url:"assigned_at,omitempty" json:"assigned_at,omitempty"`
|
||||
}
|
||||
|
||||
type RouterRequest struct {
|
||||
// Access group ID
|
||||
// Required: false
|
||||
AccessGroupID string `url:"access_group_id,omitempty" json:"access_group_id,omitempty"`
|
||||
|
||||
// Access group name
|
||||
// Required: false
|
||||
AccessGroupName string `url:"access_group_name,omitempty" json:"access_group_name,omitempty"`
|
||||
|
||||
// Created at
|
||||
// Required: false
|
||||
CreatedAt time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
|
||||
|
||||
// Detailed description of the router
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
|
||||
// User-friendly name for the router
|
||||
// Required: true
|
||||
DisplayName string `url:"display_name" json:"display_name" validate:"required"`
|
||||
|
||||
// Whether the router is enabled
|
||||
// Required: false
|
||||
Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"`
|
||||
|
||||
// Gateway ports
|
||||
// Required: false
|
||||
GatewayPorts []GatewayPortRequest `url:"-" json:"gateway_ports,omitempty"`
|
||||
|
||||
// ID
|
||||
// Required: true
|
||||
ID string `url:"id" json:"id" validate:"required"`
|
||||
|
||||
// Policies
|
||||
// Required: false
|
||||
Policies []RouterPolicyRequest `url:"-" json:"policies,omitempty"`
|
||||
|
||||
// Ports
|
||||
// Required: false
|
||||
Ports []RouterPortRequest `url:"-" json:"ports,omitempty"`
|
||||
|
||||
// Status
|
||||
// Required: false
|
||||
Status *StatusRequest `url:"-" json:"status,omitempty"`
|
||||
|
||||
// Updated at
|
||||
// Required: false
|
||||
UpdatedAt time.Time `url:"updated_at,omitempty" json:"updated_at,omitempty"`
|
||||
|
||||
// ID of version
|
||||
// Required: false
|
||||
VersionID uint64 `url:"version_id,omitempty" json:"version_id,omitempty"`
|
||||
}
|
||||
|
||||
type GatewayPortRequest struct {
|
||||
// Created at
|
||||
// Required: true
|
||||
CreatedAt time.Time `url:"created_at" json:"created_at" validate:"required"`
|
||||
|
||||
// Description
|
||||
// Required: true
|
||||
Description string `url:"description" json:"description" validate:"required"`
|
||||
|
||||
// L4 port max
|
||||
// Required: false
|
||||
ExternalL4PortMax int64 `url:"external_l4_port_max,omitempty" json:"external_l4_port_max,omitempty"`
|
||||
|
||||
// L4 port min
|
||||
// Required: false
|
||||
ExternalL4PortMin int64 `url:"external_l4_port_min,omitempty" json:"external_l4_port_min,omitempty"`
|
||||
|
||||
// External network port
|
||||
// Required: true
|
||||
ExternalNetworkPort interface{} `url:"external_network_port" json:"external_network_port" validate:"required"`
|
||||
|
||||
// ID of port
|
||||
// Required: false
|
||||
ID string `url:"id,omitempty" json:"id,omitempty"`
|
||||
|
||||
// SNAT Enabled
|
||||
// Required: true
|
||||
SNATEnabled bool `url:"snat_enabled" json:"snat_enabled"`
|
||||
|
||||
// Status
|
||||
// Required: false
|
||||
Status *StatusRequest `url:"-" json:"status,omitempty"`
|
||||
|
||||
// Updated at
|
||||
// Required: true
|
||||
UpdatedAt time.Time `url:"updated_at" json:"updated_at" validate:"required"`
|
||||
|
||||
// ID of version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
}
|
||||
|
||||
type RouterPolicyRequest struct {
|
||||
// Action
|
||||
// Required: true
|
||||
Action string `url:"action" json:"action" validate:"required"`
|
||||
|
||||
// Created at
|
||||
// Required: true
|
||||
CreatedAt time.Time `url:"created_at" json:"created_at" validate:"required"`
|
||||
|
||||
// User-friendly name for the policy
|
||||
// Required: true
|
||||
DisplayName string `url:"display_name" json:"display_name" validate:"required"`
|
||||
|
||||
// Whether the policy is enabled
|
||||
// Required: false
|
||||
Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"`
|
||||
|
||||
// ID of port
|
||||
// Required: false
|
||||
ID string `url:"id,omitempty" json:"id,omitempty"`
|
||||
|
||||
// Match
|
||||
// Required: true
|
||||
Match interface{} `url:"match" json:"match" validate:"required"`
|
||||
|
||||
// Next IPv4 address
|
||||
// Required: true
|
||||
NextIPv4Address []string `url:"next_ipv4_address" json:"next_ipv4_address" validate:"required"`
|
||||
|
||||
// Next IPv6 address
|
||||
// Required: true
|
||||
NextIPv6Address []string `url:"next_ipv6_address" json:"next_ipv6_address" validate:"required"`
|
||||
|
||||
// Priority
|
||||
// Required: true
|
||||
Priority int64 `url:"priority" json:"priority" validate:"required"`
|
||||
|
||||
// Updated at
|
||||
// Required: true
|
||||
UpdatedAt time.Time `url:"updated_at" json:"updated_at" validate:"required"`
|
||||
|
||||
// ID of version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
}
|
||||
|
||||
type RouterPortRequest struct {
|
||||
// Created at
|
||||
// Required: true
|
||||
CreatedAt time.Time `url:"created_at" json:"created_at" validate:"required"`
|
||||
|
||||
// Detailed description of the router port
|
||||
// Required: true
|
||||
Description string `url:"description" json:"description" validate:"required"`
|
||||
|
||||
// Whether the router port is enabled
|
||||
// Required: true
|
||||
Enabled bool `url:"enabled" json:"enabled"`
|
||||
|
||||
// ID of port
|
||||
// Required: false
|
||||
ID string `url:"id,omitempty" json:"id,omitempty"`
|
||||
|
||||
// Next IPv4 address
|
||||
// Required: true
|
||||
NextIPv4Address []string `url:"next_ipv4_address" json:"next_ipv4_address" validate:"required"`
|
||||
|
||||
// Next IPv6 address
|
||||
// Required: true
|
||||
NextIPv6Address []string `url:"next_ipv6_address" json:"next_ipv6_address" validate:"required"`
|
||||
|
||||
// IPv6 Config
|
||||
// Required: true
|
||||
IPv6Config *IPv6ConfigRequest `url:"-" json:"ipv6_config" validate:"required"`
|
||||
|
||||
// MAC address
|
||||
// Required: true
|
||||
MAC string `url:"mac" json:"mac" validate:"required"`
|
||||
|
||||
// Segment
|
||||
// Required: true
|
||||
Segment *SegmentRequest `url:"-" json:"segment" validate:"required"`
|
||||
|
||||
// Segment ID
|
||||
// Required: true
|
||||
SegmentID string `url:"segment_id" json:"segment_id" validate:"required"`
|
||||
|
||||
// Status
|
||||
// Required: false
|
||||
Status *StatusRequest `url:"-" json:"status,omitempty"`
|
||||
|
||||
// Updated at
|
||||
// Required: true
|
||||
UpdatedAt time.Time `url:"updated_at" json:"updated_at" validate:"required"`
|
||||
|
||||
// ID of version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
}
|
||||
|
||||
type SegmentRequest struct {
|
||||
// Access group ID
|
||||
// Required: true
|
||||
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// Access group name
|
||||
// Required: false
|
||||
AccessGroupName string `url:"access_group_name,omitempty" json:"access_group_name,omitempty"`
|
||||
|
||||
// Created at
|
||||
// Required: true
|
||||
CreatedAt time.Time `url:"created_at" json:"created_at" validate:"required"`
|
||||
|
||||
// Detailed description of the router port
|
||||
// Required: true
|
||||
Description string `url:"description" json:"description" validate:"required"`
|
||||
|
||||
// DHCP IPv4
|
||||
// Required: false
|
||||
DHCPv4 *DHCPv4ConfigRequest `url:"-" json:"dhcp_v4,omitempty"`
|
||||
|
||||
// DHCP IPv6
|
||||
// Required: false
|
||||
DHCPv6 *DHCPv6ConfigRequest `url:"-" json:"dhcp_v6,omitempty"`
|
||||
|
||||
// User-friendly name for the segment
|
||||
// Required: true
|
||||
DisplayName string `url:"display_name" json:"display_name" validate:"required"`
|
||||
|
||||
// Whether the segment is enabled
|
||||
// Required: false
|
||||
Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"`
|
||||
|
||||
// ID of segment
|
||||
// Required: false
|
||||
ID string `url:"id,omitempty" json:"id,omitempty"`
|
||||
|
||||
// Logical ports info
|
||||
// Required: false
|
||||
LogicalPortsInfo []EntityInfoRequest `url:"-" json:"logical_ports_info,omitempty"`
|
||||
|
||||
// Routers info
|
||||
// Required: false
|
||||
RoutersInfo []EntityInfoRequest `url:"-" json:"routers_info,omitempty"`
|
||||
|
||||
// Status
|
||||
// Required: false
|
||||
Status *StatusRequest `url:"-" json:"status,omitempty"`
|
||||
|
||||
// IPv4 subnet in CIDR notation (Either subnet_v4 or subnet_v6 must be specified)
|
||||
// Required: false
|
||||
SubnetV4 string `url:"subnet_v4,omitempty" json:"subnet_v4,omitempty"`
|
||||
|
||||
// IPv6 subnet in CIDR notation (Either subnet_v4 or subnet_v6 must be specified)
|
||||
// Required: false
|
||||
SubnetV6 string `url:"subnet_v6,omitempty" json:"subnet_v6,omitempty"`
|
||||
|
||||
// Updated at
|
||||
// Required: true
|
||||
UpdatedAt time.Time `url:"updated_at" json:"updated_at" validate:"required"`
|
||||
|
||||
// ID of version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
}
|
||||
|
||||
type DHCPv4ConfigRequest struct {
|
||||
// DNS
|
||||
// Required: false
|
||||
DNS []string `url:"dns,omitempty" json:"dns,omitempty"`
|
||||
|
||||
// Excluded address ranges
|
||||
// Required: false
|
||||
ExcludedAddressRanges []string `url:"excluded_address_ranges,omitempty" json:"excluded_address_ranges,omitempty"`
|
||||
|
||||
// Gateway
|
||||
// Required: true
|
||||
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||
|
||||
// ID of config
|
||||
// Required: false
|
||||
ID string `url:"id,omitempty" json:"id,omitempty"`
|
||||
|
||||
// Lease time
|
||||
// Required: false
|
||||
LeaseTime int64 `url:"lease_time,omitempty" json:"lease_time,omitempty"`
|
||||
|
||||
// Server IP
|
||||
// Required: true
|
||||
ServerIP string `url:"server_ip" json:"server_ip" validate:"required"`
|
||||
|
||||
// Server MAC
|
||||
// Required: false
|
||||
ServerMAC string `url:"server_mac,omitempty" json:"server_mac,omitempty"`
|
||||
|
||||
// Whether the config is enabled
|
||||
// Required: true
|
||||
Enabled bool `url:"enabled" json:"enabled"`
|
||||
}
|
||||
|
||||
type DHCPv6ConfigRequest struct {
|
||||
// Address prefix
|
||||
// Required: true
|
||||
AddressPrefix string `url:"address_prefix" json:"address_prefix" validate:"required"`
|
||||
|
||||
// DNS
|
||||
// Required: false
|
||||
DNS []string `url:"dns,omitempty" json:"dns,omitempty"`
|
||||
|
||||
// ID of config
|
||||
// Required: false
|
||||
ID string `url:"id,omitempty" json:"id,omitempty"`
|
||||
|
||||
// Lease time
|
||||
// Required: true
|
||||
LeaseTime int64 `url:"lease_time" json:"lease_time" validate:"required"`
|
||||
|
||||
// Server MAC
|
||||
// Required: true
|
||||
ServerMAC string `url:"server_mac" json:"server_mac" validate:"required"`
|
||||
|
||||
// Whether the config is enabled
|
||||
// Required: true
|
||||
Enabled bool `url:"enabled" json:"enabled"`
|
||||
}
|
||||
|
||||
type EntityInfoRequest struct {
|
||||
// User-friendly name for the entity
|
||||
// Required: true
|
||||
DisplayName string `url:"display_name" json:"display_name" validate:"required"`
|
||||
|
||||
// ID of entity
|
||||
// Required: false
|
||||
ID string `url:"id,omitempty" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
// Create creates extnet
|
||||
func (e ExtNet) Create(ctx context.Context, req CreateRequest) (*ExternalNetworkResponse, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/external_network/create"
|
||||
|
||||
res, err := e.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := ExternalNetworkResponse{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
42
pkg/sdn/extnet/delete.go
Normal file
42
pkg/sdn/extnet/delete.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/constants"
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
// DeleteRequest struct for delete extnet
|
||||
type DeleteRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
ExtNetID string `url:"external_network_id" json:"external_network_id" validate:"required"`
|
||||
|
||||
// ID of version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
|
||||
// Force delete
|
||||
// Required: false
|
||||
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
||||
}
|
||||
|
||||
// Delete delete an external network
|
||||
func (e ExtNet) Delete(ctx context.Context, req DeleteRequest) error {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/external_network/delete"
|
||||
|
||||
_, err = e.client.DecortApiCallCtype(ctx, http.MethodDelete, url, constants.MIMEJSON, req)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
18
pkg/sdn/extnet/extnet.go
Normal file
18
pkg/sdn/extnet/extnet.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// API Actor API for managing SDN external networks
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to external networks
|
||||
type ExtNet struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for external networks endpoints
|
||||
func New(client interfaces.Caller) *ExtNet {
|
||||
return &ExtNet{
|
||||
client,
|
||||
}
|
||||
}
|
||||
60
pkg/sdn/extnet/filter.go
Normal file
60
pkg/sdn/extnet/filter.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package extnet
|
||||
|
||||
// FilterByID returns ListExtNet with specified ID.
|
||||
func (eList ListExtNet) FilterByID(id string) ListExtNet {
|
||||
predicate := func(extNet ExternalNetworkResponse) bool {
|
||||
return extNet.ID == id
|
||||
}
|
||||
|
||||
return eList.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListExtNet with specified Bridge network name.
|
||||
func (eList ListExtNet) FilterByName(name string) ListExtNet {
|
||||
predicate := func(extNet ExternalNetworkResponse) bool {
|
||||
return extNet.BridgeNetworkName == name
|
||||
}
|
||||
|
||||
return eList.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByIPv4 returns ListExtNet with specified default gateway IPv4.
|
||||
func (eList ListExtNet) FilterByIPv4(IPv4 string) ListExtNet {
|
||||
predicate := func(extNet ExternalNetworkResponse) bool {
|
||||
return extNet.DefaultGatewayIPv4 == IPv4
|
||||
}
|
||||
|
||||
return eList.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByIPv6 returns ListExtNet with specified default gateway IPv6.
|
||||
func (eList ListExtNet) FilterByIPv6(IPv6 string) ListExtNet {
|
||||
predicate := func(extNet ExternalNetworkResponse) bool {
|
||||
return extNet.DefaultGatewayIPv6 == IPv6
|
||||
}
|
||||
|
||||
return eList.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListExtNet based on a user-specified predicate.
|
||||
func (eList ListExtNet) FilterFunc(predicate func(response ExternalNetworkResponse) bool) ListExtNet {
|
||||
var result ListExtNet
|
||||
|
||||
for _, item := range eList {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first element.
|
||||
// If none was found, returns an empty struct.
|
||||
func (eList ListExtNet) FindOne() ExternalNetworkResponse {
|
||||
if len(eList) == 0 {
|
||||
return ExternalNetworkResponse{}
|
||||
}
|
||||
|
||||
return eList[0]
|
||||
}
|
||||
149
pkg/sdn/extnet/filter_test.go
Normal file
149
pkg/sdn/extnet/filter_test.go
Normal file
@@ -0,0 +1,149 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var testExtnetList = ListExtNet{
|
||||
{
|
||||
BridgeNetworkName: "br-ext-net-01",
|
||||
DefaultGatewayIPv4: "192.168.1.1",
|
||||
DefaultGatewayIPv6: "2001:db8::1",
|
||||
Description: "test1",
|
||||
Hypervisors: []string{
|
||||
"hv-node-01",
|
||||
},
|
||||
ID: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
||||
VersionID: 1747141621952,
|
||||
SubnetV4: "192.168.1.0/24",
|
||||
SubnetV6: "2001:db8::/64",
|
||||
CreatedAt: time.Date(2025, 10, 21, 20, 34, 30, 641000000, time.UTC),
|
||||
UpdatedAt: time.Date(2025, 10, 21, 20, 34, 30, 641000000, time.UTC),
|
||||
VLANTag: 100,
|
||||
},
|
||||
{
|
||||
BridgeNetworkName: "br-backup-net-02",
|
||||
DefaultGatewayIPv4: "10.0.1.1",
|
||||
DefaultGatewayIPv6: "2001:db8:1::1",
|
||||
Description: "test2",
|
||||
Hypervisors: []string{
|
||||
"hv-node-02",
|
||||
},
|
||||
ID: "b2c3d4e5-f6g7-8901-bcde-f23456789012",
|
||||
VersionID: 1747141621953,
|
||||
SubnetV4: "10.0.1.0/24",
|
||||
SubnetV6: "2001:db8:1::/64",
|
||||
CreatedAt: time.Date(2025, 10, 21, 20, 34, 30, 641000000, time.UTC),
|
||||
UpdatedAt: time.Date(2025, 10, 21, 20, 34, 30, 641000000, time.UTC),
|
||||
VLANTag: 200,
|
||||
},
|
||||
{
|
||||
BridgeNetworkName: "br-test-net-03",
|
||||
DefaultGatewayIPv4: "172.16.1.1",
|
||||
DefaultGatewayIPv6: "2001:db8:2::1",
|
||||
Description: "test3",
|
||||
ExternalNetworkPorts: []ExternalNetworkPort{},
|
||||
Hypervisors: []string{
|
||||
"hv-node-05",
|
||||
"hv-node-06",
|
||||
},
|
||||
ID: "c3d4e5f6-g7h8-9012-cdef-345678901234",
|
||||
VersionID: 1747141621954,
|
||||
SubnetV4: "172.16.1.0/24",
|
||||
SubnetV6: "2001:db8:2::/64",
|
||||
CreatedAt: time.Date(2025, 10, 21, 20, 34, 30, 641000000, time.UTC),
|
||||
UpdatedAt: time.Date(2025, 10, 21, 20, 34, 30, 641000000, time.UTC),
|
||||
VLANTag: 300,
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := testExtnetList.FilterByID("a1b2c3d4-e5f6-7890-abcd-ef1234567890").FindOne()
|
||||
|
||||
if actual.ID != "a1b2c3d4-e5f6-7890-abcd-ef1234567890" {
|
||||
t.Fatal("actual:", actual.ID, "> expected: a1b2c3d4-e5f6-7890-abcd-ef1234567890")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := testExtnetList.FilterByName("br-ext-net-01").FindOne()
|
||||
|
||||
if actual.BridgeNetworkName != "br-ext-net-01" {
|
||||
t.Fatal("actual:", actual.BridgeNetworkName, ">> expected: br-ext-net-01")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByIPv4(t *testing.T) {
|
||||
actual := testExtnetList.FilterByIPv4("192.168.1.1").FindOne()
|
||||
|
||||
if actual.DefaultGatewayIPv4 != "192.168.1.1" {
|
||||
t.Fatal("actual:", actual.DefaultGatewayIPv4, ">> expected: 192.168.1.1")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByIPv6(t *testing.T) {
|
||||
actual := testExtnetList.FilterByIPv6("2001:db8:1::1").FindOne()
|
||||
|
||||
if actual.DefaultGatewayIPv6 != "2001:db8:1::1" {
|
||||
t.Fatal("actual:", actual.DefaultGatewayIPv6, ">> expected: 2001:db8:1::1")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := testExtnetList.FilterFunc(func(response ExternalNetworkResponse) bool {
|
||||
return response.BridgeNetworkName == "br-backup-net-02"
|
||||
})
|
||||
|
||||
if len(actual) != 1 || actual[0].ID != "b2c3d4e5-f6g7-8901-bcde-f23456789012" {
|
||||
t.Fatal("Expected 1 extnet with name 'br-backup-net-02', found:", len(actual))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindOneWithResults(t *testing.T) {
|
||||
result := testExtnetList.FilterByID("c3d4e5f6-g7h8-9012-cdef-345678901234").FindOne()
|
||||
if result.ID != "c3d4e5f6-g7h8-9012-cdef-345678901234" {
|
||||
t.Fatal("Expected c3d4e5f6-g7h8-9012-cdef-345678901234, got:", result.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindOneEmpty(t *testing.T) {
|
||||
emptyList := ListExtNet{}
|
||||
result := emptyList.FindOne()
|
||||
|
||||
if result.ID != "" || result.BridgeNetworkName != "" {
|
||||
t.Fatal("Expected empty extNet, got:", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByIDNotFound(t *testing.T) {
|
||||
actual := ListExtNet{}.FilterByID("nonexistent")
|
||||
|
||||
if len(actual) != 0 {
|
||||
t.Fatal("Expected 0 extNet, found:", len(actual))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByNameNotFound(t *testing.T) {
|
||||
actual := ListExtNet{}.FilterByName("Nonexistent")
|
||||
|
||||
if len(actual) != 0 {
|
||||
t.Fatal("Expected 0 extNet, found:", len(actual))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByIPv4NotFound(t *testing.T) {
|
||||
actual := testExtnetList.FilterByIPv4("nonexistent-ip")
|
||||
|
||||
if len(actual) != 0 {
|
||||
t.Fatal("Expected 0 extNet, found:", len(actual))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByIPv6NotFound(t *testing.T) {
|
||||
actual := testExtnetList.FilterByIPv6("nonexistent-ipv6")
|
||||
|
||||
if len(actual) != 0 {
|
||||
t.Fatal("Expected 0 extNet, found:", len(actual))
|
||||
}
|
||||
}
|
||||
50
pkg/sdn/extnet/get.go
Normal file
50
pkg/sdn/extnet/get.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get information about external network
|
||||
type GetRequest struct {
|
||||
// ID of external network
|
||||
// Required: false
|
||||
ExtNetID string `url:"external_network_id" json:"external_network_id" validate:"required"`
|
||||
|
||||
// ID of access group
|
||||
// Required: false
|
||||
AccessGroupID string `url:"access_group_id,omitempty" json:"access_group_id,omitempty"`
|
||||
}
|
||||
|
||||
// Get gets external network details as a ExternalNetworkResponse struct
|
||||
func (e ExtNet) Get(ctx context.Context, req GetRequest) (*ExternalNetworkResponse, error) {
|
||||
res, err := e.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := ExternalNetworkResponse{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets external network details as an array of bytes
|
||||
func (e ExtNet) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/external_network/get"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
10
pkg/sdn/extnet/ids.go
Normal file
10
pkg/sdn/extnet/ids.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package extnet
|
||||
|
||||
// IDs gets array of IDs from ListExtNet struct
|
||||
func (eList ListExtNet) IDs() []string {
|
||||
res := make([]string, 0, len(eList))
|
||||
for _, item := range eList {
|
||||
res = append(res, item.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
114
pkg/sdn/extnet/list.go
Normal file
114
pkg/sdn/extnet/list.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get a list of external networks
|
||||
type ListRequest struct {
|
||||
// Filter by access group ID
|
||||
// Required: false
|
||||
AccessGroupID string `url:"access_group_id,omitempty" json:"access_group_id,omitempty"`
|
||||
|
||||
// Filter by display name
|
||||
// Required: false
|
||||
DisplayName string `url:"display_name,omitempty" json:"display_name,omitempty"`
|
||||
|
||||
// Filter by IP version (v4 or v6)
|
||||
// Required: false
|
||||
Subnet string `url:"subnet,omitempty" json:"subnet,omitempty" validate:"omitempty,ipTypes"`
|
||||
|
||||
// Filter by IPv4 subnet (CIDR notation)
|
||||
// Required: false
|
||||
SubnetV4 string `url:"subnet_v4,omitempty" json:"subnet_v4,omitempty"`
|
||||
|
||||
// Filter by IPv4 subnet (CIDR notation)
|
||||
// Required: false
|
||||
SubnetV6 string `url:"subnet_v6,omitempty" json:"subnet_v6,omitempty"`
|
||||
|
||||
// Filter by exact bridge network name
|
||||
// Required: false
|
||||
BridgeNetworkName string `url:"bridge_network_name,omitempty" json:"bridge_network_name,omitempty"`
|
||||
|
||||
// Filter by VLAN tag
|
||||
// Required: false
|
||||
VLANTag string `url:"vlan_tag,omitempty" json:"vlan_tag,omitempty"`
|
||||
|
||||
// Filter by IPv4 default gateway
|
||||
// Required: false
|
||||
DefaultGatewayIPv4 string `url:"default_gateway_ipv4,omitempty" json:"default_gateway_ipv4,omitempty"`
|
||||
|
||||
// Filter by IPv6 default gateway
|
||||
// Required: false
|
||||
DefaultGatewayIPv6 string `url:"default_gateway_ipv6,omitempty" json:"default_gateway_ipv6,omitempty"`
|
||||
|
||||
// Filter by enabled status
|
||||
// Required: false
|
||||
Enabled interface{} `url:"enabled,omitempty" json:"enabled,omitempty" validate:"omitempty,isBool"`
|
||||
|
||||
// Filter by update date from
|
||||
// Required: false
|
||||
UpdatedFrom string `url:"updated_from,omitempty" json:"updated_from,omitempty"`
|
||||
|
||||
// Filter lby update date to
|
||||
// Required: false
|
||||
UpdatedTo string `url:"updated_to,omitempty" json:"updated_to,omitempty"`
|
||||
|
||||
// Filter by create date from
|
||||
// Required: false
|
||||
CreatedFrom string `url:"created_from,omitempty" json:"created_from,omitempty"`
|
||||
|
||||
// Filter lby create date to
|
||||
// Required: false
|
||||
CreatedTo string `url:"created_to,omitempty" json:"created_to,omitempty"`
|
||||
|
||||
// Page number for pagination
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Number of results per page
|
||||
// Required: false
|
||||
PerPage uint64 `url:"per_page,omitempty" json:"per_page,omitempty"`
|
||||
|
||||
// Field to sort by (display_name, created_at, updated_at, deleted_at, etc)
|
||||
// Required: false
|
||||
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
|
||||
|
||||
// Sort order (asc/desc)
|
||||
// Required: false
|
||||
SortOrder string `url:"sort_order,omitempty" json:"sort_order,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of all available external networks as a ListExtNet struct
|
||||
func (e ExtNet) List(ctx context.Context, req ListRequest) (ListExtNet, error) {
|
||||
res, err := e.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListExtNet{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of all available external networks as an array of bytes
|
||||
func (e ExtNet) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/external_network/list"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
578
pkg/sdn/extnet/models.go
Normal file
578
pkg/sdn/extnet/models.go
Normal file
@@ -0,0 +1,578 @@
|
||||
package extnet
|
||||
|
||||
import "time"
|
||||
|
||||
// List external networks
|
||||
type ListExtNet []ExternalNetworkResponse
|
||||
|
||||
type ExternalNetworkResponse struct {
|
||||
// Name of the bridge network
|
||||
BridgeNetworkName string `json:"bridge_network_name"`
|
||||
|
||||
// IPv4 default gateway address
|
||||
DefaultGatewayIPv4 string `json:"default_gateway_ipv4"`
|
||||
|
||||
// IPv6 default gateway address
|
||||
DefaultGatewayIPv6 string `json:"default_gateway_ipv6"`
|
||||
|
||||
// Detailed description of the external network
|
||||
Description string `json:"description"`
|
||||
|
||||
// List of external network ports
|
||||
ExternalNetworkPorts []ExternalNetworkPort `json:"external_network_ports"`
|
||||
|
||||
// List of hypervisor names
|
||||
Hypervisors []string `json:"hypervisors"`
|
||||
|
||||
// Extnet ID
|
||||
ID string `json:"id"`
|
||||
|
||||
// Status
|
||||
Status Status `json:"status"`
|
||||
|
||||
// ID of version
|
||||
VersionID uint64 `json:"version_id"`
|
||||
|
||||
// IPv4 subnet in CIDR notation
|
||||
SubnetV4 string `json:"subnet_v4"`
|
||||
|
||||
// IPv6 subnet in CIDR notation
|
||||
SubnetV6 string `json:"subnet_v6"`
|
||||
|
||||
// Creation time
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// Update time
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// VLAN tag identifier
|
||||
VLANTag int64 `json:"vlan_tag"`
|
||||
}
|
||||
|
||||
type ExternalNetworkPort struct {
|
||||
// Access group ID
|
||||
AccessGroupID string `json:"access_group_id"`
|
||||
|
||||
// Access group name
|
||||
AccessGroupName string `json:"access_group_name"`
|
||||
|
||||
// Comment for the external network port
|
||||
Comment string `json:"comment"`
|
||||
|
||||
// User-friendly name for the external network port
|
||||
DisplayName string `json:"display_name"`
|
||||
|
||||
// Whether the network port is enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// IPv4
|
||||
IPv4 string `json:"ipv4"`
|
||||
|
||||
// IPv6
|
||||
IPv6 string `json:"ipv6"`
|
||||
|
||||
// IPv6 Config
|
||||
IPv6Config IPv6Config `json:"ipv6_config"`
|
||||
|
||||
// MAC address
|
||||
MAC string `json:"mac"`
|
||||
|
||||
// Router gateway port
|
||||
RouterGatewayPort RouterGatewayPort `json:"router_gateway_port"`
|
||||
|
||||
// Floating IP
|
||||
FloatingIP FloatingIP `json:"floating_ip"`
|
||||
}
|
||||
|
||||
type IPv6Config struct {
|
||||
// Address mode
|
||||
AddressMode string `json:"address_mode"`
|
||||
|
||||
// If true, the port will periodically send RA packets.
|
||||
EnablePeriodicRa bool `json:"enable_periodic_ra"`
|
||||
|
||||
// The number of waiting seconds between sending periodic RA
|
||||
IntervalRa int64 `json:"interval_ra"`
|
||||
|
||||
// The Default Router Preference (PRF) indicates whether this router should be preferred over other default routers.
|
||||
RouterPreference string `json:"router_preference"`
|
||||
}
|
||||
|
||||
type RouterGatewayPort struct {
|
||||
// Creation time
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// Description
|
||||
Description string `json:"description"`
|
||||
|
||||
// Port ID
|
||||
ID string `json:"id"`
|
||||
|
||||
// User-friendly name for the external network port
|
||||
RouterDisplayName string `json:"router_display_name"`
|
||||
|
||||
// Router ID
|
||||
RouterID string `json:"router_id"`
|
||||
|
||||
// SNAT Enabled
|
||||
SNATEnabled bool `json:"snat_enabled"`
|
||||
|
||||
// Update time
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type FloatingIP struct {
|
||||
// Access group ID
|
||||
AccessGroupID string `json:"access_group_id"`
|
||||
|
||||
// Access group name
|
||||
AccessGroupName string `json:"access_group_name"`
|
||||
|
||||
// Created time
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// External network port
|
||||
ExternalNetworkPort string `json:"external_network_port"`
|
||||
|
||||
// ID of floating IP
|
||||
ID string `json:"id"`
|
||||
|
||||
// Logical Port
|
||||
LogicalPort LogicalPort `json:"logical_port"`
|
||||
|
||||
// Router
|
||||
Router Router `json:"router"`
|
||||
|
||||
// Update time
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// ID of version
|
||||
VersionID uint64 `json:"version_id"`
|
||||
}
|
||||
|
||||
type LogicalPort struct {
|
||||
// Logical Port ID
|
||||
ID string `json:"id"`
|
||||
|
||||
// Access group ID
|
||||
AccessGroupID string `json:"access_group_id"`
|
||||
|
||||
// Access group name
|
||||
AccessGroupName string `json:"access_group_name"`
|
||||
|
||||
// MAC of adapter
|
||||
AdapterMAC string `json:"adapter_mac"`
|
||||
|
||||
// Address detection
|
||||
AddressDetection bool `json:"address_detection"`
|
||||
|
||||
// Description
|
||||
Description string `json:"description"`
|
||||
|
||||
// Created time
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// User-friendly name for router
|
||||
DisplayName string `json:"display_name"`
|
||||
|
||||
// Whether the logical port is enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// External Network ID
|
||||
ExternalNetworkID string `json:"external_network_id"`
|
||||
|
||||
// Hypervisor name
|
||||
Hypervisor string `json:"hypervisor"`
|
||||
|
||||
// User-friendly name for hypervisor
|
||||
HypervisorDisplayName string `json:"hypervisor_display_name"`
|
||||
|
||||
// Live Migration Target Hv
|
||||
LiveMigrationTargetHV string `json:"live_migration_target_hv"`
|
||||
|
||||
// Status
|
||||
Status Status `json:"status"`
|
||||
|
||||
// Bindings struct
|
||||
Bindings PortBindings `json:"bindings"`
|
||||
|
||||
// Unique Identifier
|
||||
UniqueIDentifier string `json:"unique_identifier"`
|
||||
|
||||
// Updated time
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// ID of version
|
||||
VersionID uint64 `json:"version_id"`
|
||||
}
|
||||
|
||||
type PortBindings struct {
|
||||
// Binding ID
|
||||
ID string `json:"id"`
|
||||
|
||||
// User-friendly name for segment
|
||||
SegmentDisplayName string `json:"segment_display_name"`
|
||||
|
||||
// Segment ID
|
||||
SegmentID string `json:"segment_id"`
|
||||
|
||||
// Port security
|
||||
PortSecurity bool `json:"port_security"`
|
||||
|
||||
// Address detection
|
||||
AddressDetection bool `json:"address_detection"`
|
||||
|
||||
// Is Exclude From Firewall
|
||||
IsExcludedFromFirewall bool `json:"is_excluded_from_firewall"`
|
||||
|
||||
// ID of version
|
||||
VersionID uint64 `json:"version_id"`
|
||||
|
||||
// Created time
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// Update time
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// Logical port addresses
|
||||
LogicalPortAddresses []LogicalPortAddress `json:"logical_port_addresses"`
|
||||
}
|
||||
|
||||
type LogicalPortAddress struct {
|
||||
// IP of port
|
||||
IP string `json:"ip"`
|
||||
|
||||
// IP type (IPv4 or IPv6)
|
||||
IPType string `json:"ip_type"`
|
||||
|
||||
// Is discovered
|
||||
IsDiscovered bool `json:"is_discovered"`
|
||||
|
||||
// Is primary
|
||||
IsPrimary bool `json:"is_primary"`
|
||||
|
||||
// MAC
|
||||
MAC string `json:"mac"`
|
||||
|
||||
// ID
|
||||
ID string `json:"id"`
|
||||
|
||||
// Logical port id
|
||||
LogicalPortID string `json:"logical_port_id"`
|
||||
|
||||
// Assigned time
|
||||
AssignedAt time.Time `json:"assigned_at"`
|
||||
}
|
||||
|
||||
type Router struct {
|
||||
// Access group ID
|
||||
AccessGroupID string `json:"access_group_id"`
|
||||
|
||||
// Access group name
|
||||
AccessGroupName string `json:"access_group_name"`
|
||||
|
||||
// Created time
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// Detailed description of the router
|
||||
Description string `json:"description"`
|
||||
|
||||
// User-friendly name for the router
|
||||
DisplayName string `json:"display_name"`
|
||||
|
||||
// Whether the router is enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// Gateway ports
|
||||
GatewayPorts []GatewayPort `json:"gateway_ports"`
|
||||
|
||||
// ID of router
|
||||
ID string `json:"id"`
|
||||
|
||||
// Policies
|
||||
Policies []RouterPolicy `json:"policies"`
|
||||
|
||||
// Ports
|
||||
Ports []RouterPort `json:"ports"`
|
||||
|
||||
// Status
|
||||
Status Status `json:"status"`
|
||||
|
||||
// Update time
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// ID of version
|
||||
VersionID uint64 `json:"version_id"`
|
||||
}
|
||||
|
||||
type GatewayPort struct {
|
||||
// Created time
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// Description
|
||||
Description string `json:"description"`
|
||||
|
||||
// L4 port max
|
||||
ExternalL4PortMax int64 `json:"external_l4_port_max"`
|
||||
|
||||
// L4 port min
|
||||
ExternalL4PortMin int64 `json:"external_l4_port_min"`
|
||||
|
||||
// External network port
|
||||
ExternalNetworkPort interface{} `json:"external_network_port"`
|
||||
|
||||
// ID of port
|
||||
ID string `json:"id"`
|
||||
|
||||
// SNAT Enabled
|
||||
SNATEnabled bool `json:"snat_enabled"`
|
||||
|
||||
// Status
|
||||
Status Status `json:"status"`
|
||||
|
||||
// Update time
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// ID of version
|
||||
VersionID uint64 `json:"version_id"`
|
||||
}
|
||||
|
||||
type RouterPolicy struct {
|
||||
// Action
|
||||
Action string `json:"action"`
|
||||
|
||||
// Created time
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// User-friendly name for the policy
|
||||
DisplayName string `json:"display_name"`
|
||||
|
||||
// Whether the policy is enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// ID of router policy
|
||||
ID string `json:"id"`
|
||||
|
||||
// Match
|
||||
Match interface{} `json:"match"`
|
||||
|
||||
// Next IPv4 address
|
||||
NextIPv4Address []string `json:"next_ipv4_address"`
|
||||
|
||||
// Next IPv6 address
|
||||
NextIPv6Address []string `json:"next_ipv6_address"`
|
||||
|
||||
// Priority number
|
||||
Priority int64 `json:"priority"`
|
||||
|
||||
// Update time
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// ID of version
|
||||
VersionID uint64 `json:"version_id"`
|
||||
}
|
||||
|
||||
type RouterPort struct {
|
||||
// Created at
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// Detailed description of the router port
|
||||
Description string `json:"description"`
|
||||
|
||||
// Whether the router port is enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// ID of router port
|
||||
ID string `json:"id"`
|
||||
|
||||
// Next IPv4 address
|
||||
IPv4Address string `json:"ipv4_address"`
|
||||
|
||||
// Next IPv6 address
|
||||
IPv6Address string `json:"ipv6_address"`
|
||||
|
||||
// IPv6 Config
|
||||
IPv6Config IPv6Config `json:"ipv6_config"`
|
||||
|
||||
// MAC address
|
||||
MAC string `json:"mac"`
|
||||
|
||||
// Segment
|
||||
Segment Segment `json:"segment"`
|
||||
|
||||
// Segment ID
|
||||
SegmentID string `json:"segment_id"`
|
||||
|
||||
// Status
|
||||
Status Status `json:"status"`
|
||||
|
||||
// Update time
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// ID of version
|
||||
VersionID uint64 `json:"version_id"`
|
||||
}
|
||||
|
||||
type Segment struct {
|
||||
// Access group ID
|
||||
AccessGroupID string `json:"access_group_id"`
|
||||
|
||||
// Access group name
|
||||
AccessGroupName string `json:"access_group_name"`
|
||||
|
||||
// Created time
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// Detailed description of the router port
|
||||
Description string `json:"description"`
|
||||
|
||||
// DHCP IPv4
|
||||
DHCPv4 DHCPv4Config `json:"dhcp_v4"`
|
||||
|
||||
// DHCP IPv6
|
||||
DHCPv6 DHCPv6Config `json:"dhcp_v6"`
|
||||
|
||||
// User-friendly name for the segment
|
||||
DisplayName string `json:"display_name"`
|
||||
|
||||
// Whether the segment is enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// ID of segment
|
||||
ID string `json:"id"`
|
||||
|
||||
// Logical ports info
|
||||
LogicalPortsInfo []EntityInfo `json:"logical_ports_info"`
|
||||
|
||||
// Routers info
|
||||
RoutersInfo []EntityInfo `json:"routers_info"`
|
||||
|
||||
// Status
|
||||
Status Status `json:"status"`
|
||||
|
||||
// IPv4 subnet in CIDR notation
|
||||
SubnetV4 string `json:"subnet_v4"`
|
||||
|
||||
// IPv6 subnet in CIDR notation
|
||||
SubnetV6 string `json:"subnet_v6"`
|
||||
|
||||
// Update time
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// ID of version
|
||||
VersionID uint64 `json:"version_id"`
|
||||
}
|
||||
|
||||
type DHCPv4Config struct {
|
||||
// DNS
|
||||
DNS []string `json:"dns"`
|
||||
|
||||
// Excluded address ranges
|
||||
ExcludedAddressRanges []string `json:"excluded_address_ranges"`
|
||||
|
||||
// Gateway
|
||||
Gateway string `json:"gateway"`
|
||||
|
||||
// ID of config
|
||||
ID string `json:"id"`
|
||||
|
||||
// Lease time
|
||||
LeaseTime int64 `json:"lease_time"`
|
||||
|
||||
// Server IP
|
||||
ServerIP string `json:"server_ip"`
|
||||
|
||||
// Server MAC
|
||||
ServerMAC string `json:"server_mac"`
|
||||
|
||||
// Whether the config is enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type DHCPv6Config struct {
|
||||
// Address prefix
|
||||
AddressPrefix string `json:"address_prefix"`
|
||||
|
||||
// DNS
|
||||
DNS []string `json:"dns"`
|
||||
|
||||
// ID of config
|
||||
ID string `json:"id"`
|
||||
|
||||
// Lease time
|
||||
LeaseTime int64 `json:"lease_time"`
|
||||
|
||||
// Server MAC
|
||||
ServerMAC string `json:"server_mac"`
|
||||
|
||||
// Whether the config is enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type EntityInfo struct {
|
||||
// User-friendly name for the entity
|
||||
DisplayName string `json:"display_name"`
|
||||
|
||||
// ID of entity
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type Status struct {
|
||||
// Common
|
||||
Common string `json:"common"`
|
||||
|
||||
// Hypervisors status
|
||||
Hypervisors []HypervisorStatus `json:"hypervisors"`
|
||||
}
|
||||
|
||||
type HypervisorStatus struct {
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Name of hypervisor
|
||||
Name string `json:"name"`
|
||||
|
||||
// User-friendly name for the hypervisor
|
||||
DisplayName string `json:"display_name"`
|
||||
|
||||
// Hypervisor status
|
||||
HypervisorStatus string `json:"hypervisor_status"`
|
||||
|
||||
// Synced time
|
||||
SyncedAt time.Time `json:"synced_at"`
|
||||
}
|
||||
|
||||
type ExternalNetworkAddPortsResponce struct {
|
||||
// ID of extnet port
|
||||
ID string `json:"id"`
|
||||
|
||||
// ID of extnet
|
||||
ExtNetID string `json:"external_network_id"`
|
||||
|
||||
// User-friendly name for the external network port
|
||||
DisplayName string `json:"display_name"`
|
||||
|
||||
// Comment
|
||||
Comment string `json:"comment"`
|
||||
|
||||
// Mac
|
||||
MAC string `json:"mac"`
|
||||
|
||||
// IPv4 gateway address
|
||||
IPv4 string `json:"ipv4"`
|
||||
|
||||
// IPv6 gateway address
|
||||
IPv6 string `json:"ipv6"`
|
||||
|
||||
// IPv6 config
|
||||
IPv6Config IPv6Config `json:"ipv6_config"`
|
||||
|
||||
// Whether the network port is enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// ID of version
|
||||
VersionID uint64 `json:"version_id"`
|
||||
|
||||
// Router gateway port
|
||||
RouterGatewayPort RouterGatewayPort `json:"router_gateway_port"`
|
||||
}
|
||||
77
pkg/sdn/extnet/port_add.go
Normal file
77
pkg/sdn/extnet/port_add.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package extnet
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
85
pkg/sdn/extnet/port_update.go
Normal file
85
pkg/sdn/extnet/port_update.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package extnet
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// PortUpdateRequest struct for update port to extnet
|
||||
type PortUpdateRequest 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"`
|
||||
|
||||
// Port ID
|
||||
// Required: true
|
||||
PortID string `url:"port_id" json:"port_id" validate:"required"`
|
||||
|
||||
// Port version ID
|
||||
// Required: true
|
||||
PortVersionID uint64 `url:"port_version_id" json:"port_version_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"`
|
||||
}
|
||||
|
||||
// UpdatePort updated a port an external network
|
||||
func (e ExtNet) UpdatePort(ctx context.Context, req PortUpdateRequest) (*ExternalNetworkResponse, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/external_network/port_update"
|
||||
|
||||
res, err := e.client.DecortApiCallCtype(ctx, http.MethodPut, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := ExternalNetworkResponse{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
89
pkg/sdn/extnet/update.go
Normal file
89
pkg/sdn/extnet/update.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package extnet
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// UpdateRequest struct for update extnet
|
||||
type UpdateRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
ExtNetID string `url:"external_network_id" json:"external_network_id" validate:"required"`
|
||||
|
||||
// ID of version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
|
||||
// Bridge network name
|
||||
// Required: true
|
||||
BridgeNetworkName string `url:"bridge_network_name" json:"bridge_network_name" validate:"required"`
|
||||
|
||||
// Detailed description of the external network
|
||||
// Required: true
|
||||
Description string `url:"description" json:"description" validate:"required"`
|
||||
|
||||
// User-friendly name for the external network
|
||||
// Required: true
|
||||
DisplayName string `url:"display_name" json:"display_name" validate:"required"`
|
||||
|
||||
// List of hypervisor names
|
||||
// Required: true
|
||||
Hypervisors []string `url:"hypervisors" json:"hypervisors" validate:"required"`
|
||||
|
||||
// Access group ID
|
||||
// Required: false
|
||||
AccessGroupID string `url:"access_group_id,omitempty" json:"access_group_id,omitempty"`
|
||||
|
||||
// IPv4 default gateway address
|
||||
// Required: false
|
||||
DefaultGatewayIPv4 string `url:"default_gateway_ipv4,omitempty" json:"default_gateway_ipv4,omitempty"`
|
||||
|
||||
// IPv6 default gateway address
|
||||
// Required: false
|
||||
DefaultGatewayIPv6 string `url:"default_gateway_ipv6,omitempty" json:"default_gateway_ipv6,omitempty"`
|
||||
|
||||
// Whether the network is enabled
|
||||
// Required: true
|
||||
Enabled bool `url:"enabled" json:"enabled"`
|
||||
|
||||
// IPv4 subnet in CIDR notation (Either subnet_v4 or subnet_v6 must be specified)
|
||||
// Required: false
|
||||
SubnetV4 string `url:"subnet_v4,omitempty" json:"subnet_v4,omitempty"`
|
||||
|
||||
// IPv6 subnet in CIDR notation (Either subnet_v4 or subnet_v6 must be specified)
|
||||
// Required: false
|
||||
SubnetV6 string `url:"subnet_v6,omitempty" json:"subnet_v6,omitempty"`
|
||||
|
||||
// VLAN tag identifier
|
||||
// Required: false
|
||||
VLANTag string `url:"vlan_tag,omitempty" json:"vlan_tag,omitempty" validate:"omitempty,trunkTags"`
|
||||
}
|
||||
|
||||
// Update updated an external network
|
||||
func (e ExtNet) Update(ctx context.Context, req UpdateRequest) (*ExternalNetworkResponse, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/external_network/update"
|
||||
|
||||
res, err := e.client.DecortApiCallCtype(ctx, http.MethodPut, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := ExternalNetworkResponse{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
Reference in New Issue
Block a user