Class: VpsAdmin::CLI::Commands::VpsMigrateMany
- Inherits:
-
HaveAPI::CLI::Command
- Object
- HaveAPI::CLI::Command
- VpsAdmin::CLI::Commands::VpsMigrateMany
- Defined in:
- lib/vpsadmin/cli/commands/vps_migrate_many.rb
Instance Method Summary collapse
Instance Method Details
#exec(args) ⇒ Object
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 |
# File 'lib/vpsadmin/cli/commands/vps_migrate_many.rb', line 43 def exec(args) if args.size < 2 puts 'provide at least two VPS IDs' exit(false) elsif @opts[:dst_node].nil? puts 'provide --dst-node' exit(false) end puts 'Verifying VPS IDs...' vpses = [] args.each do |vps_id| if /^\d+$/ !~ vps_id puts "'#{vps_id}' is not a valid VPS ID" exit(false) end vpses << vps_id.to_i end plan = nil begin if @opts[:plan] puts 'Reusing an existing migration plan...' plan = @api.migration_plan.find(@opts[:plan]) if plan.state != 'staged' puts 'Cannot reuse a plan that has already left the staging phase' exit(false) end else puts 'Creating a migration plan...' plan = @api.migration_plan.create(@opts) end rescue HaveAPI::Client::ActionFailed => e report_error(e) end puts 'Scheduling VPS migrations...' begin vpses.each do |vps_id| params = { vps: vps_id, dst_node: @opts[:dst_node] } params[:outage_window] = @opts[:outage_window] unless @opts[:outage_window].nil? params[:cleanup_data] = @opts[:cleanup_data] unless @opts[:cleanup_data].nil? plan.vps_migration.create(params) end rescue HaveAPI::Client::ActionFailed => e report_error(e) end puts 'Executing the migration plan' begin ret = plan.start rescue HaveAPI::Client::ActionFailed => e report_error(e) end HaveAPI::CLI::OutputFormatter.print(ret.attributes) end |
#options(opts) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vpsadmin/cli/commands/vps_migrate_many.rb', line 7 def (opts) @opts = {} opts.on('--migration-plan PLAN_ID', 'Reuse existing migration plan') do |id| @opts[:plan] = id end opts.on('--dst-node NODE_ID', 'Destination node') do |id| @opts[:dst_node] = id.to_i end opts.on('--[no-]outage-window', 'Migrate VPSes inside outage windows') do |w| @opts[:outage_window] = w end opts.on('--[no-]cleanup-data', 'Cleanup VPS dataset on the source node') do |c| @opts[:cleanup_data] = c end opts.on('--[no-]stop-on-error', 'Cancel the plan if a migration fails') do |s| @opts[:stop_on_error] = s end opts.on('--concurrency N', 'How many migrations run concurrently') do |n| @opts[:concurrency] = n.to_i end opts.on('--[no-]send-mail', 'Send users mail informing about the migration') do |s| @opts[:send_mail] = s end opts.on('--reason REASON', 'Why are the VPS being migrated') do |r| @opts[:reason] = r end end |