Class: OsCtld::SendReceive::Commands::ReceiveCancel

Inherits:
Base show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System, Utils::Receive
Defined in:
lib/osctld/send_receive/commands/receive_cancel.rb

Instance Attribute Summary

Attributes inherited from Commands::Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods included from Utils::Receive

#check_auth_pubkey

Methods inherited from Base

handle

Methods inherited from Commands::Base

#base_execute, #call_cmd, #call_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



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
# File 'lib/osctld/send_receive/commands/receive_cancel.rb', line 11

def execute
  ct = SendReceive::Tokens.find_container(opts[:token])
  error!('container not found') unless ct

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

    if !ct.send_log || !ct.send_log.can_receive_cancel?
      error!('invalid send sequence')
    elsif !check_auth_pubkey(opts[:key_pool], opts[:key_name], ct)
      error!('authentication key mismatch')
    end

    ct.send_log.snapshots.each do |v|
      ds, snap = v
      zfs(:destroy, nil, "#{ds}@#{snap}")
    end

    SendReceive.stopped_using_key(ct.pool, ct.send_log.opts.key_name)
    ct.close_send_log

    call_cmd!(
      Commands::Container::Delete,
      id: ct.id,
      pool: ct.pool.name
    )
  end

  ok
end