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

Inherits:
Object
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::Send, 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.



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

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)



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

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

  return unless ret.nil? || ($?.exitstatus != 0 && !nofail)

  raise 'cancel failed'
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)



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

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

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



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

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 = send_ssh_cmd(
    nil,
    opts,
    %w[receive skel]
  )

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

  f.close
  f.unlink

  raise '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)



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

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

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

  state.set_step(:transfer)
  state.save
end