Module: Pvectl::Commands::MoveDiskCommand
- Included in:
- MoveDiskContainer, MoveDiskVm
- Defined in:
- lib/pvectl/commands/move_disk_command.rb
Overview
Shared functionality for the move disk commands (move disk vm, move disk ct).
Mirrors the structure of MigrateCommand but operates on a single resource (VM or container) and a single disk/volume rather than a batch.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VALID_FORMATS =
Allowed target formats for VM disks (per Proxmox API).
%w[raw qcow2 vmdk].freeze
Class Method Summary collapse
-
.included(base) ⇒ Object
Hook called when the module is included.
Instance Method Summary collapse
-
#execute ⇒ Integer
Executes the move disk command.
-
#initialize(args, options, global_options) ⇒ Object
Initializes a move disk command.
Class Method Details
.included(base) ⇒ Object
Hook called when the module is included.
37 38 39 |
# File 'lib/pvectl/commands/move_disk_command.rb', line 37 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#execute ⇒ Integer
Executes the move disk command.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pvectl/commands/move_disk_command.rb', line 55 def execute target = @options[:target] return usage_error("--target is required") if target.nil? || target.to_s.empty? return usage_error("#{id_label} and #{disk_label} are required") if @args.size < 2 id_str, disk = @args[0], @args[1] unless id_str.to_s.match?(/\A\d+\z/) return usage_error("Invalid #{id_label}: #{id_str}") end if @options[:format] return usage_error("--format is not supported for containers") if resource_type_symbol == :container return usage_error("Invalid format: #{@options[:format]} (allowed: #{VALID_FORMATS.join(', ')})") unless VALID_FORMATS.include?(@options[:format]) end perform_operation(id_str.to_i, disk, target) end |
#initialize(args, options, global_options) ⇒ Object
Initializes a move disk command.
46 47 48 49 50 |
# File 'lib/pvectl/commands/move_disk_command.rb', line 46 def initialize(args, , ) @args = Array(args).compact @options = @global_options = end |