Class: Pvectl::Commands::RollbackSnapshot
- Inherits:
-
Object
- Object
- Pvectl::Commands::RollbackSnapshot
- Defined in:
- lib/pvectl/commands/rollback_snapshot.rb
Overview
Handler for the ‘pvectl rollback snapshot` command.
Rolls back a VM/container to a snapshot. Requires –yes flag for confirmation. Only supports single VMID.
Constant Summary collapse
- SUPPORTED_RESOURCES =
%w[snapshot].freeze
Class Method Summary collapse
-
.execute(resource_type, args, options, global_options) ⇒ Integer
Executes the rollback snapshot command.
-
.register(cli) ⇒ void
Registers the rollback command with the CLI.
Instance Method Summary collapse
-
#execute ⇒ Integer
Executes the rollback snapshot command.
-
#initialize(resource_type, args, options, global_options) ⇒ RollbackSnapshot
constructor
Initializes a rollback snapshot command.
Constructor Details
#initialize(resource_type, args, options, global_options) ⇒ RollbackSnapshot
Initializes a rollback snapshot command.
98 99 100 101 102 103 104 105 |
# File 'lib/pvectl/commands/rollback_snapshot.rb', line 98 def initialize(resource_type, args, , ) @resource_type = resource_type @args = Array(args).compact @options = @global_options = @too_many_args = false parse_args! end |
Class Method Details
.execute(resource_type, args, options, global_options) ⇒ Integer
Executes the rollback snapshot command.
88 89 90 |
# File 'lib/pvectl/commands/rollback_snapshot.rb', line 88 def self.execute(resource_type, args, , ) new(resource_type, args, , ).execute end |
.register(cli) ⇒ void
This method returns an undefined value.
Registers the rollback command with the CLI.
21 22 23 24 25 26 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 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pvectl/commands/rollback_snapshot.rb', line 21 def self.register(cli) cli.desc "Rollback to a snapshot" cli.long_desc <<~HELP Rollback a virtual machine or container to a previous snapshot, restoring its disk (and optionally RAM) state to the snapshot point. WARNING: All changes made after the snapshot will be lost. EXAMPLES Rollback a VM to a snapshot: $ pvectl rollback snapshot 100 before-upgrade --yes Rollback and start the VM after: $ pvectl rollback snapshot 100 before-upgrade --yes --start Async rollback: $ pvectl rollback snapshot 100 before-upgrade --yes --async NOTES Rollback always operates on a single VM/container (not batch). The VM/container will be stopped during rollback if running. --yes is required — rollback is a destructive operation that discards all changes since the snapshot. SEE ALSO pvectl help create snapshot Create a snapshot before changes pvectl help get snapshots List available snapshots pvectl help describe snapshot View snapshot details HELP cli.arg_name "RESOURCE_TYPE ID SNAPSHOT_NAME" cli.command :rollback do |c| c.desc "Skip confirmation prompt (REQUIRED for destructive operations)" c.switch [:yes, :y], negatable: false c.desc "Start VM/container after rollback (LXC only)" c.switch [:start], 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.action do |, , args| resource_type = args.shift exit_code = Commands::RollbackSnapshot.execute( resource_type, args, , ) exit exit_code if exit_code != 0 end end end |
Instance Method Details
#execute ⇒ Integer
Executes the rollback snapshot command.
110 111 112 113 114 115 116 117 118 |
# File 'lib/pvectl/commands/rollback_snapshot.rb', line 110 def execute return usage_error("Resource type required (snapshot)") unless @resource_type return usage_error("Unsupported resource: #{@resource_type}") unless SUPPORTED_RESOURCES.include?(@resource_type) return usage_error("Rollback supports only single VMID") if @too_many_args return usage_error("VMID and snapshot name required") if @vmid.nil? || @snapshot_name.nil? return usage_error("Confirmation required: use --yes to confirm rollback") unless @options[:yes] perform_operation end |