This commit is contained in:
dayterr
2026-04-17 17:04:11 +03:00
parent 5cdae8520f
commit 2bd93e92c2
23 changed files with 758 additions and 118 deletions

View File

@@ -42,6 +42,10 @@ type CreateRequest struct {
// DHCP IPv6
// Required: false
DHCPv6 *DHCPv6ConfigRequest `url:"-" json:"dhcp_v6,omitempty"`
// Segment type
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
}
type DHCPv4ConfigRequest struct {

View File

@@ -0,0 +1,46 @@
package segments
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetFAARequest struct to get the floating/anycast IP address of a segment
type GetFAARequest struct {
// ID of segment
// Required: true
SegmentID string `url:"segment_id" json:"segment_id" validate:"required"`
}
// GetFAA gets the floating/anycast IP address info for a segment
func (s Segments) GetFAA(ctx context.Context, req GetFAARequest) (*GetFAAResponse, error) {
res, err := s.GetFAARaw(ctx, req)
if err != nil {
return nil, err
}
info := GetFAAResponse{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetFAARaw gets the floating/anycast IP address info for a segment as an array of bytes
func (s Segments) GetFAARaw(ctx context.Context, req GetFAARequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/sdn/segment/get_faa"
res, err := s.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -1,51 +0,0 @@
package segments
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetStatusRequest struct to get information about segment status
type GetStatusRequest struct {
// ID of segment
// Required: true
SegmentID string `url:"segment_id" json:"segment_id" validate:"required"`
// ID of version
// Required: false
VersionID uint64 `url:"version_id,omitempty" json:"version_id,omitempty"`
// Get detailed status or not
// Required: false
Detailed interface{} `url:"enabled,omitempty" json:"enabled,omitempty" validate:"omitempty,isBool"`
}
// GetStatus gets segment status
func (s Segments) GetStatus(ctx context.Context, req GetStatusRequest) (string, error) {
type temp struct {
Status string `json:"status"`
}
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/sdn/segment/get_status"
res, err := s.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return "", err
}
info := temp{}
err = json.Unmarshal(res, &info)
if err != nil {
return "", err
}
return info.Status, nil
}

View File

@@ -59,6 +59,10 @@ type ListRequest struct {
// Sort order (asc/desc)
// Required: false
SortOrder string `url:"sort_order,omitempty" json:"sort_order,omitempty"`
// Filter by operation status
// Required: false
OperationStatus string `url:"operation_status,omitempty" json:"operation_status,omitempty"`
}
// List gets list of all available segments as a ListSegment struct

View File

@@ -16,7 +16,7 @@ type SegmentResponse struct {
// Created time
CreatedAt time.Time `json:"created_at"`
// Detailed description of the router port
// Detailed description of the segment
Description string `json:"description"`
// DHCP IPv4
@@ -34,6 +34,9 @@ type SegmentResponse struct {
// ID of segment
ID string `json:"id"`
// L2 connection port info
L2ConnectionPort *L2ConnectionPort `json:"l2_connection_port,omitempty"`
// Logical ports info
LogicalPortsInfo []EntityInfo `json:"logical_ports_info"`
@@ -49,6 +52,9 @@ type SegmentResponse struct {
// IPv6 subnet in CIDR notation
SubnetV6 string `json:"subnet_v6"`
// Segment type
Type string `json:"type"`
// Update time
UpdatedAt time.Time `json:"updated_at"`
@@ -111,16 +117,16 @@ type EntityInfo struct {
}
type Status struct {
// Common
Common string `json:"common"`
// Operation status
OperationStatus string `json:"operation_status"`
// Hypervisors status
Hypervisors []HypervisorStatus `json:"hypervisors"`
}
type HypervisorStatus struct {
// Status
Status string `json:"status"`
// Operation status of the hypervisor
OperationStatus string `json:"operation_status"`
// Name of hypervisor
Name string `json:"name"`
@@ -134,3 +140,75 @@ type HypervisorStatus struct {
// Synced time
SyncedAt time.Time `json:"synced_at"`
}
// L2ConnectionPort holds information about the L2 connection port of a segment
type L2ConnectionPort struct {
// ID of the L2 connection port
ID string `json:"id"`
// Access group ID
AccessGroupID string `json:"access_group_id"`
// ID of version
VersionID uint64 `json:"version_id"`
// L2 external network details
L2ExternalNetwork L2ExternalNetwork `json:"l2_external_network"`
// Created time
CreatedAt time.Time `json:"created_at"`
// ID of the user who created the port
CreatedBy string `json:"created_by"`
// Updated time
UpdatedAt time.Time `json:"updated_at"`
// ID of the user who last updated the port
UpdatedBy string `json:"updated_by"`
}
// L2ExternalNetwork holds information about an L2 external network
type L2ExternalNetwork struct {
// ID of the network
ID string `json:"id"`
// User-friendly name for the network
DisplayName string `json:"display_name"`
// Detailed description of the network
Description string `json:"description"`
// Bridge network name
BridgeNetworkName string `json:"bridge_network_name"`
// List of hypervisor IDs attached to the network
Hypervisors []string `json:"hypervisors"`
// VLAN tag
VLANTag uint64 `json:"vlan_tag"`
// ID of version
VersionID uint64 `json:"version_id"`
// Created time
CreatedAt time.Time `json:"created_at"`
// ID of the user who created the network
CreatedBy string `json:"created_by"`
// Updated time
UpdatedAt time.Time `json:"updated_at"`
// ID of the user who last updated the network
UpdatedBy string `json:"updated_by"`
}
// GetFAAResponse holds the floating/anycast IP address info for a segment
type GetFAAResponse struct {
// IPv4 address
IPv4Address string `json:"ipv4_address"`
// IPv6 address
IPv6Address string `json:"ipv6_address"`
}

View File

@@ -50,6 +50,10 @@ type UpdateRequest struct {
// DHCP IPv6
// Required: false
DHCPv6 *DHCPv6ConfigRequest `url:"-" json:"dhcp_v6,omitempty"`
// Segment type
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
}
// Update updates segment