This commit is contained in:
2024-04-16 14:26:06 +03:00
parent bc264c4d90
commit e7c968797b
298 changed files with 11066 additions and 398 deletions

View File

@@ -0,0 +1,37 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ApplyIpmiActionRequest struct to apply ipmi action on node
type ApplyIpmiActionRequest struct {
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
// Action
// on of actions power_on shutdown force_shutdown reboot
// Required: true
Action string `url:"action" json:"action" validate:"required,action"`
}
// ApplyIpmiAction applies ipmi action on node
func (n Node) ApplyIpmiAction(ctx context.Context, req ApplyIpmiActionRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/applyIpmiAction"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,40 @@
package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ConsumptionRequest struct to get node summary by resources and consumption
type ConsumptionRequest struct {
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
}
// Consumption gets node summary by resources and consumption
func (n Node) Consumption(ctx context.Context, req ConsumptionRequest) (*ConsumptionInfo, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/consumption"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := ConsumptionInfo{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,37 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DecommissionRequest struct to set node status to DECOMMISSIONED
type DecommissionRequest struct {
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
// Force node decommission
// Default: false
// Required: false
Force bool `url:"force" json:"force"`
}
// Decommission sets node status to DECOMMISSIONED
func (n Node) Decommission(ctx context.Context, req DecommissionRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/decommission"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,40 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// EnableRequest struct to enable node from maintenance status to enabled
type EnableRequest struct {
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
// Message
// Required: false
Message string `url:"message,omitempty" json:"message,omitempty"`
// Reason
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
// Enable enables node from maintenance status to enabled
func (n Node) Enable(ctx context.Context, req EnableRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/enable"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,40 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// EnableNodesRequest struct to enable nodes from maintenance status to enabled
type EnableNodesRequest struct {
// List of Node IDs
// Required: true
NIDs []uint64 `url:"nids" json:"nids" validate:"required"`
// Message
// Required: false
Message string `url:"message,omitempty" json:"message,omitempty"`
// Reason
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
// EnableNodes enables nodes from maintenance status to enabled
func (n Node) EnableNodes(ctx context.Context, req EnableNodesRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/enableNodes"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,99 @@
package node
// FilterByID returns ListNodes with specified ID.
func (ln ListNodes) FilterByID(id uint64) ListNodes {
predicate := func(in ItemNode) bool {
return in.ID == id
}
return ln.FilterFunc(predicate)
}
// FilterByName returns ListNodes with specified Name.
func (ln ListNodes) FilterByName(name string) ListNodes {
predicate := func(in ItemNode) bool {
return in.Name == name
}
return ln.FilterFunc(predicate)
}
// FilterByVersion return ListNodes with specified version.
func (ln ListNodes) FilterByVersion(version string) ListNodes {
predicate := func(in ItemNode) bool {
return in.Version == version
}
return ln.FilterFunc(predicate)
}
// FilterByRelease returns ListNodes with specified Release.
func (ln ListNodes) FilterByRelease(release string) ListNodes {
predicate := func(in ItemNode) bool {
return in.Release == release
}
return ln.FilterFunc(predicate)
}
// FilterBySepID returns ListNodes with specified Sep ID.
func (ln ListNodes) FilterBySepID(sepId uint64) ListNodes {
predicate := func(in ItemNode) bool {
for _, s := range in.Seps {
if s == sepId {
return true
}
}
return false
}
return ln.FilterFunc(predicate)
}
// FilterByRole returns ListNodes with specified Role.
func (ln ListNodes) FilterByRole(role string) ListNodes {
predicate := func(in ItemNode) bool {
for _, r := range in.Roles {
if r == role {
return true
}
}
return false
}
return ln.FilterFunc(predicate)
}
// FilterByStatus return ListNodes with specified status.
func (ln ListNodes) FilterByStatus(status string) ListNodes {
predicate := func(in ItemNode) bool {
return in.Status == status
}
return ln.FilterFunc(predicate)
}
// FilterFunc allows filtering ListNodes based on a user-specified predicate.
func (ln ListNodes) FilterFunc(predicate func(ItemNode) bool) ListNodes {
var result ListNodes
for _, item := range ln.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemNode.
// If none was found, returns an empty struct.
func (ln ListNodes) FindOne() ItemNode {
if len(ln.Data) == 0 {
return ItemNode{}
}
return ln.Data[0]
}

View File

@@ -0,0 +1,155 @@
package node
import "testing"
var nodes = ListNodes{
Data: []ItemNode{
{
GID: 212,
GUID: "1",
ID: 1,
Name: "node_1",
Release: "1.7_x86-64",
Roles: []string{"node", "controllernode"},
Seps: []uint64{1, 2, 3},
Status: "ENABLED",
Version: "4.0.0",
},
{
GID: 212,
GUID: "2",
ID: 2,
Name: "node_2",
Release: "",
Roles: []string{"node"},
Seps: []uint64{4, 5},
Status: "CREATED",
Version: "3.8.8",
},
{
GID: 212,
GUID: "3",
ID: 3,
Name: "node_3",
Release: "",
Roles: []string{"physical"},
Seps: []uint64{1},
Status: "CREATED",
Version: "3.8.9",
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
var testId uint64 = 1
actual := nodes.FilterByID(testId).FindOne()
if actual.ID != testId {
t.Fatalf("expected ID %d, found: %d", testId, actual.ID)
}
}
func TestFilterByName(t *testing.T) {
testName := "node_1"
actual := nodes.FilterByName(testName).FindOne()
if actual.Name != testName {
t.Fatalf("expected Name '%s', found: %s", testName, actual.Name)
}
}
func TestFilterByVersion(t *testing.T) {
testVersion := "4.0.0"
actual := nodes.FilterByVersion(testVersion).FindOne()
if actual.Version != testVersion {
t.Fatalf("expected Version '%s', found: %s", testVersion, actual.Version)
}
}
func TestFilterByRelease(t *testing.T) {
testRelease := "1.7_x86-64"
actual := nodes.FilterByRelease(testRelease).FindOne()
if actual.Release != testRelease {
t.Fatalf("expected Release '%s', found: %s", testRelease, actual.Release)
}
}
func TestFilterBySepID(t *testing.T) {
var testSepId uint64 = 1
actual := nodes.FilterBySepID(testSepId)
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
var found bool
for _, sep := range item.Seps {
if sep == testSepId {
found = true
}
}
if !found {
t.Fatalf("expected SepID %d, found seps: %v", testSepId, item.Seps)
}
}
}
func TestFilterByRole(t *testing.T) {
testRole := "node"
actual := nodes.FilterByRole(testRole)
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
var found bool
for _, role := range item.Roles {
if role == testRole {
found = true
}
}
if !found {
t.Fatalf("expected Role %s, found roles: %v", testRole, item.Roles)
}
}
}
func TestFilterByStatus(t *testing.T) {
testStatus := "CREATED"
actual := nodes.FilterByStatus(testStatus)
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.Status != testStatus {
t.Fatalf("expected Status '%s', found: %s", testStatus, item.Status)
}
}
}
func TestFilterFunc(t *testing.T) {
actual := nodes.FilterFunc(func(in ItemNode) bool {
return len(in.Roles) > 0
})
if len(actual.Data) < 1 {
t.Fatal("expected 3, found: ", len(actual.Data))
}
for _, item := range actual.Data {
if len(item.Roles) < 1 {
t.Fatal("expected Roles to contain at least 1 element, found empty")
}
}
}

View File

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

View File

@@ -0,0 +1,10 @@
package node
// IDs gets array of Node IDs from ListNodes struct
func (ln ListNodes) IDs() []uint64 {
res := make([]uint64, 0, len(ln.Data))
for _, n := range ln.Data {
res = append(res, n.ID)
}
return res
}

View File

@@ -0,0 +1,84 @@
package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListRequest struct to get list of nodes
type ListRequest struct {
// Find by node ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by node name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by node version
// Required: false
Version string `url:"version,omitempty" json:"version,omitempty"`
// Find by node release
// Required: false
Release string `url:"release,omitempty" json:"release,omitempty"`
// Find by sep ID
// Required: false
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by node roles
// Required: false
Role string `url:"role,omitempty" json:"role,omitempty"`
// Find by node status
// Required: false
Status string `url:"status,omitempty" json:"status,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 all nodes as a ListNodes struct
func (n Node) List(ctx context.Context, req ListRequest) (*ListNodes, error) {
res, err := n.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListNodes{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of all nodes as an array of bytes
func (n Node) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/list"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,50 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// MaintenanceRequest struct to place node in maintenance state
type MaintenanceRequest struct {
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
// VM Action
// Default: stop
// Required: false
VMAction string `url:"vmaction,omitempty" json:"vmaction,omitempty" validate:"omitempty,vmaction"`
// Offline
// Default: false
// Required: false
Offline bool `url:"offline" json:"offline"`
// VDiskAction
// Required: false
VDiskAction string `url:"vdiskaction,omitempty" json:"vdiskaction,omitempty"`
// Reason
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
// Maintenance places node in maintenance state
func (n Node) Maintenance(ctx context.Context, req MaintenanceRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/maintenance"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,316 @@
package node
// Node summary
type RecordNode struct {
// Consumption
Consumption ConsumptionInfo `json:"consumption"`
// CPU Info
CpuInfo CpuInfo `json:"cpuInfo"`
// CPU Allocation Ratio
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
// GID
GID uint64 `json:"gid"`
// Node ID
ID uint64 `json:"id"`
// IPAddr
IPAddr []string `json:"ipaddr"`
// Isolated Cpus
IsolatedCpus []interface{} `json:"isolatedCpus"`
// Name
Name string `json:"name"`
// NeedReboot
NeedReboot bool `json:"needReboot"`
// Nic Info
NicInfo ListNicInfo `json:"nicInfo"`
// NumaTopology
NumaTopology NumaTopologyInfo `json:"numaTopology"`
// ReservedCPUs
ReservedCPUs []interface{} `json:"reservedCpus"`
// Roles
Roles []string `json:"roles"`
// SriovEnabled
SriovEnabled bool `json:"sriovEnabled"`
// StackID
StackID uint64 `json:"stackId"`
// Status
Status string `json:"status"`
// Version
Version string `json:"version"`
}
// Resource consumption of the node
type ConsumptionInfo struct {
// Consumed resources
Consumed ConsumedResourcesInfo `json:"consumed"`
// Free resources
Free FreeResourcesInfo `json:"free"`
// Hostname
Hostname string `json:"hostname"`
// Reserved resources
Reserved ResourcesInfo `json:"reserved"`
// Total resources
Total ResourcesInfo `json:"total"`
}
// Free Resources Info
type FreeResourcesInfo struct {
// RAM
RAM float64 `json:"RAM"`
}
// Resources Info
type ResourcesInfo struct {
// RAM
RAM uint64 `json:"RAM"`
}
// Consumed Resources Info
type ConsumedResourcesInfo struct {
// RAM
RAM uint64 `json:"RAM"`
// Computes
Computes uint64 `json:"computes"`
// Routers
Routers uint64 `json:"routers"`
// VCPU
VCPU uint64 `json:"vCPU"`
}
// Information about node CPU
type CpuInfo struct {
// Clock Speed
ClockSpeed uint64 `json:"clockSpeed"`
// CoreCount
CoreCount uint64 `json:"coreCount"`
// PhysCount
PhysCount uint64 `json:"physCount"`
}
// Main information about node
type ItemNode struct {
// Additional packages
AdditionalPkgs []interface{} `json:"additionalpkgs"`
// CPU Info
CpuInfo CpuInfo `json:"cpuInfo"`
// Description
Description string `json:"description"`
// GID
GID uint64 `json:"gid"`
// GUID
GUID string `json:"guid"`
// Hostkey
HostKey string `json:"hostkey"`
// ID
ID uint64 `json:"id"`
// IPAddr
IPAddr []string `json:"ipaddr"`
// Isolated Cpus
IsolatedCpus []interface{} `json:"isolatedCpus"`
// Last check
LastCheck uint64 `json:"lastcheck"`
// Machine GUID
MachineGUID string `json:"machineguid"`
// Mainboard SN
MainboardSN string `json:"mainboardSN"`
// Memory
Memory uint64 `json:"memory"`
// Milestones
Milestones uint64 `json:"milestones"`
// Model
Model string `json:"model"`
// Name
Name string `json:"name"`
// NeedReboot
NeedReboot bool `json:"needReboot"`
// NetAddr
NetAddr ListNetAddr `json:"netaddr"`
// Network mode
NetworkMode string `json:"networkmode"`
// Nic Info
NicInfo ListNicInfo `json:"nicInfo"`
// Node UUID
NodeUUID string `json:"nodeUUID"`
// NumaTopology
NumaTopology NumaTopologyInfo `json:"numaTopology"`
// PeerBackup
PeerBackup uint64 `json:"peer_backup"`
// PeerLog
PeerLog uint64 `json:"peer_log"`
// PeerStats
PeerStats uint64 `json:"peer_stats"`
// Pgpus
Pgpus []uint64 `json:"pgpus"`
// PublicKeys
PublicKeys []string `json:"publickeys"`
// Release
Release string `json:"release"`
// ReservedCPUs
ReservedCPUs []interface{} `json:"reservedCpus"`
// Roles
Roles []string `json:"roles"`
// Seps
Seps []uint64 `json:"seps"`
// SerialNum
SerialNum string `json:"serialNum"`
// SriovEnabled
SriovEnabled bool `json:"sriovEnabled"`
// StackID
StackID uint64 `json:"stackId"`
// Status
Status string `json:"status"`
// Tags
Tags []string `json:"tags"`
// Type
Type string `json:"type"`
// Version
Version string `json:"version"`
}
// Numa Topology Info
type NumaTopologyInfo struct {
// NodeNum
NodeNum uint64 `json:"nodenum"`
// Nodes
Nodes map[string]NodeInfo `json:"nodes"`
}
// Node Info from NumaTopologyInfo
type NodeInfo struct {
// CPUList
CPUList []uint64 `json:"cpulist"`
// Memory
Memory ItemMemory `json:"memory"`
}
type ItemMemory struct {
// 1G
OneG uint64 `json:"1G"`
// 2M
TwoM uint64 `json:"2M"`
// Total
Total uint64 `json:"total"`
}
type ListNicInfo []ItemNicInfo
// Item Nic Info
type ItemNicInfo struct {
// Driver
Driver string `json:"driver"`
// MaxVFS
MaxVFS uint64 `json:"maxvfs"`
// NumaNode
NumaNode int64 `json:"numaNode"`
// NumVFS
NumVFS uint64 `json:"numvfs"`
// OSName
OSName string `json:"osName"`
// PCISlot
PCISlot string `json:"pciSlot"`
// VFList
VFList []interface{} `json:"vflist"`
}
type ListNetAddr []ItemNetAddr
// Item Net Addr
type ItemNetAddr struct {
// CIDR
CIDR []string `json:"cidr"`
// Index
Index uint64 `json:"index"`
// IP
IP []string `json:"ip"`
// Mac
Mac string `json:"mac"`
// MTU
MTU uint64 `json:"mtu"`
// Name
Name string `json:"name"`
}
// List of nodes
type ListNodes struct {
// Data
Data []ItemNode `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -0,0 +1,18 @@
// API Actors for managing node. These actors are the final API for end users to manage nodes
package node
import (
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
)
// Structure for creating request to node
type Node struct {
client interfaces.Caller
}
// Builder for node endpoints
func New(client interfaces.Caller) *Node {
return &Node{
client: client,
}
}

View File

@@ -0,0 +1,37 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// RestrictRequest struct to set node status to 'RESTRICTED'
type RestrictRequest struct {
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
// Migrate node
// Default: false
// Required: false
Migrate bool `url:"migrate" json:"migrate"`
}
// Restrict sets node status to 'RESTRICTED' and migrates node if migrate=True
func (n Node) Restrict(ctx context.Context, req RestrictRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/restrict"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,59 @@
package node
import (
"encoding/json"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
)
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (ln ListNodes) Serialize(params ...string) (serialization.Serialized, error) {
if len(ln.Data) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(ln, prefix, indent)
}
return json.Marshal(ln)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (in ItemNode) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(in, prefix, indent)
}
return json.Marshal(in)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (rn RecordNode) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(rn, prefix, indent)
}
return json.Marshal(rn)
}

View File

@@ -0,0 +1,36 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// SetCoreIsolationRequest struct to isolate selected cores on node boot
type SetCoreIsolationRequest struct {
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
// List of core number to isolate
// Required: false
CoreList []uint64 `url:"coreList,omitempty" json:"coreList,omitempty"`
}
// SetCoreIsolation isolates selected cores on node boot
func (n Node) SetCoreIsolation(ctx context.Context, req SetCoreIsolationRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/setCoreIsolation"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,40 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// SetHugePagesRequest struct to set on-boot Huge Pages configuration
type SetHugePagesRequest struct {
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
// Number of 2M hugepages to claim
// Required: true
HugePages2M uint64 `url:"hugepages2M" json:"hugepages2M" validate:"required"`
// Number of 1G hugepages to claim
// Required: true
HugePages1G uint64 `url:"hugepages1G" json:"hugepages1G" validate:"required"`
}
// SetHugePages sets on-boot Huge Pages configuration
func (n Node) SetHugePages(ctx context.Context, req SetHugePagesRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/setHugePages"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,36 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// SetSRIOVStatusRequest struct to set Single-root input/output virtualization kernel config on node
type SetSRIOVStatusRequest struct {
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
// Enabled
// Required: true
Enabled bool `url:"enabled" json:"enabled" validate:"required"`
}
// SetSRIOVStatus sets Single-root input/output virtualization kernel config on node
func (n Node) SetSRIOVStatus(ctx context.Context, req SetSRIOVStatusRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/setsriovstatus"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,44 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// SetVFsNumberRequest struct to set number of VFs for individual NIC on node
type SetVFsNumberRequest struct {
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
// PCI address or NIC name
// Required: true
NicID string `url:"nicId" json:"nicId" validate:"required"`
// Number of VF to assign
// Required: true
VFNum uint64 `url:"vfNum" json:"vfNum" validate:"required"`
// Trust
// Required: true
Trust bool `url:"trust" json:"trust" validate:"required"`
}
// SetVFsNumber sets number of VFs for individual NIC on node
func (n Node) SetVFsNumber(ctx context.Context, req SetVFsNumberRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/setVFsNumber"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,32 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// UpdateRequest struct to update node for actual version
type UpdateRequest struct {
// List of Node IDs
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
}
// Update updates node for actual version
func (n Node) Update(ctx context.Context, req UpdateRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/update"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}