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

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

Instance Attribute Summary

Attributes inherited from Command

#args, #gopts, #opts

Instance Method Summary collapse

Methods inherited from Base

#convert_ct, #exporter_class, #print_convert_status

Methods inherited from Command

#initialize, #require_args!, run

Constructor Details

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

Instance Method Details

#cancelObject



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

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

  migrator.cancel(opts)
end

#cleanupObject



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

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

  migrator.cleanup(opts)
end

#nowObject



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

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)



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

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)



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

def progressbar_done
  return unless @pb
  @pb.finish
  @pb = nil
end

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



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

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 ? current : total
  @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
36
# File 'lib/vpsadminos-converter/cli/vz6/migrate.rb', line 27

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

  migrator.sync(&method(:progress))

ensure
  progressbar_done
end

#transferObject



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

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

  migrator.transfer(&method(:progress))

ensure
  progressbar_done
end