Module: OsCtld::Utils::Container
- Included in:
- Commands::Container::Boot, Commands::Container::Create, Commands::Container::Reinstall, Commands::Container::SetImageConfig, Commands::Container::Start, Commands::Container::Stop, SendReceive::Commands::Transfer
- Defined in:
- lib/osctld/utils/container.rb
Instance Method Summary collapse
- #format_unavailable_repositories(unavailable) ⇒ Object
- #get_image_path(repos, tpl) ⇒ Array<String, Hash<String, String>>
- #get_image_path!(repos, tpl) ⇒ String
- #get_repositories(pool) ⇒ Array<Repository>
- #image_not_found_message(tpl, repos) ⇒ Object
- #image_spec(tpl) ⇒ Object
- #image_unavailable_message(tpl, unavailable) ⇒ Object
-
#remove_accounting_cgroups(ct) ⇒ Object
Remove accounting cgroups to reset counters.
Instance Method Details
#format_unavailable_repositories(unavailable) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/osctld/utils/container.rb', line 78 def format_unavailable_repositories(unavailable) unavailable.map do |name, | if && !.empty? "#{name} (#{})" else name end end.join(', ') end |
#get_image_path(repos, tpl) ⇒ Array<String, Hash<String, String>>
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/osctld/utils/container.rb', line 28 def get_image_path(repos, tpl) unavailable = {} 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, unavailable] if path end rescue ImageNotFound next rescue ImageRepositoryUnavailable => e unavailable[repo.name] = e. next end end [nil, unavailable] end |
#get_image_path!(repos, tpl) ⇒ String
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/osctld/utils/container.rb', line 53 def get_image_path!(repos, tpl) if repos.empty? error!('no enabled repositories are available for container images') end path, unavailable = get_image_path(repos, tpl) return path if path if unavailable.any? error!((tpl, unavailable)) end error!((tpl, repos)) end |
#get_repositories(pool) ⇒ Array<Repository>
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 |
#image_not_found_message(tpl, repos) ⇒ Object
68 69 70 71 |
# File 'lib/osctld/utils/container.rb', line 68 def (tpl, repos) "container image #{image_spec(tpl)} not found in repositories: " \ "#{repos.map(&:name).join(', ')}" end |
#image_spec(tpl) ⇒ Object
88 89 90 91 92 |
# File 'lib/osctld/utils/container.rb', line 88 def image_spec(tpl) "#{tpl[:distribution]}:#{tpl[:version]} " \ "(arch=#{tpl[:arch]}, vendor=#{tpl[:vendor]}, " \ "variant=#{tpl[:variant]})" end |
#image_unavailable_message(tpl, unavailable) ⇒ Object
73 74 75 76 |
# File 'lib/osctld/utils/container.rb', line 73 def (tpl, unavailable) "unable to fetch container image #{image_spec(tpl)}; repositories " \ "unavailable: #{format_unavailable_repositories(unavailable)}" end |
#remove_accounting_cgroups(ct) ⇒ Object
Remove accounting cgroups to reset counters
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/osctld/utils/container.rb', line 95 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.}") return if tries >= 5 tries += 1 sleep(0.5) retry end end |