Class: Hazetug::CLI::Bootstrap
- Inherits:
-
Action
- Object
- Action
- Hazetug::CLI::Bootstrap
show all
- Defined in:
- lib/hazetug/cli/bootstrap.rb
Instance Attribute Summary
Attributes inherited from Action
#data
Instance Method Summary
collapse
Methods inherited from Action
[], inherited, #pass, #ui
Instance Method Details
#bootstrap_list(&block) ⇒ Object
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
|
# File 'lib/hazetug/cli/bootstrap.rb', line 48
def bootstrap_list(&block)
return if block.nil?
task.hosts_to_bootstrap(command_variables) do |conf|
num = conf[:number] || data[:opts][:number].to_i || 1
if convert_rand_name(conf[:name]) == conf[:name] && num > 1
ui.fatal "Can't bootstrap several hosts with the same name"
raise ArgumentError, "%rand(x)% expected"
end
(1..num).each do
newconf = conf.dup
newconf[:name] = convert_rand_name(conf[:name])
haze = Hazetug::Haze[data[:compute_name]].new(newconf)
if haze.config[:ssh_password]
newconf[:ssh_password] = haze.config[:ssh_password]
end
tug = Hazetug::Tug[data[:tug_name]].new(newconf)
block.call(haze, tug)
end
end
end
|
#command_variables ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/hazetug/cli/bootstrap.rb', line 75
def command_variables
@command_variables ||= begin
env = {}
arr = data[:opts][:variables]
if arr
arr.each do |eq|
k, v = eq.split('=')
env[k] = v
end
end
env
end
end
|
#convert_rand_name(name) ⇒ Object
89
90
91
92
93
|
# File 'lib/hazetug/cli/bootstrap.rb', line 89
def convert_rand_name(name)
name.sub(/%rand\((\d+)\)%/) do |m|
rand(36**$1.to_i).to_s(36)
end
end
|
#execute ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/hazetug/cli/bootstrap.rb', line 9
def execute
concurrency = data[:opts][:concurrency].to_i || 1
queue = channel!(Object, concurrency)
waitgroup = Agent::WaitGroup.new
bootstrap_list do |haze, tug|
queue << nil; waitgroup.add(1)
block = method(:provision_and_bootstrap).to_proc
go!(haze, tug, queue, waitgroup, &block)
end
waitgroup.wait
end
|
#provision_and_bootstrap(haze, tug, channel, waitgroup) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/hazetug/cli/bootstrap.rb', line 26
def provision_and_bootstrap(haze, tug, channel, waitgroup)
haze.provision
if haze.ready?
haze.update_access_settings tug.config
tug.bootstrap({
args: data[:args],
opts: data[:opts],
gopts: data[:gopts]
})
end
rescue
puts $!.inspect
puts $@
ensure
waitgroup.done
channel.receive
end
|
#task ⇒ Object
21
22
23
24
|
# File 'lib/hazetug/cli/bootstrap.rb', line 21
def task
yaml_task = data[:args].shift
@task ||= Hazetug::Task.load_from_file(yaml_task)
end
|