This commit is contained in:
2024-11-12 12:51:21 +03:00
parent f1e0f7abb6
commit 80491ed643
226 changed files with 3033 additions and 2633 deletions

View File

@@ -0,0 +1,62 @@
package dpdknet
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CreateRequest struct to create DPDK network
type CreateRequest struct {
// Name of new DPDK network
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Description of new DPDK network. Prefer to contain additional information about DPDK network.
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
// ID of the grid (platform)
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
// ID of vlan
// Required: true
VlanID uint64 `url:"vlanId" json:"vlanId" validate:"required"`
// Name of OVS Bridge to use for creating DPDK network on
// Required: true
OVSBridge string `url:"ovsBridge" json:"ovsBridge" validate:"required"`
// List of account IDs to which DPDK network will be available. Empty field means all accounts in the system.
// Required: false
AccountAccess []uint64 `url:"accountAccess,omitempty" json:"accountAccess,omitempty"`
// List of resource groups IDs to which DPDK network will be available. Empty field means all resource groups in the system.
// Required: false
RGAccess []uint64 `url:"rgAccess,omitempty" json:"rgAccess,omitempty"`
}
// Create creates a DPDK networks
func (d DPDKNet) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/dpdknet/create"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -0,0 +1,38 @@
package dpdknet
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DeleteRequest struct to delete DPDK network
type DeleteRequest struct {
// ID of DPDK network to delete
// Required: true
DPDKID uint64 `url:"dpdkId" json:"dpdkId" validate:"required"`
}
// Delete deletes DPDK network by ID
func (d DPDKNet) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/dpdknet/delete"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,39 @@
package dpdknet
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DisableRequest struct to disable DPDK network
// Computes will not be able to use it until it is enabled again.
type DisableRequest struct {
// ID of DPDK network to disable
// Required: true
DPDKID uint64 `url:"dpdkId" json:"dpdkId" validate:"required"`
}
// Disable disables DPDK network by ID
func (d DPDKNet) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/dpdknet/disable"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,15 @@
package dpdknet
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to DPDK network
type DPDKNet struct {
client interfaces.Caller
}
// Builder for dpdk endpoints
func New(client interfaces.Caller) *DPDKNet {
return &DPDKNet{
client,
}
}

View File

@@ -0,0 +1,38 @@
package dpdknet
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// EnableRequest struct to enable DPDK network
type EnableRequest struct {
// ID of DPDK network to enable
// Required: true
DPDKID uint64 `url:"dpdkId" json:"dpdkId" validate:"required"`
}
// Enable enables DPDK network by ID
func (d DPDKNet) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/dpdknet/enable"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,46 @@
package dpdknet
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetRequest struct to get information about DPDK network
type GetRequest struct {
// ID of the DPDK network
// Required: true
DPDKID uint64 `url:"dpdkId" json:"dpdkId" validate:"required"`
}
// Get DPDK network details as a RecordDPDKNet struct
func (d DPDKNet) Get(ctx context.Context, req GetRequest) (*RecordDPDKNet, error) {
res, err := d.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordDPDKNet{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets DPDK network details as an array of bytes
func (d DPDKNet) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/dpdknet/get"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,91 @@
package dpdknet
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListRequest struct to get list of DPDK networks
type ListRequest struct {
// Find by id
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by gid
// Required: false
GID uint64 `url:"gid,omitempty" json:"gid,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by description
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by account access
// Required: false
AccountAccess []uint64 `url:"accountAccess,omitempty" json:"accountAccess,omitempty"`
// Find by resource group access
// Required: false
RGAccess []uint64 `url:"rgAccess,omitempty" json:"rgAccess,omitempty"`
// Find by vlan ID
// Required: false
VlanID uint64 `url:"vlanId,omitempty" json:"vlanId,omitempty"`
// Find by computeIDs
// Required: false
ComputeIDs []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of the created DPDK networks belonging to an account as a ListDPDKNet struct
func (d DPDKNet) List(ctx context.Context, req ListRequest) (*ListDPDKNet, error) {
res, err := d.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListDPDKNet{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of the created DPDK networks belonging to an account as an array of bytes
func (d DPDKNet) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/dpdknet/list"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,92 @@
package dpdknet
// Detailed information about DPDK network
type RecordDPDKNet struct {
// List of accounts with access
AccountAccess []uint64 `json:"accountAccess"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// Description
Description string `json:"description"`
// Grid ID
GID uint64 `json:"gid"`
// Guid ID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// List of resource groups with access
RGAccess []uint64 `json:"rgAccess"`
// Status
Status string `json:"status"`
// OVS bridge
OVSBridge string `json:"ovsBridge"`
// Vlan ID
VlanID uint64 `json:"vlanId"`
// Compute IDs
ComputeIDs []uint64 `json:"computeIds"`
}
type ListDPDKNet struct {
// Data
Data []ItemDPDKNet `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
type ItemDPDKNet struct {
// List of accounts with access
AccountAccess []uint64 `json:"accountAccess"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// Description
Description string `json:"description"`
// Grid ID
GID uint64 `json:"gid"`
// Guid ID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// List of resource groups with access
RGAccess []uint64 `json:"rgAccess"`
// Status
Status string `json:"status"`
// OVS bridge
OVSBridge string `json:"ovsBridge"`
// Vlan ID
VlanID uint64 `json:"vlanId"`
// Compute IDs
ComputeIDs []uint64 `json:"computeIds"`
}

View File

@@ -0,0 +1,62 @@
package dpdknet
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// UpdateRequest struct to update DPDK network
type UpdateRequest struct {
// ID of DPDK network to update
// Required: true
DPDKID uint64 `url:"dpdkId" json:"dpdkId" validate:"required"`
// New name of DPDK network
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Description of DPDK network. Prefer to contain additional information about DPDK network
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
// List of account IDs to which DPDK network will be available. Empty field means all accounts in the system.
// Required: false
AccountAccess []uint64 `url:"accountAccess,omitempty" json:"accountAccess,omitempty"`
// List of resource groups IDs to which DPDK network will be available. Empty field means all resource groups in the system.
// Required: true
RGAccess []uint64 `url:"rgAccess,omitempty" json:"rgAccess,omitempty"`
// ID of vlan
// Required: true
VlanID uint64 `url:"vlanId,omitempty" json:"vlanId,omitempty"`
// Name of OVS Bridge to use for DPDK network
// Required: true
OVSBridge string `url:"ovsBridge,omitempty" json:"ovsBridge,omitempty"`
}
// Update updates a DPDK networks
func (d DPDKNet) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/dpdknet/update"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}