Class: OsCtld::Commands::Container::Copy

Inherits:
Logged
  • Object
show all
Defined in:
lib/osctld/commands/container/copy.rb

Instance Attribute Summary

Attributes inherited from Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods inherited from Logged

#base_execute

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

#config_opts(ct) ⇒ Object (protected)



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/osctld/commands/container/copy.rb', line 42

def config_opts(ct)
  {
    id: ct.id,
    pool: ct.pool.name,
    target_pool: opts[:target_pool],
    target_id: opts[:target_id],
    target_user: opts[:target_user],
    target_group: opts[:target_group],
    target_dataset: opts[:target_dataset],
    network_interfaces: opts[:network_interfaces]
  }
end

#execute(ct) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/osctld/commands/container/copy.rb', line 16

def execute(ct)
  manipulate(ct) do
    progress(type: :step, title: 'Preparing copy')
    call_cmd!(Commands::Container::CopyConfig, **config_opts(ct))

    progress(type: :step, title: 'Copying rootfs')
    call_cmd!(Commands::Container::CopyRootfs, id: ct.id, pool: ct.pool.name)

    progress(type: :step, title: 'Copying state')
    call_cmd!(
      Commands::Container::CopyState,
      id: ct.id,
      pool: ct.pool.name,
      consistent: opts.fetch(:consistent, true),
      restart: opts.fetch(:restart, true)
    )

    progress(type: :step, title: 'Cleaning up')
    call_cmd!(Commands::Container::CopyCleanup, id: ct.id, pool: ct.pool.name)
  end

  ok
end

#findObject



11
12
13
14
# File 'lib/osctld/commands/container/copy.rb', line 11

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