Enabled the option to specify the Source/Destination checks flag

This patch enables the option to set the source/destination checks flag
on an amazon vpc instance. This flag cannot be set while creating the
instance so an additional call is required.
This commit is contained in:
Preet Bhinder 2015-07-28 13:21:44 -07:00
parent ef97e5118b
commit be0a6974fc
4 changed files with 35 additions and 2 deletions

View File

@ -42,6 +42,7 @@ module VagrantPlugins
iam_instance_profile_name = region_config.iam_instance_profile_name
monitoring = region_config.monitoring
ebs_optimized = region_config.ebs_optimized
source_dest_check = region_config.source_dest_check
associate_public_ip = region_config.associate_public_ip
kernel_id = region_config.kernel_id
@ -74,6 +75,7 @@ module VagrantPlugins
env[:ui].info(" -- Terminate On Shutdown: #{terminate_on_shutdown}")
env[:ui].info(" -- Monitoring: #{monitoring}")
env[:ui].info(" -- EBS optimized: #{ebs_optimized}")
env[:ui].info(" -- Source Destination check: #{source_dest_check}")
env[:ui].info(" -- Assigning a public IP address in a VPC: #{associate_public_ip}")
options = {
@ -92,7 +94,8 @@ module VagrantPlugins
:monitoring => monitoring,
:ebs_optimized => ebs_optimized,
:associate_public_ip => associate_public_ip,
:kernel_id => kernel_id
:kernel_id => kernel_id,
:associate_public_ip => associate_public_ip
}
if !security_groups.empty?
security_group_key = options[:subnet_id].nil? ? :groups : :security_group_ids
@ -153,6 +156,22 @@ module VagrantPlugins
do_elastic_ip(env, domain, server, elastic_ip)
end
# Set the source destination checks
if !source_dest_check.nil?
if server.vpc_id.nil?
env[:ui].warn(I18n.t("vagrant_aws.source_dest_checks_no_vpc"))
else
begin
attrs = {
"SourceDestCheck.Value" => source_dest_check
}
env[:aws_compute].modify_instance_attribute(server.id, attrs)
rescue Fog::Compute::AWS::Error => e
raise Errors::FogError, :message => e.message
end
end
end
if !env[:interrupted]
env[:metrics]["instance_ssh_time"] = Util::Timer.time do
# Wait for SSH to be ready.

View File

@ -154,6 +154,11 @@ module VagrantPlugins
# @return [Boolean]
attr_accessor :ebs_optimized
# Source Destination check
#
# @return [Boolean]
attr_accessor :source_dest_check
# Assigning a public IP address in a VPC
#
# @return [Boolean]
@ -204,6 +209,7 @@ module VagrantPlugins
@ssh_host_attribute = UNSET_VALUE
@monitoring = UNSET_VALUE
@ebs_optimized = UNSET_VALUE
@source_dest_check = UNSET_VALUE
@associate_public_ip = UNSET_VALUE
@elb = UNSET_VALUE
@unregister_elb_from_az = UNSET_VALUE
@ -357,6 +363,9 @@ module VagrantPlugins
# default false
@ebs_optimized = false if @ebs_optimized == UNSET_VALUE
# default to nil
@source_dest_check = nil if @source_dest_check == UNSET_VALUE
# default false
@associate_public_ip = false if @associate_public_ip == UNSET_VALUE

View File

@ -39,6 +39,9 @@ en:
Make sure rsync is installed and the binary can be found in the PATH.
rsync_folder: |-
Rsyncing folder: %{hostpath} => %{guestpath}
source_dest_checks_no_vpc: |-
Warning! Ignoring source_dest_checks flag as it can only be configured on
a VPC instance.
starting: |-
Starting the instance...
stopping: |-

View File

@ -42,6 +42,7 @@ describe VagrantPlugins::AWS::Config do
its("ssh_host_attribute") { should be_nil }
its("monitoring") { should == false }
its("ebs_optimized") { should == false }
its("source_dest_check") { should be_nil }
its("associate_public_ip") { should == false }
its("unregister_elb_from_az") { should == true }
end
@ -56,7 +57,8 @@ describe VagrantPlugins::AWS::Config do
:ebs_optimized, :region, :secret_access_key, :session_token, :monitoring,
:associate_public_ip, :subnet_id, :tags, :package_tags, :elastic_ip,
:terminate_on_shutdown, :iam_instance_profile_arn, :iam_instance_profile_name,
:use_iam_profile, :user_data, :block_device_mapping].each do |attribute|
:use_iam_profile, :user_data, :block_device_mapping,
:source_dest_check].each do |attribute|
it "should not default #{attribute} if overridden" do
instance.send("#{attribute}=".to_sym, "foo")