Class: OsCtld::Migration::Commands::ReceiveBase

Inherits:
Base show all
Defined in:
lib/osctld/migration/commands/receive_base.rb

Instance Attribute Summary

Attributes inherited from Commands::Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods inherited from Base

handle

Methods inherited from Commands::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

#dataset_name(ct) ⇒ Object (protected)



42
43
44
45
46
47
48
# File 'lib/osctld/migration/commands/receive_base.rb', line 42

def dataset_name(ct)
  if opts[:dataset] == '/'
    ct.dataset.name
  else
    File.join(ct.dataset.name, opts[:dataset])
  end
end

#executeObject



7
8
9
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
# File 'lib/osctld/migration/commands/receive_base.rb', line 7

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

  ct.manipulate(self, block: true) do
    error!('this container is not staged') if ct.state != :staged

    if !ct.migration_log || !ct.migration_log.can_continue?(:base)
      error!('invalid migration sequence')
    end

    ds = OsCtl::Lib::Zfs::Dataset.new(dataset_name(ct), base: ct.dataset.name)
    error!('dataset does not exist') unless ds.exist?

    client.send({status: true, response: 'continue'}.to_json + "\n", 0)
    io = client.recv_io

    pid = Process.spawn('zfs', 'recv', '-F', ds.name, in: io)
    Process.wait(pid)

    if $?.exitstatus == 0
      ct.exclusively do
        ct.migration_log.state = :base
        ct.migration_log.snapshots << [ds.name, opts[:snapshot]] if opts[:snapshot]
        ct.save_config
      end

      ok
    else
      error("unable to receive stream, zfs recv exited with #{$?.exitstatus}")
    end
  end
end