Class: VpsAdminOS::Converter::Vz6::Migrator::Simfs

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

Direct Known Subclasses

Ploop

Instance Attribute Summary

Attributes inherited from Base

#progress_handler, #state

Instance Method Summary collapse

Methods inherited from Base

#cancel_remote, #export_skel, #initialize, #progress, #stage, #transfer_container

Constructor Details

This class inherits a constructor from VpsAdminOS::Converter::Vz6::Migrator::Base

Instance Method Details

#cancel(cmd_opts) ⇒ Object



32
33
34
35
# File 'lib/vpsadminos-converter/vz6/migrator/simfs.rb', line 32

def cancel(cmd_opts)
  cancel_remote(cmd_opts[:force])
  state.destroy
end

#cleanup(cmd_opts) ⇒ Object



27
28
29
30
# File 'lib/vpsadminos-converter/vz6/migrator/simfs.rb', line 27

def cleanup(cmd_opts)
  syscmd("vzctl destroy #{vz_ct.ctid}") if cmd_opts[:delete]
  state.destroy
end

#do_syncObject (protected)



49
50
51
52
# File 'lib/vpsadminos-converter/vz6/migrator/simfs.rb', line 49

def do_sync
  progress(:step, 'Synchronizing /')
  rsync("#{src_rootfs}/", "#{dst_rootfs}/", valid_rcs: [23, 24])
end

#dst_rootfsObject (protected)



43
44
45
46
47
# File 'lib/vpsadminos-converter/vz6/migrator/simfs.rb', line 43

def dst_rootfs
  @dst_rootfs ||= JSON.parse(
    root_sshcmd("osctl -j ct show #{target_ct.id}").output.strip
  )['rootfs']
end

#root_sshcmd(cmd) ⇒ Object (protected)



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vpsadminos-converter/vz6/migrator/simfs.rb', line 63

def root_sshcmd(cmd)
  args = [
    'ssh',
    '-o', 'StrictHostKeyChecking=no',
    '-T',
    '-p', opts[:port].to_s,
    '-l', 'root',
    opts[:dst],
    cmd
  ]

  syscmd(args.join(' '))
end

#rsync(src, dst, cmd_opts = {}) ⇒ Object (protected)



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

def rsync(src, dst, cmd_opts = {})
  syscmd(
    'rsync -rlptgoDHX --numeric-ids --inplace --delete-after --exclude .zfs/ ' \
    "-e \"ssh -p #{opts[:port]}\" " \
    "#{src} #{opts[:dst]}:#{dst}",
    cmd_opts
  )
end

#src_rootfsObject (protected)



39
40
41
# File 'lib/vpsadminos-converter/vz6/migrator/simfs.rb', line 39

def src_rootfs
  target_ct.rootfs
end

#sync(&block) ⇒ Object



6
7
8
9
10
11
# File 'lib/vpsadminos-converter/vz6/migrator/simfs.rb', line 6

def sync(&block)
  self.progress_handler = block
  do_sync
  state.set_step(:sync)
  state.save
end

#transfer(&block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vpsadminos-converter/vz6/migrator/simfs.rb', line 13

def transfer(&block)
  self.progress_handler = block

  # Stop the container
  running = vz_ct.running?
  syscmd("vzctl stop #{vz_ct.ctid}")

  # Second sync
  do_sync

  # Transfer to dst
  transfer_container(running)
end