GetVmList gets a list of VMs.
(ctx context.Context)
| 242 | |
| 243 | // GetVmList gets a list of VMs. |
| 244 | func (c *Client) GetVmList(ctx context.Context) ([]map[string]interface{}, error) { |
| 245 | var result map[string]interface{} |
| 246 | |
| 247 | err := c.httpClient.Get(ctx, "/cluster/resources", &result) |
| 248 | if err != nil { |
| 249 | return nil, fmt.Errorf("failed to get VM list: %w", err) |
| 250 | } |
| 251 | |
| 252 | data, ok := result["data"].([]interface{}) |
| 253 | if !ok { |
| 254 | return nil, fmt.Errorf("invalid VM list response format") |
| 255 | } |
| 256 | |
| 257 | var vms []map[string]interface{} |
| 258 | |
| 259 | for _, item := range data { |
| 260 | if vm, ok := item.(map[string]interface{}); ok { |
| 261 | // Filter for VMs and containers only |
| 262 | if resType, exists := vm["type"].(string); exists && (resType == VMTypeQemu || resType == VMTypeLXC) { |
| 263 | vms = append(vms, vm) |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | return vms, nil |
| 269 | } |
| 270 | |
| 271 | // ClearAPICache removes all API-related cached responses. |
| 272 | func (c *Client) ClearAPICache() { |