You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
252 lines
9.0 KiB
252 lines
9.0 KiB
4 months ago
|
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
|
||
|
}
|