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.

Examples:

Including in a command class

class MoveDiskVm
  include MoveDiskCommand
  RESOURCE_TYPE = :vm
  SUPPORTED_RESOURCES = %w[vm].freeze
end

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

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Hook called when the module is included.

Parameters:

  • base (Class)

    the class including this module



37
38
39
# File 'lib/pvectl/commands/move_disk_command.rb', line 37

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#executeInteger

Executes the move disk command.

Returns:

  • (Integer)

    exit code



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.

Parameters:

  • args (Array<String>)

    command-positional args ([id, disk])

  • options (Hash)

    command options

  • global_options (Hash)

    global CLI options



46
47
48
49
50
# File 'lib/pvectl/commands/move_disk_command.rb', line 46

def initialize(args, options, global_options)
  @args = Array(args).compact
  @options = options
  @global_options = global_options
end