Module: Beaker::Options::HostsFileParser
- Defined in:
- lib/beaker/options/hosts_file_parser.rb
Overview
A set of functions to parse hosts files
Class Method Summary collapse
-
.fix_roles_array(host_options) ⇒ Object
Make sure the roles array is present for all hosts.
-
.merge_hosts_yaml(host_options, error_message, &block) ⇒ OptionsHash
Merges YAML read in the passed block into given OptionsHash.
-
.new_host_options ⇒ OptionsHash
Convenience method to create new OptionsHashes with a HOSTS section.
-
.parse_hosts_file(hosts_file_path = nil) ⇒ OptionsHash
Read the contents of the hosts.cfg into an OptionsHash, merge the ‘CONFIG’ section into the OptionsHash, return OptionsHash.
-
.parse_hosts_string(hosts_def_yaml = nil) ⇒ OptionsHash
Read the contents of a host definition as a string into an OptionsHash.
Class Method Details
.fix_roles_array(host_options) ⇒ Object
Make sure the roles array is present for all hosts
54 55 56 57 58 59 60 61 62 |
# File 'lib/beaker/options/hosts_file_parser.rb', line 54 def self.fix_roles_array( ) ['HOSTS'].each_key do |host| ['HOSTS'][host]['roles'] ||= [] end if .has_key?('CONFIG') = .merge(.delete('CONFIG')) end end |
.merge_hosts_yaml(host_options, error_message, &block) ⇒ OptionsHash
Merges YAML read in the passed block into given OptionsHash
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/beaker/options/hosts_file_parser.rb', line 70 def self.merge_hosts_yaml( , , &block ) begin = yield rescue Psych::SyntaxError => e << e.to_s raise ArgumentError, end .merge( ) end |
.new_host_options ⇒ OptionsHash
Convenience method to create new OptionsHashes with a HOSTS section
46 47 48 49 50 |
# File 'lib/beaker/options/hosts_file_parser.rb', line 46 def self. = Beaker::Options::OptionsHash.new ['HOSTS'] ||= {} end |
.parse_hosts_file(hosts_file_path = nil) ⇒ OptionsHash
Read the contents of the hosts.cfg into an OptionsHash, merge the ‘CONFIG’ section into the OptionsHash, return OptionsHash
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/beaker/options/hosts_file_parser.rb', line 16 def self.parse_hosts_file(hosts_file_path = nil) = return unless hosts_file_path = "#{hosts_file_path} is not a valid YAML file\n\t" = self.merge_hosts_yaml( , ) { hosts_file_path = File.( hosts_file_path ) YAML.load_file( hosts_file_path ) } fix_roles_array( ) end |
.parse_hosts_string(hosts_def_yaml = nil) ⇒ OptionsHash
Read the contents of a host definition as a string into an OptionsHash
33 34 35 36 37 38 39 40 41 |
# File 'lib/beaker/options/hosts_file_parser.rb', line 33 def self.parse_hosts_string(hosts_def_yaml = nil) = return unless hosts_def_yaml = "#{hosts_def_yaml}\nis not a valid YAML string\n\t" = self.merge_hosts_yaml( , ) { YAML.load( hosts_def_yaml ) } fix_roles_array( ) end |