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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
#!/usr/bin/env ruby
require 'ostruct'
require 'everest-bootstrap'
require 'main'
require 'net/http'
require 'uri'
require "highline/import"
#http://www.mail-archive.com/capistrano@googlegroups.com/msg01822.html
HighLine.track_eof = false
include EverestBootstrap
Main {
version Version::STRING
def handle_exception e
puts e.message
end unless $DEBUG
def say_red(text)
say("<%= color(\"#{text}\", :red) %>")
end
def get_input
unless ENV['USER'] == 'root' || params["config-only"].given?
raise "You must run this command as root unless " +
"you specify the '--config-only' option"
end
@facts = Hash.new
@repo = ask("Enter your Everest repo machine name (leave off the '-repo'): ")
@user = ask("Enter your kerberos username: ")
say_red("Your machine name is the part right before the Everest type.")
say_red("For example, 'sso1-build.usersys.redhat.com' has a machine name of 'sso1'.")
say_red("If you do not specify a machine name it will default to your kerberos name.")
if agree("Enter machine name? (y/n)", true)
@machine_name = ask("Machine name: ")
else
@machine_name = @user
end
# Once we know the repo we can fetch the supported machines
@everest_repo = EverestRepo.new(@repo)
say_red("To see a description of these machine types visit: " +
"#{@everest_repo.machine_types_url}")
@machine_type = choose do |menu|
menu.prompt = "Select your machine type: "
menu.choices(*@everest_repo.machines.map{|m| m.name})
end
# This might be useful is we stop using DDNS
@facts["everest_machine_type"] = @machine_type
if agree("Configure this machine with Red Hat DDNS? (y/n)", true)
# Our naming convention
hostname = @machine_name + "-" + @machine_type
@fqdn = hostname + ".usersys.redhat.com"
if agree("Do you know the DDNS hash for this machine? (y/n)", true)
@facts["rh_ddns_hash"] = ask("Enter Red Hat DDNS hash: ")
else
@password = ask("Enter your kerberos password to setup DDNS: ") { |q| q.echo = "*" }
@facts["rh_ddns_hash"] = RedHatDDNS::DDNS.new(@user, @password, hostname).ddns_hash
end
else
@fqdn = ask("Enter fully qualified domain name for this machine: ")
end
@facts["cobbler_profile"] = choose do |menu|
menu.prompt = "Select your cobbler profile (This determines the OS): "
menu.choices(*@everest_repo.cobbler_profiles)
end
say_red("Now you need to enter some parameters what will be used to configure this machine.")
say_red("Most of the defaults will work out fine for development.")
@everest_repo.facts_for(@machine_type, @machine_name).each do |f|
say_red("Description: #{f.desc}") unless f.desc.empty?
@facts[f.name] = ask("Enter value for #{f.name}: ") do |q|
q.default = f.default
end
end
if agree("Enter addition facts? (y/n)", true)
begin
name = ask("Enter fact name: ")
value = ask("Enter fact value: ")
@facts[name] = value
end while agree("Enter another? ", true)
end
unless params["config-only"].given?
if agree("Use LVM for VM storage (recommended)? (y/n)", true)
@virt_path = choose do |menu|
menu.prompt = "Select the Volume Group to use: "
menu.choices(*(`/usr/sbin/vgdisplay --short`.split("\n").map {|l| /"(.*)"/.match(l).captures[0]}))
end
else
@virt_path = ask("Enter the flat file to be used for guest: ")
end
xen_conf = "/etc/xen/#{@fqdn.split(".")[0]}"
if File.exist?(xen_conf)
say_red("Previous Xen configuration detected at #{xen_conf}.")
say_red("This will cause Koan to abort.")
if agree("Clean up? (y/n)", true)
File.delete(xen_conf)
end
end
say_red("The Koan process is now starting. After it finishes start the VM back up with " +
"'xm create <name>'.")
say_red("HINT: 'xm list' will show you the running VMs.")
end
end
option('config-only', 'c'){
description "Only send the machine configuration to the Puppetmaster"
}
def run
# Ask all the silly questions
get_input
classes = @everest_repo.classes_for(@machine_type)
config = {"classes" => classes, "parameters" => @facts}
e = EverestMachine.new(@machine_type,
@fqdn,
@repo,
config)
e.post_config
e.add_system_to_cobbler
e.koan(@virt_path) unless params["config-only"].given?
end
mode 'advanced' do
option('fqdn', 'f'){
required
description "Fully qualified domain name of machine to be provisioned"
argument_required
}
option('repo', '-r'){
required
description "Fully qualified domain name for the Everest repo machine to use for provisioning"
argument_required
}
option('yaml', 'y'){
description "YAML configuration for this machine"
argument_required
validate {|f| File.exist?(f)}
}
option('virt-path', 'v'){
description "Volume group or flat file for koan provisioning"
argument_required
}
def run
config = if params['yaml'].given?
YAML.load(File.read(params['yaml'].value))
else
YAML.load($stdin.read)
end
e = EverestMachine.new(config["parameters"]["everest_machine_type"],
params['fqdn'].value,
params['repo'].value,
config)
e.post_config
e.add_system_to_cobbler
e.koan(params['virt-path'].value) if params["virt-path"].given?
end
end
mode 'cloud' do
def collect_input
unless ENV['USER'] == 'root' || params["config-only"].given?
raise "You must run this command as root unless " +
"you specify the '--config-only' option"
end
@facts = Hash.new
@repo = ask("Enter your Everest repo machine name (leave off the '-repo'): ")
@cloud = ask("Enter your cloud master (leave off the '-repo'): ")
@user = ask("Enter your kerberos username: ")
say_red("Your machine name is the part right before the Everest type.")
say_red("For example, 'sso1-build.usersys.redhat.com' has a machine name of 'sso1'.")
say_red("If you do not specify a machine name it will default to your kerberos name.")
if agree("Enter machine name? (y/n)", true)
@machine_name = ask("Machine name: ")
else
@machine_name = @user
end
# Once we know the repo we can fetch the supported machines
@everest_repo = EverestRepo.new(@repo)
say_red("To see a description of these machine types visit: " +
"#{@everest_repo.machine_types_url}")
@machine_type = choose do |menu|
menu.prompt = "Select your machine type: "
menu.choices(*@everest_repo.machines.map{|m| m.name})
end
# This might be useful is we stop using DDNS
@facts["everest_machine_type"] = @machine_type
if agree("Configure this machine with Red Hat DDNS? (y/n)", true)
# Our naming convention
hostname = @machine_name + "-" + @machine_type
@fqdn = hostname + ".usersys.redhat.com"
if agree("Do you know the DDNS hash for this machine? (y/n)", true)
@facts["rh_ddns_hash"] = ask("Enter Red Hat DDNS hash: ")
else
@password = ask("Enter your kerberos password to setup DDNS: ") { |q| q.echo = "*" }
@facts["rh_ddns_hash"] = RedHatDDNS::DDNS.new(@user, @password, hostname).ddns_hash
end
else
@fqdn = ask("Enter fully qualified domain name for this machine: ")
end
@facts["cobbler_profile"] = choose do |menu|
menu.prompt = "Select your cobbler profile (This determines the OS): "
menu.choices(*@everest_repo.cobbler_profiles)
end
say_red("Now you need to enter some parameters what will be used to configure this machine.")
say_red("Most of the defaults will work out fine for development.")
@everest_repo.facts_for(@machine_type, @machine_name).each do |f|
say_red("Description: #{f.desc}") unless f.desc.empty?
@facts[f.name] = ask("Enter value for #{f.name}: ") do |q|
q.default = f.default
end
end
if agree("Enter addition facts? (y/n)", true)
begin
name = ask("Enter fact name: ")
value = ask("Enter fact value: ")
@facts[name] = value
end while agree("Enter another? ", true)
end
say_red("The Koan process will start on a machine in the cloud.")
end
def run
collect_input
classes = @everest_repo.classes_for(@machine_type)
config = {"classes" => classes, "parameters" => @facts}
@everest_repo.register_machine(@fqdn, config)
cloud_repo = CloudRepo.new
cloud_repo.create_machine(@fqdn, @cloud)
end
end
mode 'cloud-advanced' do
option('fqdn', 'f'){
required
description "Fully qualified domain name of machine to be provisioned"
argument_required
}
option('repo', '-r'){
required
description "Fully qualified domain name for the Everest repo machine to use for provisioning"
argument_required
}
option('cloud-controller', '-c'){
description "Fully qualified domain name for the Everest repo machine to use for provisioning"
argument_required
}
option('yaml', 'y'){
description "YAML configuration for this machine"
argument_required
validate {|f| File.exist?(f)}
}
def run
config = if params['yaml'].given?
YAML.load(File.read(params['yaml'].value))
else
YAML.load($stdin.read)
end
cloud_controller = if params['cloud-controller'].given?
params['cloud-controller'].value
else
"everest-repo.usersys.redaht.com"
end
everest_repo = EverestRepo.new(params['repo'].value)
everest_repo.register_machine(params['fqdn'].value, config)
cloud_repo = CloudRepo.new(everest_repo.repo)
cloud_repo.create_machine(params['fqdn'].value, everest_repo.repo)
end
end
}
|