Class: Pvectl::Commands::CreateVm
- Inherits:
-
Object
- Object
- Pvectl::Commands::CreateVm
- Includes:
- CreateResourceCommand, SharedConfigParsers
- Defined in:
- lib/pvectl/commands/create_vm.rb
Overview
Handler for the ‘pvectl create vm` command.
Includes CreateResourceCommand for shared workflow and overrides template methods with VM-specific behavior.
Class Method Summary collapse
-
.register(cli) ⇒ void
Registers the create command with the CLI.
Methods included from SharedConfigParsers
#build_ct_config_params, #build_vm_config_params, #parse_ct_mountpoints, #parse_ct_nets, #parse_vm_cloud_init, #parse_vm_disks, #parse_vm_nets
Methods included from CreateResourceCommand
#execute, included, #initialize
Class Method Details
.register(cli) ⇒ void
This method returns an undefined value.
Registers the create command with the CLI.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/pvectl/commands/create_vm.rb', line 28 def self.register(cli) cli.desc "Create a resource" cli.long_desc <<~HELP Create a new virtual machine, container, snapshot, or backup. For VMs and containers, you can either specify configuration via flags or use --interactive for a guided wizard. Use --dry-run to preview the configuration without actually creating the resource. SUBCOMMANDS create vm [ID] Create a virtual machine create container [ID] Create an LXC container create snapshot NAME Create a snapshot (see: pvectl help create snapshot) create backup ID... Create a backup (vzdump) EXAMPLES Create a VM with specific config: $ pvectl create vm 100 --cores 4 --memory 8192 --disk storage=local-lvm,size=50G Create a VM using interactive wizard: $ pvectl create vm --interactive Preview VM creation without executing: $ pvectl create vm 100 --cores 2 --memory 4096 --dry-run Create a container: $ pvectl create container 200 --hostname nginx --ostemplate local:vztmpl/debian-12.tar.zst Create a backup: $ pvectl create backup 100 --storage nfs-backup --mode snapshot NOTES If no ID is specified for VM/container, Proxmox auto-assigns the next available ID. VM creation supports cloud-init configuration via --cloud-init flag. Backup modes: snapshot (default, no downtime), suspend (brief pause), stop (full stop during backup). SEE ALSO pvectl help clone Clone an existing VM or container pvectl help delete Delete resources pvectl help get templates List available templates HELP cli.arg_name "RESOURCE_TYPE [ID...]" cli.command :create do |c| c.desc "Resource name" c.flag [:name], arg_name: "NAME" c.desc "Description/notes" c.flag [:description, :notes], arg_name: "TEXT" # Backup-specific flags c.desc "Target storage for backup" c.flag [:storage], arg_name: "STORAGE" c.desc "Backup mode (snapshot, suspend, stop)" c.default_value "snapshot" c.flag [:mode], arg_name: "MODE", must_match: %w[snapshot suspend stop] c.desc "Compression (zstd, gzip, lzo, 0 for none)" c.default_value "zstd" c.flag [:compress], arg_name: "TYPE" c.desc "Protect backup from deletion" c.switch [:protected], negatable: false # Common flags c.desc "Skip confirmation prompt" c.switch [:yes, :y], negatable: false c.desc "Timeout in seconds for sync operations" c.flag [:timeout], type: Integer, arg_name: "SECONDS" c.desc "Force async mode (return task ID immediately)" c.switch [:async], negatable: false c.desc "Stop on first error (default: continue and report all)" c.switch [:"fail-fast"], negatable: false # Shared config flags (VM + container) SharedFlags.common_config(c) SharedFlags.vm_config(c) SharedFlags.container_config(c) c.desc "Resource pool" c.flag [:pool], arg_name: "POOL" c.desc "Force interactive wizard mode" c.switch [:interactive], negatable: true c.desc "Show what would happen without creating" c.switch [:"dry-run"], negatable: false # Container-specific create flags c.desc "Container hostname (container)" c.flag [:hostname], arg_name: "NAME" c.desc "OS template path (container): storage:vztmpl/name.tar.zst" c.flag [:ostemplate], arg_name: "TEMPLATE" # Sub-commands CreateSnapshot.register_subcommand(c) c.action do |, , args| resource_type = args.shift resource_ids = args exit_code = case resource_type when "vm" Commands::CreateVm.execute(resource_ids, , ) when "container", "ct" Commands::CreateContainer.execute(resource_ids, , ) when "backup" # Map :description to :notes for backup if notes not set [:notes] ||= [:description] Commands::CreateBackup.execute(resource_type, resource_ids, , ) else $stderr.puts "Error: Unknown resource type: #{resource_type}" $stderr.puts "Valid types: vm, container, backup (or use: create snapshot)" ExitCodes::USAGE_ERROR end exit exit_code if exit_code != 0 end end end |