Class: BeakerHostGenerator::CLI

Inherits:
Object
  • Object
show all
Includes:
Data
Defined in:
lib/beaker-hostgenerator/cli.rb

Constant Summary

Constants included from Data

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Data

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

Constructor Details

#initialize(argv = ARGV.dup) ⇒ CLI



15
16
17
18
19
20
21
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/beaker-hostgenerator/cli.rb', line 15

def initialize(argv = ARGV.dup)
  @options = {
    list_platforms_and_roles: false,
    disable_default_role: false,
    disable_role_config: false,
    osinfo_version: 0,
    hypervisor: 'vmpooler',
  }

  argv.push('--help') if argv.empty?

  optparse = OptionParser.new do |opts|
    opts.banner = "Usage: beaker-hostgenerator [options] <layout>\n\n where <layout> takes the following form:\n  <platform>-<arch>[[<arbitrary-roles>,[...]].]<roles>[{<arbitrary-settings>,[...]}][-<arch>[[<arbitrary-roles>,[...]].]<roles>[{<arbitrary-settings>,[...]}]][-<layout>]\n\n examples:\n  centos6-64mdca-32a\n   1 CentOS 6 64 bit node with roles = master, database, agent, dashboard\n   1 CentOS 6 32 bit node with roles = agent\n\n  debian8-64m-32ad-32ac-centos6-64a\n   1 Debian 8 64 bit node with roles = master\n   1 Debian 8 32 bit node with roles = agent, database\n   1 Debian 8 32 bit node with roles = agent, dashboard\n   1 CentOS 6 64 bit node with roles = agent\n\n  debian8-64m-windows8-64a\n   1 Debian 8 64 bit node with roles = master\n   1 Windows 8 64 bit node with roles = agent\n\n example with arbitrary roles:\n  centos6-32compile_master,another_role.ma\n   1 CentOS 6 32 bit node with roles = master, agent, compile_master, another_role\n\n example with arbitrary host settings:\n  centos6-64m{hypervisor=none\\\\,hostname=static1\\\\,my-key=my-value}-32a\n   1 CentOS 6 64 bit node with roles = master, hypervisor = none, node name = static1, and my-key = my-value\n   1 CentOS 6 32 bit node with roles = agent and the default hypervisor\n\n example of a list within arbitrary host settings:\n  centos6-64m{hostname=static1\\\\,disks=[8,16],my-list=[my-value1]}-32a\n   1 CentOS 6 64 bit node with roles = master, node name = static1 and lists:\n  disks:\n     - 8\n     - 16\n   my-list:\n     - my-value1\n   1 CentOS 6 32 bit node with roles = agent and the default hypervisor\n\n Generally, it is expected that beaker-hostgenerator output will be redirected to a file, for example:\n  beaker-hostgenerator centos6-64ma > host.cfg\n\n This can then be used in a Beaker call instead of a static Beaker config.\n\n        eos\n\n    opts.on('-l',\n            '--list',\n            'List beaker-hostgenerator supported platforms, roles, and hypervisors. ' <<\n            'Does not produce host config.') do\n      @options[:list_supported_values] = true\n    end\n\n    opts.on('--templates-only',\n           'Generate a reduced output including only the templates from each host.') do\n      @options[:templates_only] = true\n    end\n\n    opts.on('-t',\n            '--hypervisor HYPERVISOR',\n            'Set beaker-hostgenerator default hypervisor. ') do |h|\n      @options[:hypervisor] = h\n    end\n\n    opts.on('--pe_upgrade_dir UPGRADE_PATH',\n            'Explicitly set pe_upgrade_dir attribute on generated hosts. ') do |p|\n      @options[:pe_upgrade_dir] = p\n    end\n\n    opts.on('--pe_upgrade_ver UPGRADE_VERSION',\n            'Explicitly set pe_upgrade_ver attribute on generated hosts. ') do |p|\n      @options[:pe_upgrade_ver] = p\n    end\n\n    opts.on('--pe_dir PATH',\n            'Explicitly set pe_dir attribute on generated hosts. ') do |p|\n      @options[:pe_dir] = p\n    end\n\n    opts.on('--pe_ver VERSION',\n            'Explicitly set pe_ver attribute on generated hosts. ') do |p|\n      @options[:pe_ver] = p\n    end\n\n    opts.on('--disable-role-config',\n            \"Do not include role-specific configuration.\") do\n      @options[:disable_role_config] = true\n    end\n\n    opts.on('--disable-default-role',\n            \"Do not include the default 'agent' role.\") do\n      @options[:disable_default_role] = true\n    end\n\n    opts.on('--osinfo-version MAJOR_VERSION',\n            \"Use OSINFO for specified beaker-hostgenerator version. \" <<\n            \"Allows early access to future version of OSINFO data structure \" <<\n            \"used to generate host configs.\") do |version|\n      version = version.to_i\n      if not [0, 1].include? version\n          raise \"Invalid beaker-hostgenerator version: \#{version}\"\n      end\n\n      @options[:osinfo_version] = version\n    end\n\n    opts.on('--global-config KEYVALUE_STRING',\n            \"General configuration settings to be included as-is in the \" <<\n            \"CONFIG section. Value should be in the form '{key=value,...}'.\") do |p|\n      @options[:global_config] = p\n    end\n\n    opts.on('-h',\n            '--help',\n            'Display command help.') do\n      @options[:help] = opts.to_s\n    end\n\n    opts.on('-v',\n            '--version',\n            'Display beaker-hostgenerator version number.') do\n      @options[:version] = true\n    end\n  end\n\n  optparse.parse!(argv)\n  @layout = argv[0]\nend\n"

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/beaker-hostgenerator/cli.rb', line 13

def options
  @options
end

Instance Method Details

#executeObject



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/beaker-hostgenerator/cli.rb', line 157

def execute
  if @options[:help]
    @options[:help] # Value is help text string
  elsif @options[:version]
    BeakerHostGenerator::Version::STRING
  elsif @options[:list_supported_values]
    supported_values_help_text
  elsif @options[:templates_only]
    require 'json'
    config = BeakerHostGenerator::Generator.new.generate(@layout, @options)
    templates = BeakerHostGenerator::AbsSupport.extract_templates(config)
    templates.to_json
  else
    config = BeakerHostGenerator::Generator.new.generate(@layout, @options)
    config.to_yaml
  end
end

#execute!Object



175
176
177
# File 'lib/beaker-hostgenerator/cli.rb', line 175

def execute!
  puts execute
end