Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fixed ipv4 #188

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ assuming that test network is configured as private.
If true use IPv6 addresses to for SSH connections. If false, the default, use
IPv4 addresses for SSH connections.

### fixed_ip_v4

You can use this to set a fixed IPv4 IP address for your instance.

### network\_ref

The `network_ref` option can be specified as an exact id, an exact name,
Expand Down
13 changes: 11 additions & 2 deletions lib/kitchen/driver/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Openstack < Kitchen::Driver::Base
default_config :read_timeout, 60
default_config :write_timeout, 60
default_config :metadata, nil
default_config :fixed_ip_v4, nil

# Set the proper server name in the config
def config_server_name
Expand Down Expand Up @@ -179,12 +180,20 @@ def create_server
if config[:network_id]
networks = [].concat([config[:network_id]])
server_def[:nics] = networks.flatten.map do |net_id|
{ "net_id" => net_id }
if config[:fixed_ip_v4]
{ "net_id" => net_id, :v4_fixed_ip => config[:fixed_ip_v4] }
else
{ "net_id" => net_id }
end
end
elsif config[:network_ref]
networks = [].concat([config[:network_ref]])
server_def[:nics] = networks.flatten.map do |net|
{ "net_id" => find_network(net).id }
if config[:fixed_ip_v4]
{ "net_id" => find_network(net).id, :v4_fixed_ip => config[:fixed_ip_v4] }
else
{ "net_id" => find_network(net).id }
end
end
end

Expand Down
54 changes: 52 additions & 2 deletions spec/kitchen/driver/openstack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@
end
end

context "network specifies network_id" do
context "network specifies network_id no fixed ipv4" do
let(:config) do
{
server_name: "hello",
Expand All @@ -681,6 +681,30 @@
end
end

context "network specifies network_id with fixed ipv4" do
let(:config) do
{
server_name: "hello",
image_ref: "111",
flavor_ref: "1",
network_id: "0922b7aa-0a2f-4e68-8ff7-2886c4fc472d",
fixed_ip_v4: "192.168.1.100",
}
end

it "exact id match" do
networks = [
{ "net_id" => "0922b7aa-0a2f-4e68-8ff7-2886c4fc472d", :v4_fixed_ip => "192.168.1.100" },
]
expect(servers).to receive(:create).with(name: "hello",
image_ref: "111",
flavor_ref: "1",
availability_zone: nil,
nics: networks)
driver.send(:create_server)
end
end

context "network_id and network_ref specified" do
let(:config) do
{
Expand Down Expand Up @@ -723,7 +747,7 @@
end
end

context "network specifies name" do
context "network specifies name and no fixed ipv4" do
let(:config) do
{
server_name: "hello",
Expand All @@ -748,6 +772,32 @@
end
end

context "network specifies name and fixed ipv4" do
let(:config) do
{
server_name: "hello",
image_ref: "111",
flavor_ref: "1",
network_ref: "vlan1",
fixed_ip_v4: "192.168.1.100",
}
end

it "exact id match" do
networks = [
{ "net_id" => "1", :v4_fixed_ip => "192.168.1.100" },
]
expect(servers).to receive(:create).with(
name: "hello",
image_ref: "111",
flavor_ref: "1",
availability_zone: nil,
nics: networks
)
driver.send(:create_server)
end
end

context "multiple networks specifies id" do
let(:config) do
{
Expand Down