Class: VpsAdminOS::Converter::Vz6::Migrator::Base

Inherits:
Object
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::Migration, OsCtl::Lib::Utils::System
Defined in:
lib/vpsadminos-converter/vz6/migrator/base.rb

Direct Known Subclasses

Simfs, Zfs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state) ⇒ Base

Returns a new instance of Base



13
14
15
# File 'lib/vpsadminos-converter/vz6/migrator/base.rb', line 13

def initialize(state)
  @state = state
end

Instance Attribute Details

#progress_handlerObject (protected)

Returns the value of attribute progress_handler



63
64
65
# File 'lib/vpsadminos-converter/vz6/migrator/base.rb', line 63

def progress_handler
  @progress_handler
end

#stateObject (readonly)

Returns the value of attribute state



11
12
13
# File 'lib/vpsadminos-converter/vz6/migrator/base.rb', line 11

def state
  @state
end

Instance Method Details

#cancel(cmd_opts) ⇒ Object

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/vpsadminos-converter/vz6/migrator/base.rb', line 58

def cancel(cmd_opts)
  raise NotImplementedError
end

#cancel_remote(nofail) ⇒ Object (protected)



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/vpsadminos-converter/vz6/migrator/base.rb', line 88

def cancel_remote(nofail)
  ret = system(
    *migrate_ssh_cmd(
      nil,
      opts,
      ['receive', 'cancel', target_ct.id]
    )
  )

  if ret.nil? || $?.exitstatus != 0 && !nofail
    fail 'cancel failed'
  end
end

#cleanup(cmd_opts) ⇒ Object

Raises:

  • (NotImplementedError)


54
55
56
# File 'lib/vpsadminos-converter/vz6/migrator/base.rb', line 54

def cleanup(cmd_opts)
  raise NotImplementedError
end

#export_skel(ct, io) ⇒ Object (protected)



65
66
67
68
69
70
# File 'lib/vpsadminos-converter/vz6/migrator/base.rb', line 65

def export_skel(ct, io)
  exporter = Exporter::Base.new(ct, io)
  exporter.('skel')
  exporter.dump_configs
  exporter.close
end

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



102
103
104
105
# File 'lib/vpsadminos-converter/vz6/migrator/base.rb', line 102

def progress(type, value)
  return unless progress_handler
  progress_handler.call(type, value)
end

#stageObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vpsadminos-converter/vz6/migrator/base.rb', line 21

def stage
  f = Tempfile.open("ct-#{target_ct.id}-skel")
  export_skel(target_ct, f)
  f.seek(0)

  opts[:port] ||= 22

  ssh = migrate_ssh_cmd(
    nil,
    opts,
    ['receive', 'skel']
  )

  IO.popen("exec #{ssh.join(' ')}", 'r+') do |io|
    io.write(f.readpartial(16*1024)) until f.eof?
  end

  f.close
  f.unlink

  fail 'stage failed' if $?.exitstatus != 0

  state.save
end

#syncObject

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/vpsadminos-converter/vz6/migrator/base.rb', line 46

def sync
  raise NotImplementedError
end

#transferObject

Raises:

  • (NotImplementedError)


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

def transfer
  raise NotImplementedError
end

#transfer_container(start) ⇒ Object (protected)



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/vpsadminos-converter/vz6/migrator/base.rb', line 72

def transfer_container(start)
  progress(:step, 'Starting on the target node')
  ret = system(
    *migrate_ssh_cmd(
      nil,
      opts,
      ['receive', 'transfer', target_ct.id] + (start ? ['start'] : [])
    )
  )

  fail 'transfer failed' if ret.nil? || $?.exitstatus != 0

  state.set_step(:transfer)
  state.save
end