Skip to content

Commit

Permalink
Merge pull request #114 from opscode/pd-add-network-id-option
Browse files Browse the repository at this point in the history
Added network id option to server create command
  • Loading branch information
kaustubh-d committed Jun 2, 2014
2 parents 1961a70 + 0573824 commit 4b63cbd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/chef/knife/cloud/openstack_server_create_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def self.included(includer)
:default => true,
:description => "Use first available network for bootstrapping if 'public' and 'private' are unavailable."

option :network_ids,
:long => "--network-ids NETWORK_ID_1,NETWORK_ID_2,NETWORK_ID_3",
:description => "Comma separated list of the UUID(s) of the network(s) for the server to attach",
:proc => Proc.new { |networks| networks.split(',') }

option :availability_zone,
:short => "-Z ZONE_NAME",
:long => "--availability-zone ZONE_NAME",
Expand Down
1 change: 1 addition & 0 deletions lib/chef/knife/openstack_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def before_exec_command
}

@create_options[:server_def].merge!({:user_data => locate_config_value(:user_data)}) if locate_config_value(:user_data)
@create_options[:server_def].merge!({:nics => locate_config_value(:network_ids).map { |nic| nic_id = { 'net_id' => nic }}}) if locate_config_value(:network_ids)

Chef::Log.debug("Create server params - server_def = #{@create_options[:server_def]}")
#set columns_with_info map
Expand Down
3 changes: 1 addition & 2 deletions spec/functional/group_list_func_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
]
})
]

instance.stub(:query_resource).and_return(resources)
instance.stub(:puts)
instance.stub(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
Expand All @@ -46,4 +45,4 @@
instance.run
end
end
end
end
17 changes: 17 additions & 0 deletions spec/unit/openstack_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
Chef::Config[:knife][:openstack_security_groups] = "openstack_security_groups"
Chef::Config[:knife][:server_create_timeout] = "server_create_timeout"
Chef::Config[:knife][:openstack_ssh_key_id] = "openstack_ssh_key"
Chef::Config[:knife][:network_ids] = "test_network_id"
Chef::Config[:knife][:network_ids].stub(:map).and_return(Chef::Config[:knife][:network_ids])
end

after(:all) do
Expand All @@ -81,6 +83,7 @@
@instance.create_options[:server_def][:image_ref].should == Chef::Config[:knife][:image]
@instance.create_options[:server_def][:security_groups].should == Chef::Config[:knife][:openstack_security_groups]
@instance.create_options[:server_def][:flavor_ref].should == Chef::Config[:knife][:flavor]
@instance.create_options[:server_def][:nics].should == Chef::Config[:knife][:network_ids]
@instance.create_options[:server_create_timeout].should == Chef::Config[:knife][:server_create_timeout]
end

Expand All @@ -97,6 +100,20 @@
@instance.before_exec_command
@instance.create_options[:server_def][:user_data].should == user_data
end

context "with multiple network_ids specified" do
before(:each) do
@instance.service = double
@instance.service.should_receive(:create_server_dependencies)
Chef::Config[:knife][:network_ids] = "test_network_id1,test_network_id2"
Chef::Config[:knife][:network_ids].stub(:map).and_return(Chef::Config[:knife][:network_ids].split(","))
end

it "creates the server_def with multiple nic_ids." do
@instance.before_exec_command
@instance.create_options[:server_def][:nics].should == ["test_network_id1", "test_network_id2"]
end
end
end

describe "#after_exec_command" do
Expand Down

0 comments on commit 4b63cbd

Please sign in to comment.