Skip to content

Commit ac50d2d

Browse files
authored
Merge pull request #22 from lindycoder/time_and_report_config
Add configurable build timeout and progress display
2 parents dd2031c + 65b733e commit ac50d2d

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

lib/vagrant-openstack-cloud-provider/action/create_server.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def call(env)
100100
end
101101

102102
# Create the server
103+
launch_start_time = Time.now
103104
server = env[:openstack_compute].servers.create(options)
104105

105106
# Store the ID right away so we can track it
@@ -114,9 +115,12 @@ def call(env)
114115

115116
# Wait for the server to be ready
116117
begin
117-
(1..120).each do |n|
118-
env[:ui].clear_line
119-
env[:ui].report_progress(n, 120, true)
118+
(1..config.instance_build_timeout).each do |n|
119+
if config.report_progress
120+
env[:ui].clear_line
121+
env[:ui].report_progress(n, false)
122+
end
123+
120124
server = env[:openstack_compute].servers.get(env[:machine].id)
121125
break if self.server_to_be_available?(server)
122126
sleep 1
@@ -128,6 +132,9 @@ def call(env)
128132
end
129133
end
130134

135+
env[:ui].info(I18n.t("vagrant_openstack.active",
136+
:elapsed => (Time.now - launch_start_time).floor))
137+
131138
env[:machine].data_dir.join("cached_metadata").open("w+") do |f|
132139
f.write(server.to_json)
133140
end
@@ -136,7 +143,8 @@ def call(env)
136143
# Clear the line one more time so the progress is removed
137144
env[:ui].clear_line
138145
ssh_is_responding?(env)
139-
env[:ui].info(I18n.t("vagrant_openstack.ready"))
146+
env[:ui].info(I18n.t("vagrant_openstack.ready",
147+
:elapsed => (Time.now - launch_start_time).floor))
140148
end
141149

142150
@app.call(env)

lib/vagrant-openstack-cloud-provider/config.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ class Config < Vagrant.plugin("2", :config)
7070
# @return [Hash]
7171
attr_accessor :scheduler_hints
7272

73+
# @return [String]
74+
attr_accessor :instance_build_timeout
75+
76+
# @return [Bool]
77+
attr_accessor :report_progress
78+
# alias_method :report_progress?, :report_progress
79+
80+
7381
def initialize
7482
@api_key = UNSET_VALUE
7583
@endpoint = UNSET_VALUE
@@ -86,6 +94,8 @@ def initialize
8694
@networks = UNSET_VALUE
8795
@tenant = UNSET_VALUE
8896
@scheduler_hints = UNSET_VALUE
97+
@instance_build_timeout = UNSET_VALUE
98+
@report_progress = UNSET_VALUE
8999
end
90100

91101
def finalize!
@@ -111,6 +121,8 @@ def finalize!
111121
@networks = [@public_network_name] if @networks == UNSET_VALUE
112122
@tenant = nil if @tenant == UNSET_VALUE
113123
@scheduler_hints = {} if @scheduler_hints == UNSET_VALUE
124+
@instance_build_timeout = 120 if @instance_build_timeout == UNSET_VALUE
125+
@report_progress = true if @report_progress == UNSET_VALUE
114126
end
115127

116128
def validate(machine)

locales/en.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ en:
1414
Launching a server with the following settings...
1515
not_created: |-
1616
The server hasn't been created yet. Run `vagrant up` first.
17+
active: |-
18+
The server was built in %{elapsed} seconds!
1719
ready: |-
18-
The server is ready!
20+
The server is ready after %{elapsed} seconds!
1921
rsync_folder: |-
2022
Rsyncing folder: %{hostpath} => %{guestpath}
2123
waiting_for_build: |-

spec/vagrant-openstack-cloud-provider/config_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
its(:networks) { should eq(["public"]) }
2727
its(:tenant) { should be_nil }
2828
its(:scheduler_hints) { should eq({}) }
29+
its(:instance_build_timeout) { should eq(120) }
30+
its(:report_progress) { should be_true }
2931
end
3032

3133
describe "overriding defaults" do
@@ -42,7 +44,9 @@
4244
:public_network_name,
4345
:networks,
4446
:tenant,
45-
:scheduler_hints].each do |attribute|
47+
:scheduler_hints,
48+
:instance_build_timeout,
49+
:report_progress].each do |attribute|
4650
it "should not default #{attribute} if overridden" do
4751
subject.send("#{attribute}=", "foo")
4852
subject.finalize!

vagrant-openstack-cloud-provider.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
1515

1616
gem.add_runtime_dependency "fog", "~> 1.22"
1717

18-
gem.add_development_dependency "rake"
18+
gem.add_development_dependency "rake", '< 11.0'
1919
gem.add_development_dependency "rspec", "~> 2.13.0"
2020

2121
gem.files = `git ls-files`.split($/)

0 commit comments

Comments
 (0)