Class: Pvectl::Commands::DeleteSnapshot
- Inherits:
-
Object
- Object
- Pvectl::Commands::DeleteSnapshot
- Defined in:
- lib/pvectl/commands/delete_snapshot.rb
Overview
Handler for the ‘pvectl delete snapshot` sub-command.
Deletes snapshots from VMs/containers. Snapshot name is the first positional argument, or use –all to delete ALL snapshots. VMIDs are specified via –vmid flag. Without –vmid, operates cluster-wide.
Constant Summary collapse
- VMID_PATTERN =
/\A[1-9]\d{0,8}\z/
Class Method Summary collapse
-
.execute(args, options, global_options) ⇒ Integer
Executes the delete snapshot command.
-
.register_subcommand(parent) ⇒ void
Registers as a sub-command under the parent delete command.
Instance Method Summary collapse
-
#execute ⇒ Integer
Executes the delete snapshot command.
-
#initialize(args, options, global_options) ⇒ DeleteSnapshot
constructor
Initializes a delete snapshot command.
Constructor Details
#initialize(args, options, global_options) ⇒ DeleteSnapshot
Initializes a delete snapshot command.
82 83 84 85 86 87 88 89 90 |
# File 'lib/pvectl/commands/delete_snapshot.rb', line 82 def initialize(args, , ) @args = Array(args) @options = @global_options = @snapshot_name = @args.first @vmids = parse_vmids([:vmid]) @node = [:node] @delete_all = [:all] || false end |
Class Method Details
.execute(args, options, global_options) ⇒ Integer
Executes the delete snapshot command.
73 74 75 |
# File 'lib/pvectl/commands/delete_snapshot.rb', line 73 def self.execute(args, , ) new(args, , ).execute end |
.register_subcommand(parent) ⇒ void
This method returns an undefined value.
Registers as a sub-command under the parent delete command.
27 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 |
# File 'lib/pvectl/commands/delete_snapshot.rb', line 27 def self.register_subcommand(parent) parent.desc "Delete snapshots from VMs or containers" parent.long_desc <<~HELP Delete snapshots from VMs and containers. EXAMPLES Delete a specific snapshot from a VM: $ pvectl delete snapshot before-upgrade --vmid 100 --yes Delete a snapshot from all VMs that have it: $ pvectl delete snapshot before-upgrade --yes Delete ALL snapshots from a specific VM: $ pvectl delete snapshot --all --vmid 100 --yes Delete ALL snapshots cluster-wide: $ pvectl delete snapshot --all --yes NOTES Snapshot deletion is irreversible. --all deletes every snapshot, not just the named one. Use with extreme caution, especially without --vmid. SEE ALSO pvectl help create snapshot Create snapshots pvectl help rollback Rollback to a snapshot pvectl help get snapshots List existing snapshots HELP parent.command :snapshot do |s| s.desc "VM/CT ID (repeatable)" s.flag [:vmid], arg_name: "VMID", multiple: true s.action do |, , args| exit_code = execute(args, , ) exit exit_code if exit_code != 0 end end end |
Instance Method Details
#execute ⇒ Integer
Executes the delete snapshot command.
95 96 97 98 99 100 101 102 103 |
# File 'lib/pvectl/commands/delete_snapshot.rb', line 95 def execute return usage_error("Snapshot name or --all required") if @snapshot_name.nil? && !@delete_all return usage_error("Cannot use --all with snapshot name") if @snapshot_name && @delete_all return usage_error("Invalid VMID: #{invalid_vmid}") if invalid_vmid return ExitCodes::SUCCESS unless confirm_operation perform_operation end |