v1.0.0
This commit is contained in:
42
pkg/node/list.go
Normal file
42
pkg/node/list.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/validators"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/node/models"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/node/requests"
|
||||
)
|
||||
|
||||
// Returns a list of nodes for a specific node
|
||||
func (n Node) List(ctx context.Context, req requests.ListNodesRequest) (*models.ListNodeResponse, error) {
|
||||
|
||||
res, err := n.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := models.ListNodeResponse{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets a list of all nodes as an array of bytes
|
||||
func (n Node) ListRaw(ctx context.Context, req requests.ListNodesRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := constants.APIv0 + "/node"
|
||||
|
||||
res, err := n.client.ApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
251
pkg/node/models/model_list.go
Normal file
251
pkg/node/models/model_list.go
Normal file
@@ -0,0 +1,251 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ListNodeResponse struct {
|
||||
List ListNode `json:"node_list"`
|
||||
Task interface{} `json:"task"` //TaskNode
|
||||
RequestID string `json:"request_id"`
|
||||
}
|
||||
|
||||
type ListNode struct {
|
||||
Total int `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PerPage int `json:"per_page"`
|
||||
IsApproximateTotal bool `json:"is_approximate_total"`
|
||||
Items []ItemNode `json:"items"`
|
||||
HasMore bool `json:"has_more"`
|
||||
}
|
||||
|
||||
type TaskNode struct {
|
||||
Command string `json:"command"`
|
||||
Started any `json:"started"` //I don't now type
|
||||
Type string `json:"type"`
|
||||
Snapshot string `json:"snapshot"`
|
||||
ParentID int `json:"parent_id"`
|
||||
Progress string `json:"progress"`
|
||||
InitiatorID int `json:"initiator_id"`
|
||||
TimeoutAt time.Time `json:"timeout_at"`
|
||||
Error string `json:"error"`
|
||||
Finished time.Time `json:"finished"`
|
||||
Created time.Time `json:"created"`
|
||||
Status string `json:"status"`
|
||||
RequestID string `json:"request_id"`
|
||||
HasChildren bool `json:"has_children"`
|
||||
Initiator TaskInitiator `json:"initiator"`
|
||||
}
|
||||
|
||||
type TaskInitiator struct {
|
||||
Name string `json:"name"`
|
||||
UserID int `json:"user_id"`
|
||||
Email string `json:"email"`
|
||||
Login string `json:"login"`
|
||||
}
|
||||
|
||||
type ItemNode struct {
|
||||
Deleted time.Time `json:"deleted"`
|
||||
MasterVmsPath string `json:"master_vms_path"`
|
||||
IPAddress string `json:"ip_address"`
|
||||
Modified time.Time `json:"modified"`
|
||||
Arch string `json:"arch"`
|
||||
TrafficShaping bool `json:"traffic_shaping"`
|
||||
VstorageHostID int `json:"vstorage_host_id"`
|
||||
MemoryReservationMb int `json:"memory_reservation_mb"`
|
||||
MemoryWeight int `json:"memory_weight"`
|
||||
VstorageIPAddress string `json:"vstorage_ip_address"`
|
||||
Status string `json:"status"`
|
||||
Compute bool `json:"compute"`
|
||||
HaCPUOvercommit float64 `json:"ha_cpu_overcommit"`
|
||||
HaMemoryOvercommit float64 `json:"ha_memory_overcommit"`
|
||||
Memory int `json:"memory"`
|
||||
ImageCachePath string `json:"image_cache_path"`
|
||||
VstorageMountPoints any `json:"vstorage_mount_points"` //I don't now type
|
||||
Os string `json:"os"`
|
||||
MemoryOvercommit float64 `json:"memory_overcommit"`
|
||||
StorageStatus string `json:"storage_status"`
|
||||
HwInfo HWInfo `json:"hw_info"`
|
||||
Created time.Time `json:"created"`
|
||||
VirtProduct string `json:"virt_product"`
|
||||
ServerUUID string `json:"server_uuid"`
|
||||
Deletable bool `json:"deletable"`
|
||||
CPUReservation int `json:"cpu_reservation"`
|
||||
Login string `json:"login"`
|
||||
VstorageClusterID int `json:"vstorage_cluster_id"`
|
||||
DiskMb float64 `json:"disk_mb"`
|
||||
Name string `json:"name"`
|
||||
HaEnabled bool `json:"ha_enabled"`
|
||||
Metrics interface{} `json:"metrics"` //Metrics
|
||||
Hostname string `json:"hostname"`
|
||||
CPUWeight int `json:"cpu_weight"`
|
||||
ResourceParameters ResourceParameters `json:"resource_parameters"`
|
||||
NumaInfo NumaInfo `json:"numa_info"`
|
||||
HaStatus string `json:"ha_status"`
|
||||
AgentUpdateStatus string `json:"agent_update_status"`
|
||||
ClusterID int `json:"cluster_id"`
|
||||
NodeID int `json:"node_id"`
|
||||
NodeStatusInHaCluster string `json:"node_status_in_ha_cluster"`
|
||||
VstorageStatus string `json:"vstorage_status"`
|
||||
VirtProductID string `json:"virt_product_id"`
|
||||
Description string `json:"description"`
|
||||
CPU int `json:"cpu"`
|
||||
CPUOvercommit float64 `json:"cpu_overcommit"`
|
||||
SdkStatus string `json:"sdk_status"`
|
||||
VstorageIscsiRoot any `json:"vstorage_iscsi_root"` //I don't now type
|
||||
MaintenanceStatus string `json:"maintenance_status"`
|
||||
ClusterName string `json:"cluster_name"`
|
||||
Shares Shares `json:"shares"`
|
||||
SdkLicense interface{} `json:"sdk_license"` //SDKLicence
|
||||
IsPasswordSet bool `json:"is_password_set"`
|
||||
ResourceMetrics interface{} `json:"resource_metrics"` //ResourceMetrics
|
||||
BlockdevPaths string `json:"blockdev_paths"`
|
||||
}
|
||||
|
||||
type HWInfo struct {
|
||||
CPU struct {
|
||||
Sockets int `json:"sockets"`
|
||||
Cores int `json:"cores"`
|
||||
Cpus int `json:"cpus"`
|
||||
FrequencyMin float64 `json:"frequency_min"`
|
||||
FrequencyMax float64 `json:"frequency_max"`
|
||||
Model string `json:"model"`
|
||||
} `json:"cpu"`
|
||||
Memory struct {
|
||||
SlotsCount int `json:"slots_count"`
|
||||
UsedSlots []struct {
|
||||
RAMSlot0 struct {
|
||||
Size float64 `json:"size"`
|
||||
} `json:"RAM slot #0"`
|
||||
} `json:"used_slots"`
|
||||
} `json:"memory"`
|
||||
Disk []struct {
|
||||
Name string `json:"name"`
|
||||
Size string `json:"size"`
|
||||
} `json:"disk"`
|
||||
}
|
||||
|
||||
type Metrics struct {
|
||||
CPUUsagePercent float64 `json:"cpu_usage_percent"`
|
||||
CombinedPartitionTotalMb float64 `json:"combined_partition_total_mb"`
|
||||
SwapTotalMb float64 `json:"swap_total_mb"`
|
||||
SwapUsedMb float64 `json:"swap_used_mb"`
|
||||
MemoryFreeMb float64 `json:"memory_free_mb"`
|
||||
SwapFreeMb float64 `json:"swap_free_mb"`
|
||||
Modified time.Time `json:"modified"`
|
||||
UptimeSec float64 `json:"uptime_sec"`
|
||||
SwapUsagePercent float64 `json:"swap_usage_percent"`
|
||||
MemoryTotalMb float64 `json:"memory_total_mb"`
|
||||
CombinedPartitionUsageMb float64 `json:"combined_partition_usage_mb"`
|
||||
CombinedPartitionUsagePercent float64 `json:"combined_partition_usage_percent"`
|
||||
MemoryUsedMb float64 `json:"memory_used_mb"`
|
||||
MemoryUsagePercent float64 `json:"memory_usage_percent"`
|
||||
}
|
||||
|
||||
type ResourceParameters struct {
|
||||
VcmmdPolicy string `json:"vcmmd-policy"`
|
||||
VstorageLimitMax int `json:"vstorage_limit_max"`
|
||||
VMOvercommitMemory int `json:"vm.overcommit_memory"`
|
||||
VMSwappiness int `json:"vm.swappiness"`
|
||||
VMVfsCachePressure int `json:"vm.vfs_cache_pressure"`
|
||||
VMMinFreeKbytes int `json:"vm.min_free_kbytes"`
|
||||
}
|
||||
|
||||
type NumaInfo struct {
|
||||
Num0 []int `json:"0"`
|
||||
}
|
||||
|
||||
type Shares struct {
|
||||
Hdd string `json:"hdd"`
|
||||
Iso string `json:"iso"`
|
||||
}
|
||||
|
||||
type SDKLicense struct {
|
||||
NrVms string `json:"nr_vms"`
|
||||
}
|
||||
|
||||
type ResourceMetrics struct {
|
||||
MemoryFree float64 `json:"memory_free"`
|
||||
RunningVmsCount int `json:"running_vms_count"`
|
||||
SumUtilization float64 `json:"sum_utilization"`
|
||||
CPUUtilization float64 `json:"cpu_utilization"`
|
||||
CPUFree float64 `json:"cpu_free"`
|
||||
MemoryUtilization float64 `json:"memory_utilization"`
|
||||
CurrentCPUOvercommit float64 `json:"current_cpu_overcommit"`
|
||||
CurrentMemoryOvercommit float64 `json:"current_memory_overcommit"`
|
||||
}
|
||||
|
||||
func (ln *ListNodeResponse) UnmarshalJSON(data []byte) error {
|
||||
type Alias ListNodeResponse
|
||||
temp := &struct {
|
||||
TaskNode json.RawMessage `json:"task,omitempty"`
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(ln),
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &temp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(temp.TaskNode) > 0 {
|
||||
var task TaskNode
|
||||
if err := json.Unmarshal(temp.TaskNode, &task); err != nil {
|
||||
return err
|
||||
}
|
||||
ln.Task = task
|
||||
} else {
|
||||
ln.Task = nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (in *ItemNode) UnmarshalJSON(data []byte) error {
|
||||
type Alias ItemNode
|
||||
temp := &struct {
|
||||
Metrics json.RawMessage `json:"metrics,omitempty"`
|
||||
ResourceMetrics json.RawMessage `json:"resource_metrics,omitempty"`
|
||||
SdkLicense json.RawMessage `json:"sdk_license,omitempty"`
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(in),
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &temp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(temp.Metrics) > 0 {
|
||||
var metrics Metrics
|
||||
if err := json.Unmarshal(temp.Metrics, &metrics); err != nil {
|
||||
return err
|
||||
}
|
||||
in.Metrics = metrics
|
||||
} else {
|
||||
in.Metrics = nil
|
||||
}
|
||||
|
||||
if len(temp.ResourceMetrics) > 0 {
|
||||
var resourceMetrics ResourceMetrics
|
||||
if err := json.Unmarshal(temp.ResourceMetrics, &resourceMetrics); err != nil {
|
||||
return err
|
||||
}
|
||||
in.ResourceMetrics = resourceMetrics
|
||||
} else {
|
||||
in.ResourceMetrics = nil
|
||||
}
|
||||
|
||||
if len(temp.SdkLicense) > 0 {
|
||||
var license SDKLicense
|
||||
if err := json.Unmarshal(temp.SdkLicense, &license); err != nil {
|
||||
return err
|
||||
}
|
||||
in.SdkLicense = license
|
||||
} else {
|
||||
in.SdkLicense = nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
17
pkg/node/node.go
Normal file
17
pkg/node/node.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to images
|
||||
type Node struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for images endpoints
|
||||
func New(client interfaces.Caller) *Node {
|
||||
return &Node{
|
||||
client,
|
||||
}
|
||||
}
|
||||
130
pkg/node/requests/request_list.go
Normal file
130
pkg/node/requests/request_list.go
Normal file
@@ -0,0 +1,130 @@
|
||||
package requests
|
||||
|
||||
import "time"
|
||||
|
||||
// ListNodesRequest struct to filter nodes based on given parameters
|
||||
type ListNodesRequest struct {
|
||||
// Name of the node to filter by partial matching. Ignored if NameExact is provided.
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Exact name of the node to filter.
|
||||
// Required: false
|
||||
NameExact string `url:"name_exact,omitempty" json:"name_exact,omitempty"`
|
||||
|
||||
// Cluster ID where the node is attached.
|
||||
// Required: false
|
||||
ClusterID int `url:"cluster_id,omitempty" json:"cluster_id,omitempty"`
|
||||
|
||||
// VStorage cluster ID where the node is attached.
|
||||
// Required: false
|
||||
VStorageClusterID int `url:"vstorage_cluster_id,omitempty" json:"vstorage_cluster_id,omitempty"`
|
||||
|
||||
// Include nodes that do not belong to any cluster or VStorage cluster.
|
||||
// Required: false
|
||||
AddWithoutCluster bool `url:"add_without_cluster,omitempty" json:"add_without_cluster,omitempty"`
|
||||
|
||||
// Online status filter (multiple choices).
|
||||
// Required: false
|
||||
Status []string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Maintenance status filter (multiple choices).
|
||||
// Required: false
|
||||
MaintenanceStatus []string `url:"maintenance_status,omitempty" json:"maintenance_status,omitempty" validate:"omitempty,maintenance_status"`
|
||||
|
||||
// Agent update status filter (multiple choices).
|
||||
// Required: false
|
||||
AgentUpdateStatus []string `url:"agent_update_status,omitempty" json:"agent_update_status,omitempty" validate:"omitempty,agent_update_status"`
|
||||
|
||||
// Name of the node’s cluster.
|
||||
// Required: false
|
||||
ClusterName string `url:"cluster_name,omitempty" json:"cluster_name,omitempty"`
|
||||
|
||||
// Text to search within the nodes.
|
||||
// Required: false
|
||||
FilterText string `url:"filter_text,omitempty" json:"filter_text,omitempty"`
|
||||
|
||||
// Columns to be used for filtering based on FilterText.
|
||||
// Required: false
|
||||
FilterColumns string `url:"filter_columns,omitempty" json:"filter_columns,omitempty"`
|
||||
|
||||
// OS type filter for the node.
|
||||
// Required: false
|
||||
OS string `url:"os,omitempty" json:"os,omitempty"`
|
||||
|
||||
// HA status filter (multiple choices).
|
||||
// Required: false
|
||||
HAStatus []string `url:"ha_status,omitempty" json:"ha_status,omitempty" validate:"omitempty,ha_multi_status"`
|
||||
|
||||
// HA status in Fenix cluster filter (multiple choices).
|
||||
// Required: false
|
||||
NodeStatusInHACluster []string `url:"node_status_in_ha_cluster,omitempty" json:"node_status_in_ha_cluster,omitempty" validate:"omitempty,node_status_in_ha_cluster"`
|
||||
|
||||
// Filter by IP address.
|
||||
// Required: false
|
||||
IPAddress string `url:"ip_address,omitempty" json:"ip_address,omitempty"`
|
||||
|
||||
// Filter by node architecture.
|
||||
// Required: false
|
||||
Arch string `url:"arch,omitempty" json:"arch,omitempty"`
|
||||
|
||||
// Filter entities created before this date.
|
||||
// Required: false
|
||||
CreatedBefore time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
|
||||
|
||||
// Filter entities created after this date.
|
||||
// Required: false
|
||||
CreatedAfter time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
|
||||
|
||||
// Include node’s current metrics in the response.
|
||||
// Required: false
|
||||
WithMetrics bool `url:"with_metrics,omitempty" json:"with_metrics,omitempty"`
|
||||
|
||||
// Include current resource scheduler metrics info.
|
||||
// Required: false
|
||||
WithResourceMetrics bool `url:"with_resource_metrics,omitempty" json:"with_resource_metrics,omitempty"`
|
||||
|
||||
// Include external resource’s nodes.
|
||||
// Required: false
|
||||
IncludeExternal bool `url:"include_external,omitempty" json:"include_external,omitempty"`
|
||||
|
||||
// Include nodes with enabled traffic shaping.
|
||||
// Required: false
|
||||
TrafficShaping bool `url:"traffic_shaping,omitempty" json:"traffic_shaping,omitempty"`
|
||||
|
||||
// List of node IDs to exclude from the listing.
|
||||
// Required: false
|
||||
ExcludeIDs []int `url:"exclude_ids,omitempty" json:"exclude_ids,omitempty"`
|
||||
|
||||
// Column sorting order.
|
||||
// Required: false
|
||||
Sort []string `url:"sort,omitempty" json:"sort,omitempty"`
|
||||
|
||||
// Visibility options: "visible" (default), "deleted", or "all".
|
||||
// Required: false
|
||||
Visibility string `url:"visibility,omitempty" json:"visibility,omitempty" validate:"omitempty,visibility"`
|
||||
|
||||
// Number of the page to return.
|
||||
// Required: false
|
||||
Page int `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Number of items to return per page.
|
||||
// Required: false
|
||||
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
|
||||
|
||||
// Show SDK license information.
|
||||
// Required: false
|
||||
WithLicense bool `url:"with_license,omitempty" json:"with_license,omitempty"`
|
||||
|
||||
// Storage status filter.
|
||||
// Required: false
|
||||
StorageStatus string `url:"storage_status,omitempty" json:"storage_status,omitempty"`
|
||||
|
||||
// List of virtual network IDs to filter nodes by.
|
||||
// Required: false
|
||||
VirtualNetworkIDs []int `url:"virtual_network_ids,omitempty" json:"virtual_network_ids,omitempty"`
|
||||
|
||||
// List of external storage IDs to filter nodes by. Only READY storages are included.
|
||||
// Required: false
|
||||
ExternalStorageIDs []int `url:"external_storage_ids,omitempty" json:"external_storage_ids,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user