This commit is contained in:
2026-06-19 17:37:20 +03:00
parent b897b3447a
commit f679261f74
1513 changed files with 107093 additions and 1 deletions

View File

@@ -0,0 +1,54 @@
package node
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AddSSHIdentityRequest struct to add node ssh information
type AddSSHIdentityRequest struct {
// Node ID
// Required: true
NID uint64 `url:"node_id" json:"node_id" validate:"required"`
// Host name of the client
// Required: true
ClientHostName string `url:"client_host_name" json:"client_host_name" validate:"required"`
// SSH host key of the client
// Required: true
ClientHostKey string `url:"client_host_key" json:"client_host_key" validate:"required" `
// SSH public key of the client
// Required: true
ClientPublicKey string `url:"client_public_key" json:"client_public_key" validate:"required"`
// IPv4 address
// Required: true
ClientIPAddress string `url:"client_ip_address" json:"client_ip_address" validate:"required" `
}
// AddSSHIdentity adds node ssh information
func (n Node) AddSSHIdentity(ctx context.Context, req AddSSHIdentityRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/add_ssh_identity"
res, err := n.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,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
// Available values : is_powered, 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,42 @@
package node
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AutoStartRequest struct to set node autostart
type AutoStartRequest struct {
// Node ID
// Required: true
NodeID uint64 `url:"node_id" json:"node_id" validate:"required"`
// Auto start
// Required: true
AutoStart bool `url:"autostart" json:"autostart" validate:"required"`
}
// AutoStart sets node autostart
func (n Node) AutoStart(ctx context.Context, req AutoStartRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/autostart"
res, err := n.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,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,86 @@
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"`
// Do not check locks, iscsi-sessions or disk-present
// Default: false
// Required: false
Force interface{} `url:"force" json:"force" validate:"isBool"`
// Reason
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
type wrapperEnableRequest struct {
EnableRequest
AsyncMode bool `url:"asyncMode"`
}
// 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))
}
if req.Force == nil {
req.Force = false
}
reqWrapped := wrapperEnableRequest{
EnableRequest: req,
AsyncMode: false,
}
url := "/cloudbroker/node/enable"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
return string(res), nil
}
// EnableAsync enables node from maintenance status to enabled with AsyncMode
func (n Node) EnableAsync(ctx context.Context, req EnableRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
if req.Force == nil {
req.Force = false
}
reqWrapped := wrapperEnableRequest{
EnableRequest: req,
AsyncMode: true,
}
url := "/cloudbroker/node/enable"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
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"
)
// 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"`
// 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,42 @@
package node
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetLogicalCoresCountRequest struct to get logical cores count by node
type GetLogicalCoresCountRequest struct {
// Node ID
// Required: true
NodeId uint64 `url:"node_id" json:"node_id" validate:"required"`
// Target
// Required: false
Target string `url:"target,omitempty" json:"target,omitempty" validate:"omitempty,oneof=core node"`
}
// GetLogicalCoresCount get logical cores count by node
func (i Node) GetLogicalCoresCount(ctx context.Context, req GetLogicalCoresCountRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/get_logical_cores_count"
res, err := i.client.DecortApiCall(ctx, http.MethodGet, 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,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

@@ -0,0 +1,39 @@
package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetSSHIdentityRequest struct to get node ssh information
type GetSSHIdentityRequest struct {
// Node ID
// Required: true
NID uint64 `url:"node_id" json:"node_id" validate:"required"`
}
// GetSSHIdentity gets node ssh information
func (n Node) GetSSHIdentity(ctx context.Context, req GetSSHIdentityRequest) (*SSHIdentity, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/get_ssh_identity"
res, err := n.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return nil, err
}
info := SSHIdentity{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

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,76 @@
package node
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// InstallRequest struct to install a node
type InstallRequest struct {
// Node name
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Node roles
// Required: true
Roles []string `url:"roles" json:"roles" validate:"required"`
// OS version
// Required: true
OSVersion string `url:"os_version" json:"os_version" validate:"required"`
// OS user
// Required: false
OSUser string `url:"os_user,omitempty" json:"os_user,omitempty"`
// OS user password
// Required: true
OSUserPassword string `url:"os_user_password" json:"os_user_password" validate:"required"`
// Backplane IP address
// Required: true
BackplaneIP string `url:"backplane_ip" json:"backplane_ip" validate:"required"`
// Management IP address
// Required: true
ManagementIP string `url:"management_ip" json:"management_ip" validate:"required"`
// VX backend IP address
// Required: true
VXBackendIP string `url:"vxbackend_ip" json:"vxbackend_ip" validate:"required"`
// Gateway management IP address
// Required: true
GWMgmtIP string `url:"gw_mgmt_ip" json:"gw_mgmt_ip" validate:"required"`
// IPMI address
// Required: true
IPMIAddress string `url:"ipmi_address" json:"ipmi_address" validate:"required"`
// IPMI user
// Required: true
IPMIUser string `url:"ipmi_user" json:"ipmi_user" validate:"required"`
// IPMI password
// Required: true
IPMIPassword string `url:"ipmi_password" json:"ipmi_password" validate:"required"`
}
// Install installs a node
func (n Node) Install(ctx context.Context, req InstallRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/install"
res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,88 @@
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"`
// Find by zone ID
// Required: false
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,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,51 @@
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"`
// Reason
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
// Allow node auto-enable
// Default: false
// Required: false
AutoStart bool `url:"autostart" json:"autostart"`
}
// 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,776 @@
package node
// Node summary
type RecordNode struct {
// Consumption
Consumption ConsumptionInfo `json:"consumption"`
// CPU Info
CpuInfo CpuInfo `json:"cpuInfo"`
// CPU Allocation Ratio
CPUAllocationRatio uint64 `json:"cpu_allocation_ratio"`
// DPDK info
DPDK DPDK `json:"dpdk"`
// GID
GID uint64 `json:"gid"`
// Node ID
ID uint64 `json:"id"`
// IPAddr
IPAddr []string `json:"ipaddr"`
// Isolated Cpus
IsolatedCpus []interface{} `json:"isolatedCpus"`
// MemAllocationRatio
MemAllocationRatio uint64 `json:"mem_allocation_ratio"`
// Name
Name string `json:"name"`
// NeedReboot
NeedReboot bool `json:"needReboot"`
// Netaddr
NetAddr NetAddr `json:"netaddr"`
// Network mode
NetworkMode string `json:"networkmode"`
// 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"`
// Status
Status string `json:"status"`
// To active
ToActive Role `json:"to_active"`
// To installing
ToInstalling Role `json:"to_installing"`
// To maintenance
ToMaintenance Role `json:"to_maintenance"`
// To restricted
ToRestricted Role `json:"to_restricted"`
// Version
Version string `json:"version"`
// Zone ID
ZoneID uint64 `json:"zoneId"`
// OpenvSwitch Bridges
OpenvSwitchBridges []string `json:"openvswitch_bridges"`
// Description
Description string `json:"description"`
// SDN Hypervisor Name
SDNHypervisorName string `json:"sdn_hypervisor_name"`
// CPU used by the node
UsableCPUs []string `json:"usable_cpus"`
// AutoStart
AutoStart bool `json:"autostart"`
// AutoStart Count
AutoStartCount uint64 `json:"autostart_count"`
}
// 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"`
// VCPU
VCPU uint64 `json:"vCPUs"`
}
// 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 float64 `json:"clockSpeed"`
// CoreCount
CoreCount uint64 `json:"coreCount"`
// PhysCount
PhysCount uint64 `json:"physCount"`
// Thread count
ThreadCount uint64 `json:"threadCount"`
// Flags
Flags []string `json:"flags"`
// Model name
ModelName string `json:"model_name"`
// Max supported generation
MaxSupportedGeneration string `json:"max_supported_generation"`
}
// Main information about node
type ItemNode struct {
// Additional packages
AdditionalPkgs []interface{} `json:"additionalpkgs"`
// CPU Info
CpuInfo CpuInfo `json:"cpuInfo"`
// Description
Description string `json:"description"`
// DPDK
DPDK DPDK `json:"dpdk"`
// 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"`
// SDN Hypervisor Name
SDNHypervisorName string `json:"sdn_hypervisor_name"`
// Seps
Seps []uint64 `json:"seps"`
// SerialNum
SerialNum string `json:"serialNum"`
// SriovEnabled
SriovEnabled bool `json:"sriovEnabled"`
// Status
Status string `json:"status"`
// Tags
Tags []string `json:"tags"`
// Type
Type string `json:"type"`
//UEFI Firmware File
UEFIFirmwareFile string `json:"uefiFirmwareFile"`
// Version
Version string `json:"version"`
// Zone ID
ZoneID uint64 `json:"zoneId"`
// OpenvSwitch Bridges
OpenvSwitchBridges []string `json:"openvswitch_bridges"`
// APIUrl
APIUrl string `json:"apiUrl"`
// Drivers
Drivers []string `json:"drivers"`
// Old Compat LVM ID
OldCompatLVMID uint64 `json:"old_compat_lvm_id"`
// CPU Allocation ratio
CPUAllocationRatio uint64 `json:"cpu_allocation_ratio"`
// MemAllocationRatio
MemAllocationRatio uint64 `json:"mem_allocation_ratio"`
// Packages
Packages map[string]PackageInfo `json:"packages"`
// CPU used by the node
UsableCPUs []string `json:"usable_cpus"`
// AutoStart
AutoStart bool `json:"autostart"`
// AutoStart Count
AutoStartCount uint64 `json:"autostart_count"`
// PCI devices attached to the node
PCIDevices []ItemPCIDevice `json:"pci_devices"`
}
type PackageInfo struct {
// Installed size
InstalledSize string `json:"installed_size"`
// Version
Ver string `json:"ver"`
}
// 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"`
// 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"`
}
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"`
}
// Net address
type NetAddr struct {
// Name
Name string `json:"name"`
// IP list backplane1 node
IP []string `json:"ip"`
}
// DPDK info
type DPDK struct {
// Bridges
Bridges Bridges `json:"bridges"`
// hp memory
HPMemory map[string]uint64 `json:"hp_memory"`
// pmd cpu
PMDCPU []uint64 `json:"pmd_cpu"`
}
// Bridges
type Bridges struct {
Backplane1 Backplane1 `json:"backplane1"`
}
// Backplane1
type Backplane1 struct {
Interfaces []string `json:"interfaces"`
NumaNode int64 `json:"numa_node"`
}
// Role
type Role struct {
Actor string `json:"actor"`
Reason string `json:"reason"`
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
HostName string `json:"host_name"`
//SSH host key of the client
HostKey string `json:"host_key"`
//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,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,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

@@ -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,44 @@
package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// SetCpuAllocationRatioRequest struct to set CPU allocation ratio
type SetCpuAllocationRatioRequest struct {
// Node ID
// Required: true
NodeID uint64 `url:"node_id" json:"node_id" validate:"required"`
// Allocation ratio (zero or positive value)
// Required: true
Ratio uint64 `url:"ratio" json:"ratio" validate:"required"`
}
// SetCpuAllocationRatio set CPU allocation ratio
func (i Node) SetCpuAllocationRatio(ctx context.Context, req SetCpuAllocationRatioRequest) (*ItemNode, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/set_cpu_allocation_ratio"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := ItemNode{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, 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,44 @@
package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// SetMemAllocationRatioRequest struct to set memory allocation ratio
type SetMemAllocationRatioRequest struct {
// Node ID
// Required: true
NodeID uint64 `url:"node_id" json:"node_id" validate:"required"`
// Allocation ratio (zero or positive value)
// Required: true
Ratio uint64 `url:"ratio" json:"ratio" validate:"required"`
}
// SetMemAllocationRatio set memory allocation ratio
func (i Node) SetMemAllocationRatio(ctx context.Context, req SetMemAllocationRatioRequest) (*ItemNode, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/set_mem_allocation_ratio"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := ItemNode{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, 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,51 @@
package node
import (
"context"
"net/http"
"strconv"
"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"`
// Number of VF to assign
// Required: true
VFParams []VFParam `url:"vfParams" json:"vfParams" validate:"required"`
}
// SetVFsNumber sets number of VFs for individual NIC on node
func (n Node) SetVFsNumber(ctx context.Context, req SetVFsNumberRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/setVFsNumber"
res, err := n.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,62 @@
package node
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type VFParam struct {
// ID of the FN
// Required: true
FNID uint64 `url:"fnId" json:"fnId" validate:"required"`
// Trust
// Required: true
Trust bool `url:"trust" json:"trust" validate:"required"`
// Enable spoof checking
// Required: true
SpoofChk bool `url:"spoofchk" json:"spoofchk" validate:"required"`
}
// SetVFsParamsRequest struct to set params of VFs for individual NIC on node
type SetVFsParamsRequest 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
VFParams []VFParam `url:"vfParams" json:"vfParams" validate:"required"`
}
// SetVFsParams sets params of VFs for individual NIC on node
func (n Node) SetVFsParams(ctx context.Context, req SetVFsParamsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/setVFsParams"
res, err := n.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, 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,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
}

View File

@@ -0,0 +1,42 @@
package node
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// UpdateDescriptionRequest struct to update description of the node
type UpdateDescriptionRequest struct {
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
// New description for the node
// Required: true
Description string `url:"description" json:"description" validate:"required"`
}
// UpdateDescription updates description of the node
func (n Node) UpdateDescription(ctx context.Context, req UpdateDescriptionRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/update_description"
res, err := n.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
}