This commit is contained in:
asteam
2024-10-01 11:15:36 +03:00
commit a25a3c2e5c
81 changed files with 5143 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package models
import "time"
type CreateVMResponse struct {
Task CreateTask `json:"task"`
VMIds []int `json:"vm_ids"`
RequestID string `json:"request_id"`
}
type CreateTask struct {
Error string `json:"error"`
Snapshot string `json:"snapshot"`
ParentID int `json:"parent_id"`
Status string `json:"status"`
Created time.Time `json:"created"`
Progress string `json:"progress"`
Command string `json:"command"`
Finished time.Time `json:"finished"`
Type string `json:"type"`
TimeoutAt time.Time `json:"timeout_at"`
InitiatorID int `json:"initiator_id"`
RequestID string `json:"request_id"`
Started time.Time `json:"started"`
VMID int `json:"vm_id"`
NodeID int `json:"node_id"`
HasChildren bool `json:"has_children"`
Initiator Initiator `json:"initiator"`
Node TaskNode `json:"node"`
Cluster Cluster `json:"cluster"`
VM VM `json:"vm"`
}

176
pkg/vm/models/model_get.go Normal file
View File

@@ -0,0 +1,176 @@
package models
import (
"encoding/json"
"time"
)
// RecordVMResponse represents the virtual machine information.
type RecordVMResponse struct {
VMInfo RecordVM `json:"vm_info"`
RequestID string `json:"request_id"`
}
// RecordVM represents the detailed virtual machine information.
type RecordVM struct {
Domain string `json:"domain"`
Status string `json:"status"`
VMID int `json:"vm_id"`
SystemFlags string `json:"system_flags"`
IopsLimit int `json:"iops_limit"`
IsInfrastructure bool `json:"is_infrastructure"`
TpmEnabled bool `json:"tpm_enabled"`
SecureBoot bool `json:"secure_boot"`
Created time.Time `json:"created"`
ResourcePoolID int `json:"resource_pool_id"`
ExternalStorageID int `json:"external_storage_id"`
AutoStartDelay int `json:"auto_start_delay"`
GuestOsVersion string `json:"guest_os_version"`
RAMSize int `json:"ram_size"`
IsTemplate bool `json:"is_template"`
Description string `json:"description"`
RAMHotplugEnabled bool `json:"ram_hotplug_enabled"`
AutoStart string `json:"auto_start"`
MemGuaranteeSize int `json:"mem_guarantee_size"`
RAMTotalHotplug int `json:"ram_total_hotplug"`
Maxmemory int `json:"maxmemory"`
HaPriority int `json:"ha_priority"`
IoPriority int `json:"io_priority"`
CPUSockets int `json:"cpu_sockets"`
NodeMask string `json:"node_mask"`
MaxRAMSize int `json:"max_ram_size"`
Name string `json:"name"`
CPUMask string `json:"cpu_mask"`
NodeID int `json:"node_id"`
BootDeviceList []BootDevice `json:"boot_device_list"`
DisableAutobalance bool `json:"disable_autobalance"`
CPUUnits int `json:"cpu_units"`
SmbiosUUID string `json:"smbios_uuid"`
InstallOs bool `json:"install_os"`
UsedByDesktop bool `json:"used_by_desktop"`
CPUCount int `json:"cpu_count"`
VirtType string `json:"virt_type"`
VncPassword string `json:"vnc_password"`
VncHostname string `json:"vnc_hostname"`
Ratebound bool `json:"ratebound"`
EfiEnabled bool `json:"efi_enabled"`
Affinity string `json:"affinity"`
GuestOs string `json:"guest_os"`
CPUHotplug bool `json:"cpu_hotplug"`
Imported bool `json:"imported"`
ExternalResourceName string `json:"external_resource_name"`
CoresCount int `json:"cores_count"`
AutoStop string `json:"auto_stop"`
Hostname string `json:"hostname"`
VideoRAMSize int `json:"video_ram_size"`
HaStatus string `json:"ha_status"`
MacAddresses []string `json:"mac_addresses"`
ClusterID int `json:"cluster_id"`
ParentUUID string `json:"parent_uuid"`
ClockOffset string `json:"clock_offset"`
IsLinkedClone bool `json:"is_linked_clone"`
GuestToolsState string `json:"guest_tools_state"`
VncMode string `json:"vnc_mode"`
ExternalUUID string `json:"external_uuid"`
Deleted time.Time `json:"deleted"`
LinkedVMUUID string `json:"linked_vm_uuid"`
RAMBalloonActualHotplug int `json:"ram_balloon_actual_hotplug"`
IPAddress string `json:"ip_address"`
Rates any `json:"rates"` //I don't now type
UUID string `json:"uuid"`
CPULimit int `json:"cpu_limit"`
Location string `json:"location"`
CreationDate time.Time `json:"creation_date"`
VncPort int `json:"vnc_port"`
MonitoringEnabled bool `json:"monitoring_enabled"`
ExternalStorageName string `json:"external_storage_name"`
HaEnabled bool `json:"ha_enabled"`
IoLimit int `json:"io_limit"`
ExternalResourceID int `json:"external_resource_id"`
FolderID int `json:"folder_id"`
Lock bool `json:"lock"`
IsVzTemplate bool `json:"is_vz_template"`
Chipset string `json:"chipset"`
LinkedVMID int `json:"linked_vm_id"`
LinkedCloneCount int `json:"linked_clone_count"`
SnapshotCount int `json:"snapshot_count"`
HostDeviceCount int `json:"host_device_count"`
Node Node `json:"node"`
AllMd5 bool `json:"all_md5"`
EditableParams EditableParams `json:"editable_params"`
Metrics interface{} `json:"metrics"` //Metrics
ParentTree []ParentTree `json:"parent_tree"`
}
// BootDevice represents the boot device information.
type BootDevice struct {
Type string `json:"type"`
InUse bool `json:"in_use"`
Index int `json:"index"`
}
// Node represents the node information.
type Node struct {
Name string `json:"name"`
NodeID int `json:"node_id"`
}
// EditableParams represents the editable parameters.
type EditableParams struct {
OnTheFly []string `json:"on_the_fly"`
NeedRestart []string `json:"need_restart"`
}
// Metrics represents the metrics parameters.
type Metrics struct {
CombinedPartitionTotalMb float64 `json:"combined_partition_total_mb"`
MemoryTotalMb float64 `json:"memory_total_mb"`
DiskIoReadPs float64 `json:"disk_io_read_ps"`
CPUUsagePercent float64 `json:"cpu_usage_percent"`
CombinedPartitionFreeMb float64 `json:"combined_partition_free_mb"`
TrafficInMb float64 `json:"traffic_in_mb"`
TrafficOutMb float64 `json:"traffic_out_mb"`
MemoryFreeMb float64 `json:"memory_free_mb"`
CombinedPartitionUsageMb float64 `json:"combined_partition_usage_mb"`
Modified time.Time `json:"modified"`
UptimeSec float64 `json:"uptime_sec"`
CombinedPartitionUsagePercent float64 `json:"combined_partition_usage_percent"`
DiskIoWritePs float64 `json:"disk_io_write_ps"`
MemoryUsagePercent float64 `json:"memory_usage_percent"`
}
// ParentTree represents the parent tree information.
type ParentTree struct {
VMID int `json:"vm_id"`
Name string `json:"name"`
UUID string `json:"uuid"`
ParentID int `json:"parent_id"`
IsTemplate bool `json:"is_template"`
Depth int `json:"depth"`
}
func (vm *RecordVM) UnmarshalJSON(data []byte) error {
type Alias RecordVM
temp := &struct {
Metrics json.RawMessage `json:"metrics,omitempty"`
*Alias
}{
Alias: (*Alias)(vm),
}
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
}
vm.Metrics = metrics
} else {
vm.Metrics = nil
}
return nil
}

