Class: Pvectl::Commands::CreateSnapshot
- Inherits:
-
Object
- Object
- Pvectl::Commands::CreateSnapshot
- Defined in:
- lib/pvectl/commands/create_snapshot.rb
Overview
Handler for the ‘pvectl create snapshot` sub-command.
Creates snapshots for VMs/containers. Snapshot name is the first positional argument, VMIDs are specified via –vmid flag. Without –vmid, operates on ALL VMs/CTs in the cluster.
Constant Summary collapse
- VMID_PATTERN =
/\A[1-9]\d{0,8}\z/
Class Method Summary collapse
-
.execute(args, options, global_options) ⇒ Integer
Executes the create snapshot command.
-
.register_subcommand(parent) ⇒ void
Registers as a sub-command under the parent create command.
Instance Method Summary collapse
-
#execute ⇒ Integer
Executes the create snapshot command.
-
#initialize(args, options, global_options) ⇒ CreateSnapshot
constructor
Initializes a create snapshot command.
Constructor Details
#initialize(args, options, global_options) ⇒ CreateSnapshot
Initializes a create snapshot command.
86 87 88 89 90 91 92 93 |
# File 'lib/pvectl/commands/create_snapshot.rb', line 86 def initialize(args, , ) @args = Array(args) @options = @global_options = @snapshot_name = @args.first @vmids = parse_vmids([:vmid]) @node = [:node] end |
Class Method Details
.execute(args, options, global_options) ⇒ Integer
Executes the create snapshot command.
77 78 79 |
# File 'lib/pvectl/commands/create_snapshot.rb', line 77 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 create 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 66 67 68 69 |
# File 'lib/pvectl/commands/create_snapshot.rb', line 27 def self.register_subcommand(parent) parent.desc "Create a snapshot of VMs or containers" parent.long_desc <<~HELP Create a snapshot of one or more VMs or containers. Snapshots capture the current state of disks (and optionally RAM) for later rollback. EXAMPLES Snapshot a single VM: $ pvectl create snapshot before-upgrade --vmid 100 Snapshot multiple VMs: $ pvectl create snapshot before-upgrade --vmid 100 --vmid 101 Snapshot with description and VM memory state: $ pvectl create snapshot before-upgrade --vmid 100 --description "Pre-upgrade" --vmstate Snapshot all VMs/containers cluster-wide: $ pvectl create snapshot before-upgrade --yes NOTES --vmstate saves the VM's RAM state (QEMU only, not for containers). This increases snapshot size but allows resuming from exact state. Without --vmid, operates cluster-wide (requires --yes confirmation). SEE ALSO pvectl help rollback Rollback to a snapshot pvectl help delete snapshot Delete snapshots 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.desc "Save VM memory state (QEMU only)" s.switch [:vmstate], negatable: false 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 create snapshot command.
98 99 100 101 102 103 |
# File 'lib/pvectl/commands/create_snapshot.rb', line 98 def execute return usage_error("Snapshot name required") unless @snapshot_name return usage_error("Invalid VMID: #{invalid_vmid}") if invalid_vmid perform_operation end |