This commit is contained in:
2026-06-05 17:14:39 +03:00
parent e9adcfec1c
commit fea00bbb42
157 changed files with 4837 additions and 251 deletions

View File

@@ -0,0 +1,46 @@
package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetNetworkInfoRequest struct to get network information of a node
type GetNetworkInfoRequest struct {
// Node ID
// Required: true
NodeID uint64 `url:"node_id" json:"node_id" validate:"required"`
}
// GetNetworkInfo gets network information of a node as a RecordNodeNetworkInfo struct
func (n Node) GetNetworkInfo(ctx context.Context, req GetNetworkInfoRequest) (*RecordNodeNetworkInfo, error) {
res, err := n.GetNetworkInfoRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordNodeNetworkInfo{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetNetworkInfoRaw gets network information of a node as an array of bytes
func (n Node) GetNetworkInfoRaw(ctx context.Context, req GetNetworkInfoRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/get_network_info"
res, err := n.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,62 @@
package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetPCIDevicesRequest struct to get list of PCI devices on a node
type GetPCIDevicesRequest struct {
// Node ID
// Required: true
NodeID uint64 `url:"nid" json:"nid" validate:"required"`
// Search string
// Required: false
Search string `url:"search,omitempty" json:"search,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sort_by,omitempty" json:"sort_by,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"`
}
// GetPCIDevices gets list of PCI devices on a node as a ListPCIDevices struct
func (n Node) GetPCIDevices(ctx context.Context, req GetPCIDevicesRequest) (*ListPCIDevices, error) {
res, err := n.GetPCIDevicesRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListPCIDevices{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// GetPCIDevicesRaw gets list of PCI devices on a node as an array of bytes
func (n Node) GetPCIDevicesRaw(ctx context.Context, req GetPCIDevicesRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/get_pci_devices"
res, err := n.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -9,7 +9,7 @@ type RecordNode struct {
CpuInfo CpuInfo `json:"cpuInfo"`
// CPU Allocation Ratio
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
CPUAllocationRatio uint64 `json:"cpu_allocation_ratio"`
// DPDK info
DPDK DPDK `json:"dpdk"`
@@ -27,7 +27,7 @@ type RecordNode struct {
IsolatedCpus []interface{} `json:"isolatedCpus"`
// MemAllocationRatio
MemAllocationRatio float64 `json:"mem_allocation_ratio"`
MemAllocationRatio uint64 `json:"mem_allocation_ratio"`
// Name
Name string `json:"name"`
@@ -120,7 +120,7 @@ type FreeResourcesInfo struct {
RAM float64 `json:"RAM"`
// VCPU
VCPU float64 `json:"vCPUs"`
VCPU uint64 `json:"vCPUs"`
}
// Resources Info
@@ -303,10 +303,10 @@ type ItemNode struct {
OldCompatLVMID uint64 `json:"old_compat_lvm_id"`
// CPU Allocation ratio
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
CPUAllocationRatio uint64 `json:"cpu_allocation_ratio"`
// MemAllocationRatio
MemAllocationRatio float64 `json:"mem_allocation_ratio"`
MemAllocationRatio uint64 `json:"mem_allocation_ratio"`
// Packages
Packages map[string]PackageInfo `json:"packages"`
@@ -319,6 +319,9 @@ type ItemNode struct {
// AutoStart Count
AutoStartCount uint64 `json:"autostart_count"`
// PCI devices attached to the node
PCIDevices []ItemPCIDevice `json:"pci_devices"`
}
type PackageInfo struct {
@@ -350,9 +353,36 @@ type ItemMemory struct {
// 1G
OneG uint64 `json:"1G"`
// 1G available
OneGAvailable uint64 `json:"1G_available"`
// 1G free
OneGFree uint64 `json:"1G_free"`
// 1G reserved
OneGReserved uint64 `json:"1G_reserved"`
// 1G used
OneGUsed uint64 `json:"1G_used"`
// 1G DPDK reserved
OneGDPDKReserved uint64 `json:"1G_dpdk_reserved"`
// 2M
TwoM uint64 `json:"2M"`
// 2M available
TwoMAvailable uint64 `json:"2M_available"`
// 2M free
TwoMFree uint64 `json:"2M_free"`
// 2M reserved
TwoMReserved uint64 `json:"2M_reserved"`
// 2M used
TwoMUsed uint64 `json:"2M_used"`
// Total
Total uint64 `json:"total"`
}
@@ -454,6 +484,54 @@ type Role struct {
Time uint64 `json:"time"`
}
// PCI device info
type ItemPCIDevice struct {
// Hardware path
HWPath string `json:"hw_path"`
// Current driver
CurrentDriver string `json:"current_driver"`
// NUMA node
NUMANode uint64 `json:"numa_node"`
// Product ID
ProductID string `json:"product_id"`
// Product name
ProductName string `json:"product_name"`
// Vendor ID
VendorID string `json:"vendor_id"`
// Vendor name
VendorName string `json:"vendor_name"`
// IOMMU group
IOMMUGroup uint64 `json:"iommu_group"`
}
// List of PCI devices
type ListPCIDevices struct {
// Data
Data []ItemPCIDevice `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Response for PCI device driver binding actions
type RecordPCIDeviceDriver struct {
// Success
Success bool `json:"success"`
// Message
Message string `json:"message"`
// Result
Result interface{} `json:"result"`
}
// Information about SSH Identity
type SSHIdentity struct {
//Host name of the client
@@ -465,3 +543,231 @@ type SSHIdentity struct {
//Array of SSH public keys of the client
PublicKeys []string `json:"public_keys"`
}
// Full network configuration of a node
type RecordNodeNetworkInfo struct {
// System-level information about all network interfaces on the node
SystemNetworksInfo map[string]SystemNetworkInfo `json:"system_networks_info"`
// Raw OVS ports data
OVSNetworksInfo []OVSNetworkInfo `json:"ovs_networks_info"`
// VM network interface connections
LibvirtNetworksInfo []LibvirtNetworkInfo `json:"libvirt_networks_info"`
// Assembled network topology of the node
Topology NetworkTopology `json:"topology"`
}
// System network interface
type SystemNetworkInfo struct {
// MTU value
MTU uint64 `json:"mtu"`
// Interface link speed
Speed int64 `json:"speed"`
// Linux bridge ID
BridgeID string `json:"bridge_id"`
// Bridge port ID
BPortID string `json:"bport_id"`
// MAC address
MAC string `json:"mac"`
}
// OVS port information
type OVSNetworkInfo struct {
// Bridge name
BridgeName string `json:"bridge_name"`
// Bridge tag
BridgeTag string `json:"bridge_tag"`
// Interface UUID
InterfaceUUID string `json:"interface_uuid"`
// Interface type
InterfaceType string `json:"interface_type"`
// Interface name
InterfaceName string `json:"interface_name"`
// Interface MTU value
InterfaceMTU uint64 `json:"interface_mtu"`
// Interface IP address
InterfaceIP string `json:"interface_ip"`
// Interface MAC address
InterfaceMAC string `json:"interface_mac"`
// Interface peer name
InterfacePeer string `json:"interface_peer"`
}
// VM network interface connection
type LibvirtNetworkInfo struct {
// VM name
VMName string `json:"vm_name"`
// Host-side interface name used by the VM
Interface string `json:"interface"`
// Interface type
InterfaceType string `json:"interface_type"`
// Name of the bridge the VM interface is attached to
InterfaceSource string `json:"interface_source"`
}
// Assembled network topology of the node
type NetworkTopology struct {
// Map of all network interfaces by name with their topology details and connections
Interfaces map[string]TopologyInterface `json:"interfaces"`
}
// Interface and its role in the network topology
type TopologyInterface struct {
// Interface type
Type string `json:"type"`
// Interface MTU value
MTU uint64 `json:"mtu"`
// Interface link speed
Speed int64 `json:"speed"`
// Connections to VMs and to bridges
Connections TopologyInterfaceConnections `json:"connections"`
// VLANs associated with the interface
VLANs []string `json:"vlans"`
// Linux bridge ID
BridgeID string `json:"bridge_id"`
// Port configuration of this bridge
BridgeInfo *TopologyBridgeInfo `json:"bridge_info"`
// Peer bridges connected to this bridge via patch ports
BridgeConnections []TopologyBridgeRef `json:"bridge_connections"`
// Names of interfaces attached to this bridge as ports
ConnectedInterfaces []string `json:"connected_interfaces"`
// Peer interface name
Peer string `json:"peer"`
// OVS UUID
UUID string `json:"uuid"`
}
// Lists what is connected to this interface
type TopologyInterfaceConnections struct {
// VMs connected to this interface
VMs []TopologyVMConnection `json:"vms"`
// Bridges this interface is attached to
Bridges []TopologyBridgeAttachment `json:"bridges"`
}
// VM connected to a bridge or interface
type TopologyVMConnection struct {
// VM name
Name string `json:"name"`
// Host-side interface name
VMInterface string `json:"vm_interface"`
// VM interface type
VMInterfaceType string `json:"vm_interface_type"`
// Connection type
ConnectionType string `json:"connection_type"`
// Via bridge
ViaBridge string `json:"via_bridge"`
}
// How interface is attached to a bridge
type TopologyBridgeAttachment struct {
// Bridge name
Name string `json:"name"`
// Bridge type
Type string `json:"type"`
// Attachment method
Via string `json:"via"`
// Port details
PortInfo *TopologyPortInfo `json:"port_info"`
// Linux bridge port ID
BPortID string `json:"bport_id"`
}
// Bridge port entry
type TopologyPortInfo struct {
// Port name
Name string `json:"name"`
// Port type
Type string `json:"type"`
// MTU value
MTU uint64 `json:"mtu"`
// VLAN tag
VLAN string `json:"vlan"`
// OVS UUID of the port
UUID string `json:"uuid"`
}
// OVS bridge port configuration
type TopologyBridgeInfo struct {
// Bridge type
Type string `json:"type"`
// List of ports on this bridge
Ports []TopologyBridgePort `json:"ports"`
}
// Port on an OVS bridge
type TopologyBridgePort struct {
// Port name
Name string `json:"name"`
// Port type
Type string `json:"type"`
// MTU value
MTU uint64 `json:"mtu"`
// VLAN tag
VLAN string `json:"vlan"`
// UUID
UUID string `json:"uuid"`
// IP address
IP string `json:"ip"`
// MAC address
MAC string `json:"mac"`
}
// Peer bridge connected via a patch port
type TopologyBridgeRef struct {
// Name of the peer bridge
Name string `json:"name"`
// Name of the patch port used to connect to the peer bridge
Via string `json:"via"`
// VLAN tag on the patch connection
VLAN string `json:"vlan"`
}

View File

@@ -0,0 +1,45 @@
package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// PCIDeviceDriverToKernelRequest struct to bind PCI device driver to kernel
type PCIDeviceDriverToKernelRequest struct {
// Node ID
// Required: true
NodeID uint64 `url:"nid" json:"nid" validate:"required"`
// Hardware path of the PCI device, e.g. 0000:81:00.0
// Required: true
HWPath string `url:"hw_path" json:"hw_path" validate:"required,pciDeviceHWPath"`
}
// PCIDeviceDriverToKernel binds PCI device driver to kernel
func (n Node) PCIDeviceDriverToKernel(ctx context.Context, req PCIDeviceDriverToKernelRequest) (*RecordPCIDeviceDriver, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/pci_device_driver_to_kernel"
res, err := n.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return nil, err
}
result := RecordPCIDeviceDriver{}
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return &result, nil
}

View File

@@ -0,0 +1,50 @@
package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// PCIDeviceDriverToVFIORequest struct to bind PCI device driver to VFIO
type PCIDeviceDriverToVFIORequest struct {
// Node ID
// Required: true
NodeID uint64 `url:"nid" json:"nid" validate:"required"`
// Hardware path of the PCI device, e.g. 0000:81:00.0
// Required: true
HWPath string `url:"hw_path" json:"hw_path" validate:"required,pciDeviceHWPath"`
// Driver binding mode
// Required: true
// Possible values: safe, unsafe
Mode string `url:"mode" json:"mode" validate:"required,oneof=safe unsafe"`
}
// PCIDeviceDriverToVFIO binds PCI device driver to VFIO
func (n Node) PCIDeviceDriverToVFIO(ctx context.Context, req PCIDeviceDriverToVFIORequest) (*RecordPCIDeviceDriver, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/pci_device_driver_to_vfio"
res, err := n.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return nil, err
}
result := RecordPCIDeviceDriver{}
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return &result, nil
}

View File

@@ -2,6 +2,7 @@ package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
@@ -15,22 +16,29 @@ type SetCpuAllocationRatioRequest struct {
// Allocation ratio (zero or positive value)
// Required: true
Ratio float64 `url:"ratio" json:"ratio" validate:"required"`
Ratio uint64 `url:"ratio" json:"ratio" validate:"required"`
}
// SetCpuAllocationRatio set CPU allocation ratio
func (i Node) SetCpuAllocationRatio(ctx context.Context, req SetCpuAllocationRatioRequest) error {
func (i Node) SetCpuAllocationRatio(ctx context.Context, req SetCpuAllocationRatioRequest) (*ItemNode, error) {
err := validators.ValidateRequest(req)
if err != nil {
return validators.ValidationErrors(validators.GetErrors(err))
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/set_cpu_allocation_ratio"
_, err = i.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return err
return nil, err
}
return nil
info := ItemNode{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -2,6 +2,7 @@ package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
@@ -15,22 +16,29 @@ type SetMemAllocationRatioRequest struct {
// Allocation ratio (zero or positive value)
// Required: true
Ratio float64 `url:"ratio" json:"ratio" validate:"required"`
Ratio uint64 `url:"ratio" json:"ratio" validate:"required"`
}
// SetMemAllocationRatio set memory allocation ratio
func (i Node) SetMemAllocationRatio(ctx context.Context, req SetMemAllocationRatioRequest) error {
func (i Node) SetMemAllocationRatio(ctx context.Context, req SetMemAllocationRatioRequest) (*ItemNode, error) {
err := validators.ValidateRequest(req)
if err != nil {
return validators.ValidationErrors(validators.GetErrors(err))
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/set_mem_allocation_ratio"
_, err = i.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return err
return nil, err
}
return nil
info := ItemNode{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}