Add option to list storage

This commit is contained in:
2025-11-15 10:47:22 +07:00
parent b9ab1caf02
commit 36fa9644b4
5 changed files with 87 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
"os/exec"
@@ -236,3 +237,63 @@ func createProxmoxVM(config *Config) error {
return nil
}
func listAvailableStorage(config *Config) error {
fmt.Printf("Detecting available storage on %s...\n", config.ProxmoxHost)
sshCmd := func(args ...string) *exec.Cmd {
fullArgs := []string{
"-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=/dev/null",
fmt.Sprintf("%s@%s", strings.Split(config.ProxmoxUser, "@")[0], config.ProxmoxHost),
}
fullArgs = append(fullArgs, args...)
return exec.Command("ssh", fullArgs...)
}
cmd := sshCmd("pvesm", "status", "--output-format", "json")
var stdout bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to get storage status: %w", err)
}
// Parse JSON output
var storageList []map[string]interface{}
if err := json.Unmarshal(stdout.Bytes(), &storageList); err != nil {
return fmt.Errorf("failed to parse storage status: %w", err)
}
fmt.Println("\nAvailable storage:")
fmt.Println("================")
found := false
for _, storage := range storageList {
nameVal, ok := storage["storage"]
if !ok {
continue
}
name, _ := nameVal.(string)
typeVal, _ := storage["type"]
typeStr, _ := typeVal.(string)
activeVal, _ := storage["active"]
activeFloat, _ := activeVal.(float64)
if activeFloat == 1 {
fmt.Printf("- %s (%s) - ACTIVE\n", name, typeStr)
found = true
}
}
if !found {
fmt.Println("No active storage found!")
fmt.Println("\nManual check:")
fmt.Println(" ssh root@your-proxmox 'pvesm status'")
}
return nil
}