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

[MSYS-719]add primary eni to server #515

Merged
merged 3 commits into from
Dec 22, 2017
Merged
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
19 changes: 17 additions & 2 deletions lib/chef/knife/ec2_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class Ec2ServerCreate < Knife
:description => "The placement group to place a cluster compute instance",
:proc => Proc.new { |pg| Chef::Config[:knife][:placement_group] = pg }

option :primary_eni,
:long => "--primary-eni ENI_ID",
:description => "Specify a pre-existing eni to use when building the instance."

option :tags,
:short => "-T T=V[,T=V,...]",
:long => "--tags Tag=Value[,Tag=Value...]",
Expand Down Expand Up @@ -636,6 +640,7 @@ def run
msg_pair("Security Groups", printed_security_groups) unless vpc_mode? or (@server.groups.nil? and @server.security_group_ids)
msg_pair("Security Group Ids", printed_security_group_ids) if vpc_mode? or @server.security_group_ids
msg_pair("IAM Profile", locate_config_value(:iam_instance_profile)) if locate_config_value(:iam_instance_profile)
msg_pair("Primary ENI", locate_config_value(:primary_eni)) if locate_config_value(:primary_eni)
msg_pair("Tags", printed_tags)
msg_pair("SSH Key", @server.key_name)
msg_pair("Root Device Type", @server.root_device_type)
Expand Down Expand Up @@ -1109,8 +1114,18 @@ def create_server_def
:request_type => locate_config_value(:spot_request_type)
}

server_def[:security_group_ids] = locate_config_value(:security_group_ids)
server_def[:subnet_id] = locate_config_value(:subnet_id) if vpc_mode?
if primary_eni = locate_config_value(:primary_eni)
server_def[:network_interfaces] = [
{
:NetworkInterfaceId => primary_eni,
:DeviceIndex => "0"
}
]
else
server_def[:security_group_ids] = locate_config_value(:security_group_ids)
server_def[:subnet_id] = locate_config_value(:subnet_id) if vpc_mode?
end

server_def[:private_ip_address] = locate_config_value(:private_ip_address) if vpc_mode?
server_def[:placement_group] = locate_config_value(:placement_group)
server_def[:iam_instance_profile_name] = locate_config_value(:iam_instance_profile)
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/ec2_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2628,5 +2628,17 @@
end

end
describe '--primary_eni option' do
before do
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
end

context 'when a preexisting eni is specified eg. eni-12345678 use that eni for device index 0' do
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(['--primary-eni', 'eni-12345678']) }
it 'provides a network_interfaces list of hashes with on element for the primary interface' do
server_def = ec2_server_create.create_server_def
expect(server_def[:network_interfaces]).to eq([{:NetworkInterfaceId => 'eni-12345678', :DeviceIndex => '0'}])
end
end
end
end