MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / GetVmList

Method GetVmList

pkg/api/client.go:244–269  ·  view source on GitHub ↗

GetVmList gets a list of VMs.

(ctx context.Context)

Source from the content-addressed store, hash-verified

242
243// GetVmList gets a list of VMs.
244func (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.
272func (c *Client) ClearAPICache() {

Callers 9

ExampleUsageFunction · 0.95
TestPVEMockAPIFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
pollForConfigChangeMethod · 0.80

Calls 1

GetMethod · 0.65