Class: OsCtld::Commands::Container::MigrateStage

Inherits:
Base
  • Object
show all
Includes:
OsCtl::Lib::Utils::Migration
Defined in:
lib/osctld/commands/container/migrate_stage.rb

Instance Attribute Summary

Attributes inherited from Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods inherited from Base

#base_execute, #call_cmd, #call_cmd!, cmd, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!

Constructor Details

This class inherits a constructor from OsCtld::Commands::Base

Instance Method Details

#executeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/osctld/commands/container/migrate_stage.rb', line 10

def execute
  ct = DB::Containers.find(opts[:id], opts[:pool])
  error!('container not found') unless ct

  manipulate(ct) do
    next error('this container is already being migrated') if ct.migration_log

    f = Tempfile.open("ct-#{ct.id}-skel")
    export(ct, f)
    f.seek(0)

    m_opts = {
      port: opts[:port] || 22,
      dst: opts[:dst],
    }

    ssh = migrate_ssh_cmd(
      ct.pool.migration_key_chain,
      m_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

    if $?.exitstatus == 0
      ct.open_migration_log(:source, m_opts)
      ok
    else
      error('stage failed')
    end
  end
end

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



49
50
51
52
53
54
55
# File 'lib/osctld/commands/container/migrate_stage.rb', line 49

def export(ct, io)
  exporter = OsCtl::Lib::Exporter::Base.new(ct, io)
  exporter.('skel')
  exporter.dump_configs
  exporter.dump_user_hook_scripts(Container::Hook.hooks)
  exporter.close
end