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



46
47
48
49
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 46

def cancel
  require_args!('ctid')
  perform_cancel(args[0])
end

#cleanupObject



41
42
43
44
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 41

def cleanup
  require_args!('ctid')
  perform_cleanup(args[0])
end

#nowObject



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

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'
      perform_cancel(args[0])
      return
    end
  end

  puts '* Performing initial synchronization'
  perform_sync(args[0])
  progressbar_done

  puts '* Transfering container to the destination'
  perform_transfer(args[0])
  progressbar_done

  puts '* Cleaning up'
  perform_cleanup(args[0])
ensure
  progressbar_done
end

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



84
85
86
87
88
89
90
91
92
93
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 84

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)



109
110
111
112
113
114
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 109

def progressbar_done
  return unless @pb

  @pb.finish
  @pb = nil
end

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



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 95

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

def sync
  require_args!('ctid')
  perform_sync(args[0])
ensure
  progressbar_done
end

#transferObject



34
35
36
37
38
39
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 34

def transfer
  require_args!('ctid')
  perform_transfer(args[0])
ensure
  progressbar_done
end