Skip to content

Commit d6bebee

Browse files
fboulianeSimon
authored andcommitted
Add support for availability zone
This is needed to choose which compute node you will boot on. Not added test to create_server, this is tech debt we should address soon. Uses the fog default if the availability zone is not passed, should not break anything. Tested locally with and without the availability_zone config.
1 parent d18581b commit d6bebee

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ This provider exposes quite a few provider-specific configuration options:
7070
* `image` - The server image to boot. This can be a string matching the
7171
exact ID or name of the image, or this can be a regular expression to
7272
partially match some image.
73+
* `availability_zone` - The availability zone to use with nova,
74+
this allows to choose which zone your instance will exist on.
7375
* `endpoint` - The keystone authentication URL of your OpenStack installation.
7476
* `server_name` - The name of the server within the OpenStack Cloud. This
7577
defaults to the name of the Vagrant machine (via `config.vm.define`), but

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ def call(env)
6464
env[:ui].info(" - #{net['name']}")
6565
end
6666
end
67+
68+
unless config.availability_zone.nil?
69+
env[:ui].info(" -- Availability Zone: #{config.availability_zone}")
70+
end
71+
6772
env[:ui].info(" -- Name: #{server_name}")
6873

6974
openstack_nics = []
@@ -83,6 +88,10 @@ def call(env)
8388
:os_scheduler_hints => config.scheduler_hints
8489
}
8590

91+
unless config.availability_zone.nil?
92+
options[:availability_zone] = config.availability_zone
93+
end
94+
8695
if openstack_nics.any?
8796
options[:nics] = openstack_nics
8897
end

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class Config < Vagrant.plugin("2", :config)
9494
# @return [String]
9595
attr_accessor :user_domain_id
9696

97+
# @return [String]
98+
attr_accessor :availability_zone
99+
97100
# Version to use for keystone authentication
98101
# Not used for now, will be supported in the next version.
99102
# Known version are 'v2.0', 'v3'
@@ -141,6 +144,7 @@ def initialize
141144
@instance_ssh_timeout = UNSET_VALUE
142145
@instance_ssh_check_interval = UNSET_VALUE
143146
@report_progress = UNSET_VALUE
147+
@availability_zone = UNSET_VALUE
144148

145149
@project_name = UNSET_VALUE
146150
@project_id = UNSET_VALUE
@@ -194,6 +198,7 @@ def finalize!
194198
@instance_ssh_timeout = 120 if @instance_ssh_timeout == UNSET_VALUE
195199
@instance_ssh_check_interval = 2 if @instance_ssh_check_interval == UNSET_VALUE
196200

201+
@availability_zone = nil if @availability_zone == UNSET_VALUE
197202
@report_progress = true if @report_progress == UNSET_VALUE
198203
end
199204

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
it { is_expected.to have_attributes(identity_api_version: nil) }
4141

4242
it { is_expected.to have_attributes(scheduler_hints: {}) }
43+
it { is_expected.to have_attributes(availability_zone: nil) }
4344
it { is_expected.to have_attributes(instance_build_timeout: 120) }
4445
it { is_expected.to have_attributes(instance_build_status_check_interval: 1) }
4546
it { is_expected.to have_attributes(instance_ssh_timeout: 120) }
@@ -71,6 +72,7 @@
7172
:user_domain_id,
7273
:identity_api_version,
7374
:scheduler_hints,
75+
:availability_zone,
7476
:report_progress].each do |attribute|
7577
it "should not default #{attribute} if overridden" do
7678
subject.send("#{attribute}=", "foo")

0 commit comments

Comments
 (0)