File: abs_support.rb

package info (click to toggle)
ruby-beaker-hostgenerator 1.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,556 kB
  • sloc: ruby: 3,059; makefile: 3
file content (30 lines) | stat: -rw-r--r-- 1,016 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module BeakerHostGenerator
  # Utility functions for supporting CI.next and the AlwaysBeScheduling hypervisor.
  module AbsSupport
    module_function

    # Given an existing, fully-specified host configuration, count the number of
    # hosts using each template, and return a map of template name to host count.
    #
    # For example, given the following config (parts omitted for brevity):
    #    {"HOSTS"=>
    #     {"centos6-64-1"=>
    #        {"template"=>"centos-6-x86_64", ...},
    #      "redhat7-64-1"=>
    #        {"template"=>"redhat-7-x86_64", ...},
    #      "centos6-64-2"=>
    #        {"template"=>"centos-6-x86_64", ...}},
    #     ...
    #    }}
    #
    # Returns the following map:
    #     {"centos-6-x86_64"=>2, "redhat-7-x86_64"=>1}
    #
    def extract_templates(config)
      templates_hosts = config['HOSTS'].values.group_by { |h| h['template'] }
      templates_hosts.each do |template, hosts|
        templates_hosts[template] = hosts.count
      end
    end
  end
end