package models import ( "encoding/json" "time" ) // ListClusterResponse represents the response for a list of clusters. type ListClusterResponse struct { List ListCluster `json:"cluster_list"` RequestID string `json:"request_id"` } type ListCluster struct { Total int `json:"total"` Page int `json:"page"` PerPage int `json:"per_page"` IsApproximateTotal bool `json:"is_approximate_total"` Items []ItemCluster `json:"items"` HasMore bool `json:"has_more"` } // ItemCluster represents the details of a specific cluster. type ItemCluster struct { FenixClusterStatus string `json:"fenix_cluster_status"` ClusterID int `json:"cluster_id"` MemoryOvercommit float64 `json:"memory_overcommit"` CPUOvercommit float64 `json:"cpu_overcommit"` Created time.Time `json:"created"` StorageName string `json:"storage_name"` StorageType string `json:"storage_type"` FenixBroadcastIP string `json:"fenix_broadcast_ip"` Modified time.Time `json:"modified"` FenixPingIP string `json:"fenix_ping_ip"` Deleted time.Time `json:"deleted"` DrsMode string `json:"drs_mode"` Name string `json:"name"` FenixClusterID int `json:"fenix_cluster_id"` VstorageClusterID int `json:"vstorage_cluster_id"` FenixBalancingStrategy string `json:"fenix_balancing_strategy"` FenixEnabled bool `json:"fenix_enabled"` NodeCount int `json:"node_count"` VMTotalRAM int `json:"vm_total_ram"` VMCount int `json:"vm_count"` ResourceMetrics interface{} `json:"resource_metrics"` } type ResourceMetrics struct { CPU int `json:"cpu"` MemoryAvailable float64 `json:"memory_available"` AvgUtilization float64 `json:"avg_utilization"` MaxMemoryAvailable float64 `json:"max_memory_available"` MaxCPUAvailable float64 `json:"max_cpu_available"` MigrationsCount int `json:"migrations_count"` CPUAvailable float64 `json:"cpu_available"` Memory int `json:"memory"` StandardDeviation float64 `json:"standard_deviation"` MaxStandardDeviation float64 `json:"max_standard_deviation"` } func (ic *ItemCluster) UnmarshalJSON(data []byte) error { type Alias ItemCluster temp := &struct { ResourceMetrics json.RawMessage `json:"resource_metrics,omitempty"` *Alias }{ Alias: (*Alias)(ic), } if err := json.Unmarshal(data, &temp); err != nil { return err } if len(temp.ResourceMetrics) > 0 { var metrics ResourceMetrics if err := json.Unmarshal(temp.ResourceMetrics, &metrics); err != nil { return err } ic.ResourceMetrics = metrics } else { ic.ResourceMetrics = nil } return nil }