Files
decort-golang-sdk/pkg/cloudapi/compute/net_attach.go

88 lines
2.6 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package compute
import (
"context"
"encoding/json"
"net/http"
2023-03-17 12:54:34 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-10-03 16:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// NetAttachRequest struct to attach network
2022-10-03 16:56:47 +03:00
type NetAttachRequest struct {
2022-12-22 17:56:47 +03:00
// ID of compute instance
// Required: true
2023-03-17 12:54:34 +03:00
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
2022-12-22 17:56:47 +03:00
// Network type
// 'EXTNET' for connect to external network directly
2024-05-31 13:35:39 +03:00
// 'VINS' for connect to ViNS
// 'VFNIC' for connect to vfpool
2024-11-12 12:51:21 +03:00
// 'DPDK' for connect to DPDK
2025-07-15 17:39:18 +03:00
// `EMPTY` for connect empty network
// `SDT` for connect to SDN
// `TRUNK` for connect to TRUNK
2022-12-22 17:56:47 +03:00
// Required: true
2024-05-31 13:35:39 +03:00
NetType string `url:"netType" json:"netType" validate:"computex86NetType"`
2022-12-22 17:56:47 +03:00
// Network ID for connect to
// For EXTNET - external network ID
// For VINS - VINS ID
// Required: true
2023-03-17 12:54:34 +03:00
NetID uint64 `url:"netId" json:"netId" validate:"required"`
2022-12-22 17:56:47 +03:00
// Directly required IP address for new network interface
2023-03-17 12:54:34 +03:00
// Required: false
2023-03-01 19:05:53 +03:00
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
2024-11-12 12:51:21 +03:00
2025-04-09 11:21:07 +03:00
// MAC address
// Required: false
MACAddr string `url:"mac_addr,omitempty" json:"mac_addr,omitempty"`
2025-07-15 17:39:18 +03:00
// Used only for EXTNET and DPDK
// For DPDK must be 1-9216
// For EXTNET must be 1500-9216
2025-08-29 12:51:25 +03:00
// Required: false
2024-11-12 12:51:21 +03:00
MTU uint64 `url:"mtu,omitempty" json:"mtu,omitempty" validate:"omitempty,mtu"`
2025-07-15 17:39:18 +03:00
// Unique identifier of logical port on SDN side
// Required: false
SDNInterfaceID string `url:"sdn_interface_id,omitempty" json:"sdn_interface_id,omitempty" validate:"omitempty"`
2025-08-29 12:51:25 +03:00
// List of security group IDs to assign to this interface
// Required: false
SecGroups []uint64 `url:"security_groups,omitempty" json:"security_groups,omitempty"`
// Flag indicating whether security groups are enabled for this interface
// Required: false
EnableSecGroups bool `url:"enable_secgroups,omitempty" json:"enable_secgroups,omitempty"`
// Flag indicating whether this interface is enabled (only for VINS, EXTNET, DPDK, SDN, TRUNK)
// Required: false
Enabled interface{} `url:"enabled,omitempty" json:"enabled,omitempty" validate:"omitempty,isBool"`
2022-10-03 16:56:47 +03:00
}
2023-10-25 17:37:18 +03:00
// NetAttach attaches network to compute and gets info about network
2022-12-22 17:56:47 +03:00
func (c Compute) NetAttach(ctx context.Context, req NetAttachRequest) (*RecordNetAttach, error) {
2023-03-17 12:54:34 +03:00
err := validators.ValidateRequest(req)
2022-10-03 16:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return nil, validators.ValidationErrors(validators.GetErrors(err))
2022-10-03 16:56:47 +03:00
}
url := "/cloudapi/compute/netAttach"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
2022-12-22 17:56:47 +03:00
info := RecordNetAttach{}
err = json.Unmarshal(res, &info)
2022-10-03 16:56:47 +03:00
if err != nil {
return nil, err
}
2022-12-22 17:56:47 +03:00
return &info, nil
2022-10-03 16:56:47 +03:00
}