Class: BeakerHostGenerator::Generator

Inherits:
Object
  • Object
show all
Includes:
Data, Parser, Roles
Defined in:
lib/beaker-hostgenerator/generator.rb

Constant Summary

Constants included from Roles

Roles::CM_CONFIG, Roles::ROLES, Roles::ROLE_CONFIG

Constants included from Parser

Parser::NODE_REGEX

Constants included from Data

Data::BASE_CONFIG, Data::MAIN_PE_VERSION, Data::PE_TARBALL_SERVER, Data::PE_USE_WIN32

Instance Method Summary collapse

Methods included from Roles

get_role_config

Methods included from Parser

is_ostype_token?, parse_node_info_token, prepare, settings_string_to_map, tokenize_layout

Methods included from Data

base_host_config, generate_osinfo, get_osinfo, get_platform_info, get_platforms, osinfo, osinfo_bhgv1, pe_dir, pe_upgrade_version, pe_version

Instance Method Details

#generate(layout, options) ⇒ Object

Main host generation entry point, returns a Ruby map for the given host specification and optional configuration.

Parameters:

  • layout (String)

    The raw hosts specification user input. For example ‘“centos9-64m-redhat7-64a”`.

  • options (Hash)

    Global, optional configuration such as the default hypervisor or OS info version.



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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/beaker-hostgenerator/generator.rb', line 22

def generate(layout, options)
  layout = prepare(layout)
  tokens = tokenize_layout(layout)
  config = {}.deeper_merge(BASE_CONFIG)
  nodeid = Hash.new(1)
  ostype = nil
  bhg_version = options[:osinfo_version] || 0

  tokens.each do |token|
    if is_ostype_token?(token, bhg_version)
      raise "Error: no nodes generated for #{ostype}" if nodeid[ostype] == 1 and !ostype.nil?

      ostype = token
      next
    end

    node_info = parse_node_info_token(token)

    # Build node host name
    platform = "#{ostype}-#{node_info['bits']}"
    host_name = "#{platform}-#{nodeid[ostype]}"

    node_info['platform'] = platform
    node_info['ostype'] = ostype
    node_info['nodeid'] = nodeid[ostype]

    host_config = base_host_config(options)

    # Delegate to the hypervisor
    hypervisor = BeakerHostGenerator::Hypervisor.create(node_info, options)
    host_config = hypervisor.generate_node(node_info, host_config, bhg_version)
    config['CONFIG'].deeper_merge!(hypervisor.global_config)

    # Merge in any arbitrary key-value host settings. Treat the 'hostname'
    # setting specially, and don't merge it in as an arbitrary setting.
    arbitrary_settings = node_info['host_settings']
    host_name = arbitrary_settings.delete('hostname') if
      arbitrary_settings.has_key?('hostname')
    host_config.merge!(arbitrary_settings)

    if PE_USE_WIN32 && ostype =~ /windows/ && node_info['bits'] == '64'
      host_config['ruby_arch'] = 'x86'
      host_config['install_32'] = true
    end

    generate_host_roles!(host_config, node_info, options)

    config['HOSTS'][host_name] = host_config
    nodeid[ostype] += 1
  end

  # Merge in global configuration settings after the hypervisor defaults
  if options[:global_config]
    decoded = prepare(options[:global_config])
    # Support for strings without '{}' was introduced, so just double
    # check here to ensure that we pass in values surrounded by '{}'.
    decoded = "{#{decoded}}" unless decoded.start_with?('{')
    global_config = settings_string_to_map(decoded)
    config['CONFIG'].deeper_merge!(global_config)
  end

  # Munge non-string scalar values into proper data types
  unstringify_values!(config)

  config
end

#get_host_roles(node_info) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/beaker-hostgenerator/generator.rb', line 89

def get_host_roles(node_info)
  roles = []

  node_info['roles'].each_char do |c|
    roles << ROLES[c]
  end

  node_info['arbitrary_roles'].each do |role|
    roles << role
  end

  roles
end