Class: Pvectl::Commands::MigrateVm
- Inherits:
-
Object
- Object
- Pvectl::Commands::MigrateVm
- Includes:
- MigrateCommand
- Defined in:
- lib/pvectl/commands/migrate_vm.rb,
sig/pvectl/commands/migrate_vm.rbs
Overview
Handler for the pvectl migrate vm command.
Migrates one or more virtual machines to another cluster node. Always requires --target and confirmation (--yes to skip).
Constant Summary collapse
- RESOURCE_TYPE =
:vm- SUPPORTED_RESOURCES =
%w[vm].freeze
Constants included from MigrateCommand
Pvectl::Commands::MigrateCommand::NODE_NAME_FORMAT
Class Method Summary collapse
-
.register(cli) ⇒ void
Registers the migrate command with the CLI.
Methods included from MigrateCommand
#apply_selectors, #confirm_operation, #determine_exit_code, #execute, included, #initialize, #load_config, #no_resources_found, #output_results, #perform_operation, #resolve_resources, #resource_type_symbol, #restart_not_allowed?, #selector_strings, #service_options, #usage_error
Class Method Details
.register(cli) ⇒ void
This method returns an undefined value.
Registers the migrate command with the CLI.
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/pvectl/commands/migrate_vm.rb', line 23 def self.register(cli) cli.desc "Migrate a resource to another node" cli.long_desc " Migrate virtual machines or containers between cluster nodes.\n Supports live migration (--online) for zero-downtime moves.\n\n EXAMPLES\n Offline migration:\n $ pvectl migrate vm 100 --target pve2\n\n Live migration (zero downtime):\n $ pvectl migrate vm 100 --target pve2 --online\n\n Migrate a container with restart:\n $ pvectl migrate ct 200 --target pve2 --restart\n\n Migrate to different storage:\n $ pvectl migrate vm 100 --target pve2 --target-storage local-lvm\n\n Batch migrate all VMs from a node:\n $ pvectl migrate vm --all --node pve1 --target pve2 --yes\n\n Migrate VMs matching a selector:\n $ pvectl migrate vm --all -l tags=web --target pve2 --yes\n\n NOTES\n --online (live migration) requires shared storage or migration\n network configured between nodes.\n\n Container migration with --restart briefly stops the container,\n migrates, then starts it on the target node.\n\n --target is required for all migrations.\n\n Default timeout is 600 seconds. Use --timeout to adjust for\n large VMs with lots of memory/disk.\n\n SEE ALSO\n pvectl help clone Clone instead of move\n pvectl help get nodes List available target nodes\n HELP\n cli.arg_name \"RESOURCE_TYPE [ID...]\"\n cli.command :migrate do |c|\n c.desc \"Target node (required)\"\n c.flag [:target, :t], arg_name: \"NODE\"\n\n c.desc \"Online/live migration\"\n c.switch [:online], negatable: false\n\n c.desc \"Restart migration (container only)\"\n c.switch [:restart], negatable: false\n\n c.desc \"Target storage mapping\"\n c.flag [:\"target-storage\"], arg_name: \"STORAGE\"\n\n c.desc \"Select all resources of this type\"\n c.switch [:all, :A], negatable: false\n\n c.desc \"Filter by source node\"\n c.flag [:node, :n], arg_name: \"NODE\"\n\n c.desc \"Filter by selector (e.g., status=running,tags=prod)\"\n c.flag [:l, :selector], arg_name: \"SELECTOR\", multiple: true\n\n c.desc \"Skip confirmation prompt\"\n c.switch [:yes, :y], negatable: false\n\n c.desc \"Stop on first error\"\n c.switch [:\"fail-fast\"], negatable: false\n\n c.desc \"Wait for migration to complete (sync mode)\"\n c.switch [:wait], negatable: false\n\n c.desc \"Timeout in seconds for sync operations (default: 600)\"\n c.flag [:timeout], type: Integer, arg_name: \"SECONDS\"\n\n c.action do |global_options, options, args|\n resource_type = args.shift\n\n exit_code = case resource_type\n when \"vm\"\n Commands::MigrateVm.execute(args, options, global_options)\n when \"container\", \"ct\"\n Commands::MigrateContainer.execute(args, options, global_options)\n else\n $stderr.puts \"Error: Unknown resource type: \#{resource_type}\"\n $stderr.puts \"Valid types: vm, container, ct\"\n ExitCodes::USAGE_ERROR\n end\n\n exit exit_code if exit_code != 0\n end\n end\nend\n" |