Class: Pvectl::Commands::DeleteVm
- Inherits:
-
Object
- Object
- Pvectl::Commands::DeleteVm
- Includes:
- DeleteCommand
- Defined in:
- lib/pvectl/commands/delete_vm.rb
Overview
Handler for the ‘pvectl delete vm` command.
Deletes one or more virtual machines from the cluster. Always requires confirmation (–yes to skip). Running VMs must be stopped first or use –force.
Constant Summary collapse
- RESOURCE_TYPE =
:vm- SUPPORTED_RESOURCES =
%w[vm].freeze
Class Method Summary collapse
-
.register(cli) ⇒ void
Registers the delete command with the CLI.
Methods included from DeleteCommand
Methods included from IrreversibleCommand
#execute, included, #initialize
Class Method Details
.register(cli) ⇒ void
This method returns an undefined value.
Registers the delete command with the CLI.
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 |
# File 'lib/pvectl/commands/delete_vm.rb', line 30 def self.register(cli) cli.desc "Delete a resource" cli.long_desc <<~HELP Delete virtual machines, containers, snapshots, or backups. Destructive operations require confirmation (--yes flag or interactive prompt). Use --force to stop running resources before deletion. SUBCOMMANDS delete vm ID... Delete virtual machines delete container ID... Delete LXC containers delete snapshot NAME Delete snapshots (see: pvectl help delete snapshot) delete backup VOLID... Delete backup volumes EXAMPLES Delete a stopped VM: $ pvectl delete vm 100 --yes Force-delete a running VM (stops it first): $ pvectl delete vm 100 --force --yes Delete VM but keep its disks: $ pvectl delete vm 100 --keep-disks --yes Delete a backup by volume ID: $ pvectl delete backup local:backup/vzdump-qemu-100-2026_01_01.vma.zst --yes NOTES Deletion is irreversible. Always verify the resource ID before confirming. --force stops a running VM/container before deleting. --purge removes the resource from replication and backup jobs. SEE ALSO pvectl help get List resources to find IDs pvectl help create Create new resources HELP cli.arg_name "RESOURCE_TYPE [ID...] [NAME]" cli.command :delete do |c| c.desc "Skip confirmation prompt (REQUIRED for destructive operations)" c.switch [:yes, :y], negatable: false c.desc "Force stop running VM/container before deletion" c.switch [:force, :f], negatable: false c.desc "Keep disks (do not destroy)" c.switch [:"keep-disks"], negatable: false c.desc "Remove from HA, replication, and backups" c.switch [:purge], negatable: false c.desc "Select all resources of this type" c.switch [:all, :A], negatable: false c.desc "Filter by node name" c.flag [:node, :n], arg_name: "NODE" c.desc "Filter by selector (e.g., status=running,tags=prod)" c.flag [:l, :selector], arg_name: "SELECTOR", multiple: true 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 # Sub-commands DeleteSnapshot.register_subcommand(c) c.action do |, , args| resource_type = args.shift exit_code = case resource_type when "vm" Commands::DeleteVm.execute(resource_type, args, , ) when "container", "ct" Commands::DeleteContainer.execute(resource_type, args, , ) when "backup" Commands::DeleteBackup.execute(resource_type, args, , ) else $stderr.puts "Error: Unknown resource type: #{resource_type}" $stderr.puts "Valid types: vm, container, backup (or use: delete snapshot)" ExitCodes::USAGE_ERROR end exit exit_code if exit_code != 0 end end end |