View File

@@ -0,0 +1,48 @@
package models
import "time"
// ListDiskResponse represents the hard disks information.
type ListDiskResponse struct {
List DeviceList `json:"device_list"`
RequestID string `json:"request_id"`
}
type DeviceList struct {
Total int `json:"total"`
Page int `json:"page"`
PerPage int `json:"per_page"`
IsApproximateTotal bool `json:"is_approximate_total"`
Items []DiskItem `json:"items"`
HasMore bool `json:"has_more"`
}
type DiskItem struct {
Enabled bool `json:"enabled"`
Status string `json:"status"`
Modified time.Time `json:"modified"`
Created time.Time `json:"created"`
Name string `json:"name"`
StackIndex int `json:"stack_index"`
DiskType string `json:"disk_type"`
ImageID int `json:"image_id"`
Deleted time.Time `json:"deleted"`
ExternalStorageID int `json:"external_storage_id"`
ImagePath string `json:"image_path"`
DeviceID int `json:"device_id"`
IsSharedDisk bool `json:"is_shared_disk"`
ExternalUUID string `json:"external_uuid"`
TierID int `json:"tier_id"`
DeviceIndex int `json:"device_index"`
VolumeID int `json:"volume_id"`
Connected bool `json:"connected"`
DeviceType string `json:"device_type"`
ExternalResourceID int `json:"external_resource_id"`
VMID int `json:"vm_id"`
EmulationType string `json:"emulation_type"`
Size int `json:"size"`
UUID string `json:"uuid"`
InterfaceType string `json:"interface_type"`
EditableParams []string `json:"editable_params"`
DiskCaches []interface{} `json:"disk_caches"`
}

