This commit is contained in:
asteam
2025-09-27 01:06:15 +03:00
parent 1ccc37a104
commit cf584c8123
1175 changed files with 11022 additions and 1832 deletions

46
pkg/cloudapi/trunk/get.go Normal file
View File

@@ -0,0 +1,46 @@
package trunk
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
)
// GetRequest struct to get information about a trunk
type GetRequest struct {
// ID of trunk
// Required: true
TrunkID uint64 `url:"id" json:"id" validate:"required"`
}
// Get gets detailed information about a trunk as a ItemTrunk struct
func (t Trunk) Get(ctx context.Context, req GetRequest) (*ItemTrunk, error) {
res, err := t.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := ItemTrunk{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets detailed information about a trunk as an array of bytes
func (t Trunk) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/trunk/get"
res, err := t.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,64 @@
package trunk
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
)
// ListRequest struct to get list of trunks
type ListRequest struct {
// Account access ID to filter by
AccountIDs []uint64 `url:"account_ids,omitempty" json:"account_ids,omitempty"`
// ID of the trunk to filter by
IDs []uint64 `url:"ids,omitempty" json:"ids,omitempty"`
// Sort by one of supported fields, format ±<field>
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
// Trunk tags to filter by
TrunkTags string `url:"trunk_tags,omitempty" json:"trunk_tags,omitempty" validate:"omitempty,trunkTags"`
// Page number
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Status
Status string `url:"status,omitempty" json:"status,omitempty"`
}
// List gets list of all trunks as a ListTrunks struct
func (t Trunk) List(ctx context.Context, req ListRequest) (*ListTrunks, error) {
res, err := t.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListTrunks{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of all trunks as an array of bytes
func (t Trunk) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/trunk/list"
res, err := t.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,59 @@
package trunk
type ItemTrunk struct {
// List of account IDs with access to this trunk
AccountIDs []uint64 `json:"accountIds"`
// Created at
CreatedAt uint64 `json:"created_at"`
// Created by
CreatedBy string `json:"created_by"`
// Deleted at
DeletedAt uint64 `json:"deleted_at"`
// Deleted by
DeletedBy string `json:"deleted_by"`
// Description of a trunk
Description string `json:"description"`
// GUID
GUID uint64 `json:"guid"`
// ID of a trunk
ID uint64 `json:"id"`
// MAC
MAC string `json:"mac"`
// Name of a trunk
Name string `json:"name"`
// Native VLAN ID
NativeVLANID uint64 `json:"nativeVlanId"`
// OVS bridge name
OVSBridge string `json:"ovsBridge"`
// If the trunk is enabled
Status string `json:"status"`
// List of trunk tags (values between 1-4095)
TrunkTags string `json:"trunkTags"`
// Updated at
UpdatedAt uint64 `json:"updated_at"`
// Updated by
UpdatedBy string `json:"updated_by"`
}
// List of trunks
type ListTrunks struct {
Data []ItemTrunk `json:"data"`
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -0,0 +1,18 @@
// API Actor API for trunk nerworks
package trunk
import (
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/interfaces"
)
// Structure for creating request to trunk
type Trunk struct {
client interfaces.Caller
}
// Builder for trunk endpoints
func New(client interfaces.Caller) *Trunk {
return &Trunk{
client,
}
}