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
|
# File 'lib/vagrant-dustcloud/action/run_instance.rb', line 19
def call(env)
env[:metrics] ||= {}
flavor = env[:machine].provider_config.flavor.to_s
image = env[:machine].provider_config.image.to_s
env[:ui].info(I18n.t("vagrant_dustcloud.launching_instance"))
env[:ui].info(" -- Image: #{image}")
env[:ui].info(" -- Flavor: #{flavor}")
begin
server = env[:dustcloud].create_vm(image, flavor)
end
env[:machine].id = server["uuid"]
env[:machine_ssh_username] = server["username"]
env[:machine_ssh_password] = server["password"]
pw_file = env[:machine].data_dir.join('ssh_password')
pw_file.open('w+') do |f|
f.write(server["password"])
end
env[:metrics]["instance_ready_time"] = Util::Timer.time do
env[:ui].info(I18n.t("vagrant_dustcloud.waiting_for_ready"))
total_waited = 0
while true
break if env[:interrupted]
vm = env[:dustcloud].get_vm(server["uuid"])
if vm["status"] == "ACTIVE"
break
end
sleep(2)
total_waited += 2
if total_waited > 180
raise Errors::InstanceReadyTimeout, timeout: 180
end
end
end
env[:ui].info("Time to instance ready: #{env[:metrics]["instance_ready_time"]}")
if !env[:interrupted]
env[:metrics]["instance_ssh_time"] = Util::Timer.time do
env[:ui].info(I18n.t("vagrant_dustcloud.waiting_for_ssh"))
network_ready_retries = 0
network_ready_retries_max = 10
while true
break if env[:interrupted]
begin
break if env[:machine].communicate.ready?
rescue Exception => e
if network_ready_retries < network_ready_retries_max then
network_ready_retries += 1
@logger.warn("SSH not yet up, retrying...")
else
raise e
end
end
sleep 2
end
end
env[:ui].info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
env[:ui].info(I18n.t("vagrant_dustcloud.ready"))
end
terminate(env) if env[:interrupted]
@app.call(env)
end
|