Class: VpsAdminOS::Converter::Cli::Vz6::Migrate

Inherits:
Base
  • Object
show all
Defined in:
lib/vpsadminos-converter/cli/vz6/migrate.rb

Instance Method Summary collapse

Methods inherited from Base

#convert_ct, #exporter_class, #print_convert_status

Methods inherited from Command

#initialize, run

Constructor Details

This class inherits a constructor from VpsAdminOS::Converter::Cli::Command

Instance Method Details

#cancelObject



55
56
57
58
59
60
61
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 55

def cancel
  require_args!('ctid')
  migrator = Vz6::Migrator.load(args[0])
  raise 'invalid migration sequence' unless migrator.can_proceed?(:cancel)

  migrator.cancel(opts)
end

#cleanupObject



47
48
49
50
51
52
53
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 47

def cleanup
  require_args!('ctid')
  migrator = Vz6::Migrator.load(args[0])
  raise 'invalid migration sequence' unless migrator.can_proceed?(:cleanup)

  migrator.cleanup(opts)
end

#nowObject



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
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 63

def now
  require_args!('ctid', 'dst')

  puts '* Staging migration'
  stage

  unless opts[:proceed]
    $stdout.write('Do you wish to continue? [y/N]: ')
    $stdout.flush

    if $stdin.readline.strip.downcase != 'y'
      puts '* Cancelling migration'
      cancel
      return
    end
  end

  puts '* Performing initial synchronization'
  sync

  puts '* Transfering container to the destination'
  transfer

  puts '* Cleaning up'
  cleanup
end

#progress(type, value) ⇒ Object (protected)



92
93
94
95
96
97
98
99
100
101
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 92

def progress(type, value)
  case type
  when :step
    progressbar_done
    puts "> #{value}"

  when :transfer
    progressbar_update(value[0], value[1])
  end
end

#progressbar_doneObject (protected)



117
118
119
120
121
122
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 117

def progressbar_done
  return unless @pb

  @pb.finish
  @pb = nil
end

#progressbar_update(total, current) ⇒ Object (protected)



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 103

def progressbar_update(total, current)
  @pb ||= ProgressBar.create(
    title: 'Copying',
    total: nil,
    format: "%E %t #{(total / 1024.0).round(2)} GB: [%B] %p%% %r MB/s",
    throttle_rate: 0.2,
    starting_at: 0,
    autofinish: false,
    output: $stdout
  )
  @pb.total = [current, total].max
  @pb.progress = current
end

#stageObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 7

def stage
  require_args!('ctid', 'dst')

  vz_ct, target_ct = convert_ct(args[0])
  migrator = Vz6::Migrator.create(vz_ct, target_ct, {
    dst: args[1],
    port: opts[:port],
    zfs: opts[:zfs],
    zfs_dataset: opts['zfs-dataset'],
    zfs_subdir: opts['zfs-subdir'],
    zfs_compressed_send: opts['zfs-compressed-send']
  })
  migrator.stage

  print_convert_status(vz_ct)
  puts
  puts 'Migration stage successful'
  puts 'Continue with vz6 migrate sync, or abort with vz6 migrate cancel'
end

#syncObject



27
28
29
30
31
32
33
34
35
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 27

def sync
  require_args!('ctid')
  migrator = Vz6::Migrator.load(args[0])
  raise 'invalid migration sequence' unless migrator.can_proceed?(:sync)

  migrator.sync(&method(:progress))
ensure
  progressbar_done
end

#transferObject



37
38
39
40
41
42
43
44
45
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 37

def transfer
  require_args!('ctid')
  migrator = Vz6::Migrator.load(args[0])
  raise 'invalid migration sequence' unless migrator.can_proceed?(:transfer)

  migrator.transfer(&method(:progress))
ensure
  progressbar_done
end