Module: Pvectl::Commands::MigrateCommand

Included in:
MigrateContainer, MigrateVm
Defined in:
lib/pvectl/commands/migrate_command.rb

Overview

Shared functionality for migrate commands (migrate vm, migrate container).

This module extracts common code used by MigrateVm and MigrateContainer. Pattern: identical to DeleteCommand module but with migrate-specific behavior:

  • Requires –target flag (no default)

  • Validates –restart only for containers

  • Async is default (no –async flag), –wait for sync

  • partition_by_target logic is in Service layer

Examples:

Including in a command class

class MigrateVm
  include MigrateCommand
  RESOURCE_TYPE = :vm
  SUPPORTED_RESOURCES = %w[vm].freeze
end

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

NODE_NAME_FORMAT =

Valid Proxmox node name format: lowercase alphanumeric, starting with letter, hyphens allowed.

/\A[a-z][a-z0-9-]*\z/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Hook called when module is included.

Parameters:

  • base (Class)

    the class including this module



41
42
43
# File 'lib/pvectl/commands/migrate_command.rb', line 41

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

Instance Method Details

#executeInteger

Executes the migrate command.

Returns:

  • (Integer)

    exit code



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pvectl/commands/migrate_command.rb', line 59

def execute
  target = @options[:target]
  return usage_error("--target is required") if target.nil? || target.empty?

  unless target.match?(NODE_NAME_FORMAT)
    return usage_error("Invalid target node name: #{target}")
  end

  return usage_error("--restart is only supported for containers") if restart_not_allowed?

  if @resource_ids.empty? && !@options[:all] && selector_strings.empty?
    return usage_error("VMID, --all, or -l selector required")
  end

  perform_operation
end

#initialize(args, options, global_options) ⇒ Object

Initializes a migrate command.

Parameters:

  • args (Array<String>)

    resource identifiers

  • options (Hash)

    command options

  • global_options (Hash)

    global CLI options



50
51
52
53
54
# File 'lib/pvectl/commands/migrate_command.rb', line 50

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