Class: OsCtld::Commands::Container::Create

Inherits:
Logged
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System, Utils::Container
Defined in:
lib/osctld/commands/container/create.rb

Instance Attribute Summary

Attributes inherited from Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods included from Utils::Container

#get_image_path, #get_repositories, #remove_accounting_cgroups

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

#execute(pool) ⇒ Object



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
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/osctld/commands/container/create.rb', line 18

def execute(pool)
  if DB::Containers.find(opts[:id], pool)
    error!("container #{pool.name}:#{opts[:id]} already exists")
  end

  if opts[:user]
    user = DB::Users.find(opts[:user], pool)
    error!('user not found') unless user
  end

  if opts[:group]
    group = DB::Groups.find(opts[:group], pool)
    error!('group not found') unless group
  end

  if !opts[:image].is_a?(::Hash)
    error!('invalid input')

  elsif !opts[:image][:distribution]
    error!('provide distribution')

  elsif !opts[:image][:version]
    error!('provide distribution version')

  elsif !opts[:image][:arch]
    error!('provide architecture')
  end

  progress('Fetching image')
  tpl_path = get_image_path(get_repositories(pool), opts[:image])
  error!('image not found in searched repositories') if tpl_path.nil?

  call_cmd!(
    Commands::Container::Import,
    pool: pool.name,
    as_id: opts[:id],
    as_user: opts[:user],
    as_group: opts[:group],
    dataset: opts[:dataset],
    file: tpl_path
  )
end

#findObject



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

def find
  pool = DB::Pools.get_or_default(opts[:pool])
  error!('pool not found') unless pool

  pool
end