Add option to list storage
This commit is contained in:
22
main.go
22
main.go
@@ -28,13 +28,16 @@ func main() {
|
||||
config := &Config{}
|
||||
var configFile string
|
||||
var batchFile string
|
||||
var listStorage bool
|
||||
|
||||
flag.StringVar(&configFile, "config", "", "Config file path (YAML)")
|
||||
flag.StringVar(&batchFile, "batch", "", "Batch file with multiple config paths (one per line)")
|
||||
flag.BoolVar(&listStorage, "list-storage", false, "List available storage on Proxmox host")
|
||||
flag.BoolVar(&listStorage, "ls", false, "List available storage on Proxmox host (shorthand)")
|
||||
flag.StringVar(&config.ImageURL, "image-url", "", "Cloud image URL to download")
|
||||
flag.StringVar(&config.VMName, "vm-name", "cloud-vm", "VM name")
|
||||
flag.IntVar(&config.VMID, "vm-id", 0, "VM ID (0 = auto-find from 10000+)")
|
||||
flag.StringVar(&config.Storage, "storage", "local-lvm", "Proxmox storage name")
|
||||
flag.StringVar(&config.Storage, "storage", "", "Proxmox storage name (auto-detect if empty)")
|
||||
flag.IntVar(&config.Memory, "memory", 2048, "Memory in MB")
|
||||
flag.IntVar(&config.Cores, "cores", 2, "CPU cores")
|
||||
flag.StringVar(&config.DiskSize, "disk-size", "20G", "Disk size (e.g., 20G)")
|
||||
@@ -44,9 +47,24 @@ func main() {
|
||||
flag.StringVar(&config.ProxmoxHost, "proxmox-host", "", "Proxmox host (e.g., 192.168.1.100)")
|
||||
flag.StringVar(&config.ProxmoxUser, "proxmox-user", "root@pam", "Proxmox user")
|
||||
flag.StringVar(&config.ProxmoxPass, "proxmox-pass", "", "Proxmox password")
|
||||
flag.BoolVar(&config.GuestAgent, "guest-agent", false, "Enable QEMU guest agent")
|
||||
flag.BoolVar(&config.Firewall, "firewall", false, "Enable firewall")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
// Handle storage listing
|
||||
if listStorage || flag.Lookup("ls").Value.(flag.Getter).Get().(bool) {
|
||||
if config.ProxmoxHost == "" {
|
||||
fmt.Println("Error: -proxmox-host is required for storage listing")
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := listAvailableStorage(config); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error listing storage: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Batch mode
|
||||
if batchFile != "" {
|
||||
if err := runBatch(batchFile); err != nil {
|
||||
@@ -56,8 +74,6 @@ func main() {
|
||||
fmt.Println("\nAll templates created successfully!")
|
||||
return
|
||||
}
|
||||
|
||||
// Single config mode
|
||||
if configFile != "" {
|
||||
if err := loadConfigFile(configFile, config); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error loading config file: %v\n", err)
|
||||
|
||||
Reference in New Issue
Block a user