107
pkg/vm/models/model_list.go Normal file
View File

@@ -0,0 +1,107 @@
package models
import "time"
// ListVMResponse represents the entire JSON response
type ListVMResponse struct {
VMList ListVM `json:"vm_list"`
RequestID string `json:"request_id"`
}
// ListVM represents a list of virtual machines.
type ListVM struct {
Total int `json:"total"`
Page int `json:"page"`
PerPage int `json:"per_page"`
IsApproximateTotal bool `json:"is_approximate_total"`
Items []ItemVM `json:"items"`
HasMore bool `json:"has_more"`
}
// ItemVM represents a single virtual machine.
type ItemVM struct {
Domain string `json:"domain"`
Status string `json:"status"`
VMID int `json:"vm_id"`
SystemFlags string `json:"system_flags"`
IopsLimit int `json:"iops_limit"`
IsInfrastructure bool `json:"is_infrastructure"`
TpmEnabled bool `json:"tpm_enabled"`
SecureBoot bool `json:"secure_boot"`
Created time.Time `json:"created"`
ResourcePoolID int `json:"resource_pool_id"`
ExternalStorageID int `json:"external_storage_id"`
AutoStartDelay int `json:"auto_start_delay"`
GuestOsVersion string `json:"guest_os_version"`
RAMSize int `json:"ram_size"`
IsTemplate bool `json:"is_template"`
Description string `json:"description"`
RAMHotplugEnabled bool `json:"ram_hotplug_enabled"`
AutoStart string `json:"auto_start"`
MemGuaranteeSize int `json:"mem_guarantee_size"`
RAMTotalHotplug int `json:"ram_total_hotplug"`
Maxmemory int `json:"maxmemory"`
HaPriority int `json:"ha_priority"`
IoPriority int `json:"io_priority"`
CPUSockets int `json:"cpu_sockets"`
NodeMask string `json:"node_mask"`
MaxRAMSize int `json:"max_ram_size"`
Name string `json:"name"`
CPUMask string `json:"cpu_mask"`
NodeID int `json:"node_id"`
BootDeviceList []BootDevice `json:"boot_device_list"`
DisableAutobalance bool `json:"disable_autobalance"`
CPUUnits int `json:"cpu_units"`
SmbiosUUID string `json:"smbios_uuid"`
InstallOs bool `json:"install_os"`
UsedByDesktop bool `json:"used_by_desktop"`
CPUCount int `json:"cpu_count"`
VirtType string `json:"virt_type"`
VncPassword string `json:"vnc_password"`
VncHostname string `json:"vnc_hostname"`
Ratebound bool `json:"ratebound"`
EfiEnabled bool `json:"efi_enabled"`
Affinity string `json:"affinity"`
GuestOs string `json:"guest_os"`
CPUHotplug bool `json:"cpu_hotplug"`
Imported bool `json:"imported"`
ExternalResourceName string `json:"external_resource_name"`
CoresCount int `json:"cores_count"`
AutoStop string `json:"auto_stop"`
Hostname string `json:"hostname"`
VideoRAMSize int `json:"video_ram_size"`
HaStatus string `json:"ha_status"`
MacAddresses []string `json:"mac_addresses"`
ClusterID int `json:"cluster_id"`
ParentUUID string `json:"parent_uuid"`
ClockOffset string `json:"clock_offset"`
IsLinkedClone bool `json:"is_linked_clone"`
GuestToolsState string `json:"guest_tools_state"`
VncMode string `json:"vnc_mode"`
ExternalUUID string `json:"external_uuid"`
Deleted time.Time `json:"deleted"`
LinkedVMUUID string `json:"linked_vm_uuid"`
RAMBalloonActualHotplug int `json:"ram_balloon_actual_hotplug"`
IPAddress string `json:"ip_address"`
Rates any `json:"rates"` //I don't now type
UUID string `json:"uuid"`
CPULimit int `json:"cpu_limit"`
Location string `json:"location"`
CreationDate time.Time `json:"creation_date"`
VncPort int `json:"vnc_port"`
MonitoringEnabled bool `json:"monitoring_enabled"`
ExternalStorageName string `json:"external_storage_name"`
HaEnabled bool `json:"ha_enabled"`
IoLimit int `json:"io_limit"`
ExternalResourceID int `json:"external_resource_id"`
FolderID int `json:"folder_id"`
Lock bool `json:"lock"`
IsVzTemplate bool `json:"is_vz_template"`
Chipset string `json:"chipset"`
LinkedVMID int `json:"linked_vm_id"`
LinkedCloneCount int `json:"linked_clone_count"`
SnapshotCount int `json:"snapshot_count"`
HostDeviceCount int `json:"host_device_count"`
Node Node `json:"node"`
AllMd5 bool `json:"all_md5"`
}

