Module: OsCtld::Utils::Container

Instance Method Summary collapse

Instance Method Details

#get_image_path(repos, tpl) ⇒ String?

Parameters:

Options Hash (tpl):

  • :distribution (String)
  • :version (String)
  • :arch (String)
  • :vendor (String)
  • :variant (String)

Returns:

  • (String, nil)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/osctld/utils/container.rb', line 28

def get_image_path(repos, tpl)
  repos.each do |repo|
    osctl_repo = OsCtlRepo.new(repo)

    begin
      %i[zfs tar].each do |format|
        path = osctl_repo.get_image_path(tpl, format)
        return path if path
      end
    rescue ImageNotFound, ImageRepositoryUnavailable
      next
    end
  end

  nil
end

#get_repositories(pool) ⇒ Array<Repository>

Parameters:

Returns:



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/osctld/utils/container.rb', line 7

def get_repositories(pool)
  if opts[:repository]
    repo = DB::Repositories.find(opts[:repository], pool)
    error!('repository not found') unless repo
    [repo]

  else
    DB::Repositories.get.select do |repo|
      repo.enabled? && repo.pool == pool
    end
  end
end

#remove_accounting_cgroups(ct) ⇒ Object

Remove accounting cgroups to reset counters



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/osctld/utils/container.rb', line 46

def remove_accounting_cgroups(ct)
  tries = 0

  begin
    %w[cpuacct cpuset memory].each do |subsys|
      CGroup.rmpath(subsys, ct.base_cgroup_path)
    end
  rescue SystemCallError => e
    ct.log(:warn, "Error occurred while pruning cgroups: #{e.message}")

    return if tries >= 5

    tries += 1
    sleep(0.5)
    retry
  end
end