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 }