Class: OsCtld::Commands::Container::SetImageConfig

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

Instance Method Summary collapse

Methods included from Utils::Container

#format_unavailable_repositories, #get_image_path, #get_image_path!, #get_repositories, #image_not_found_message, #image_spec, #image_unavailable_message, #remove_accounting_cgroups, #with_image_path, #with_repository_image_path!

Methods inherited from Logged

#base_execute

Instance Method Details

#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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/osctld/commands/container/set_image_config.rb', line 16

def execute(ct)
  manipulate(ct) do
    error!('container is running') if ct.running?

    tpl = opts[:image]
    image = {
      distribution: tpl[:distribution] || ct.distribution,
      version: tpl[:version] || ct.version,
      arch: tpl[:arch] || ct.arch,
      vendor: tpl[:vendor] || ct.vendor,
      variant: tpl[:variant] || ct.variant
    }

    with_image_path(ct.pool, type: opts[:type], path: opts[:path], image:) do |tpl_path|
      # Apply new image configuration
      progress('Applying configuration')
      fh = File.open(tpl_path, 'r')
      importer = Container::Importer.new(ct.pool, fh, ct_id: ct.id, image_file: tpl_path)
      importer.
      ct.patch_config(importer.get_container_config)
      fh.close
    end

    # If changed, update also distribution/version/arch info
    if tpl[:distribution] || tpl[:version] || tpl[:arch] || tpl[:vendor] || tpl[:variant]
      ct.set(distribution: {
        name: image[:distribution],
        version: image[:version],
        arch: image[:arch],
        vendor: image[:vendor],
        variant: image[:variant]
      })
    end

    ok
  end
end

#findObject



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

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