View File

@@ -0,0 +1,110 @@
package models
import "time"
// DisableInfoResponse represents the response containing disable information for a VM operation.
type DisableInfoResponse struct {
DisableInfo DisableInfo `json:"task_info"`
RequestID string `json:"request_id"`
}
// DisableInfo represents the detailed task information for a VM operation.
type DisableInfo struct {
Progress int `json:"progress"`
RequestID string `json:"request_id"`
Finished time.Time `json:"finished"`
ParentID int `json:"parent_id"`
NodeID int `json:"node_id"`
Error string `json:"error"`
VMID int `json:"vm_id"`
NewVMStatus string `json:"new_vm_status"`
CurrentVMStatus string `json:"current_vm_status"`
Snapshot string `json:"snapshot"`
InitiatorID int `json:"initiator_id"`
Type string `json:"type"`
Started time.Time `json:"started"`
TimeoutAt time.Time `json:"timeout_at"`
NewNodeID int `json:"new_node_id"`
Status string `json:"status"`
Command string `json:"command"`
Created time.Time `json:"created"`
HasChildren bool `json:"has_children"`
Initiator Initiator `json:"initiator"`
Node TaskNode `json:"node"`
Cluster Cluster `json:"cluster"`
VM VM `json:"vm"`
}
// Initiator represents the initiator of the task.
type Initiator struct {
Name string `json:"name"`
UserID int `json:"user_id"`
Email string `json:"email"`
Login string `json:"login"`
}
// TaskNode represents the node information.
type TaskNode struct {
ServerUUID string `json:"server_uuid"`
SDKStatus string `json:"sdk_status"`
NodeID int `json:"node_id"`
Status string `json:"status"`
Compute bool `json:"compute"`
Name string `json:"name"`
VStorageClusterID int `json:"vstorage_cluster_id"`
VStorageStatus string `json:"vstorage_status"`
MaintenanceStatus string `json:"maintenance_status"`
StorageStatus string `json:"storage_status"`
ClusterID int `json:"cluster_id"`
IPAddress string `json:"ip_address"`
Deleted time.Time `json:"deleted"`
Modified time.Time `json:"modified"`
VStorageHostID int `json:"vstorage_host_id"`
Description string `json:"description"`
Created time.Time `json:"created"`
}
// Cluster represents the cluster information.
type Cluster struct {
CPUOvercommit float64 `json:"cpu_overcommit"`
FenixPingIP string `json:"fenix_ping_ip"`
Created time.Time `json:"created"`
FenixClusterStatus string `json:"fenix_cluster_status"`
StorageName string `json:"storage_name"`
FenixBalancingStrategy string `json:"fenix_balancing_strategy"`
FenixEnabled bool `json:"fenix_enabled"`
Name string `json:"name"`
VStorageClusterID int `json:"vstorage_cluster_id"`
FenixClusterID int `json:"fenix_cluster_id"`
FenixBroadcastIP string `json:"fenix_broadcast_ip"`
DRSMode string `json:"drs_mode"`
MemoryOvercommit float64 `json:"memory_overcommit"`
ClusterID int `json:"cluster_id"`
StorageType string `json:"storage_type"`
Deleted time.Time `json:"deleted"`
Modified time.Time `json:"modified"`
NodeCount int `json:"node_count"`
VMTotalRAM int `json:"vm_total_ram"`
VMCount int `json:"vm_count"`
}
// VM represents the virtual machine information.
type VM struct {
VMID int `json:"vm_id"`
Name string `json:"name"`
UUID string `json:"uuid"`
IPAddress string `json:"ip_address"`
Status string `json:"status"`
LinkedCloneCount int `json:"linked_clone_count"`
SnapshotCount int `json:"snapshot_count"`
HostDeviceCount int `json:"host_device_count"`
Node NodeRef `json:"node"`
SMBIOSUUID string `json:"smbios_uuid"`
AllMD5 bool `json:"all_md5"`
}
// NodeRef represents a reference to a node, used within VM information.
type NodeRef struct {
NodeID int `json:"node_id"`
Name string `json:"name"`
}

View File

@@ -0,0 +1,36 @@
package models
import "time"
// EnableInfoResponse represents the response containing enable information for a VM operation.
type EnableInfoResponse struct {
EnableInfo EnableInfo `json:"task_info"`
RequestID string `json:"request_id"`
}
// EnableInfo represents the detailed task information for a VM operation.
type EnableInfo struct {
Progress int `json:"progress"`
RequestID string `json:"request_id"`
Finished time.Time `json:"finished"`
ParentID int `json:"parent_id"`
NodeID int `json:"node_id"`
Error string `json:"error"`
VMID int `json:"vm_id"`
NewVMStatus string `json:"new_vm_status"`
CurrentVMStatus string `json:"current_vm_status"`
Snapshot string `json:"snapshot"`
InitiatorID int `json:"initiator_id"`
Type string `json:"type"`
Started time.Time `json:"started"`
TimeoutAt time.Time `json:"timeout_at"`
NewNodeID int `json:"new_node_id"`
Status string `json:"status"`
Command string `json:"command"`
Created time.Time `json:"created"`
HasChildren bool `json:"has_children"`
Initiator Initiator `json:"initiator"`
Node TaskNode `json:"node"`
Cluster Cluster `json:"cluster"`
VM VM `json:"vm"`
}