From 1cc3cdf7b5b13b386df2ba58546e7db065683a5b Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 21 Feb 2017 17:46:16 -0800 Subject: [PATCH] Always set both SRIOV and ENA when Enhanced Networking is enabled Set SriovNetSupport to "simple". As of February 2017, this applies to C3, C4, D2, I2, R3, and M4 (excluding m4.16xlarge). Set EnaSupport to true. As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge. --- builder/amazon/chroot/step_register_ami.go | 7 ++++- .../amazon/common/step_modify_ebs_instance.go | 26 +++++++++++++++---- builder/amazon/common/step_source_ami_info.go | 2 +- .../amazon/ebssurrogate/step_register_ami.go | 7 ++++- builder/amazon/instance/step_register_ami.go | 7 ++++- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/builder/amazon/chroot/step_register_ami.go b/builder/amazon/chroot/step_register_ami.go index 9b83f941e..8523b595a 100644 --- a/builder/amazon/chroot/step_register_ami.go +++ b/builder/amazon/chroot/step_register_ami.go @@ -75,9 +75,14 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction { registerOpts = buildRegisterOpts(config, image, newMappings) } - // Set SriovNetSupport to "simple". See http://goo.gl/icuXh5 if config.AMIEnhancedNetworking { + // Set SriovNetSupport to "simple". See http://goo.gl/icuXh5 + // As of February 2017, this applies to C3, C4, D2, I2, R3, and M4 (excluding m4.16xlarge) registerOpts.SriovNetSupport = aws.String("simple") + + // Set EnaSupport to true + // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge + registerOpts.EnaSupport = aws.Bool(true) } registerResp, err := ec2conn.RegisterImage(registerOpts) diff --git a/builder/amazon/common/step_modify_ebs_instance.go b/builder/amazon/common/step_modify_ebs_instance.go index ab0cd9e6c..59307ea08 100644 --- a/builder/amazon/common/step_modify_ebs_instance.go +++ b/builder/amazon/common/step_modify_ebs_instance.go @@ -17,16 +17,32 @@ func (s *StepModifyEBSBackedInstance) Run(state multistep.StateBag) multistep.St instance := state.Get("instance").(*ec2.Instance) ui := state.Get("ui").(packer.Ui) - // Set SriovNetSupport to "simple". See http://goo.gl/icuXh5 if s.EnableEnhancedNetworking { - ui.Say("Enabling Enhanced Networking...") + // Set SriovNetSupport to "simple". See http://goo.gl/icuXh5 + // As of February 2017, this applies to C3, C4, D2, I2, R3, and M4 (excluding m4.16xlarge) + ui.Say("Enabling Enhanced Networking (SR-IOV)...") simple := "simple" - _, err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{ + _, err_iov := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{ InstanceId: instance.InstanceId, SriovNetSupport: &ec2.AttributeValue{Value: &simple}, }) - if err != nil { - err := fmt.Errorf("Error enabling Enhanced Networking on %s: %s", *instance.InstanceId, err) + if err_iov != nil { + err := fmt.Errorf("Error enabling Enhanced Networking (SR-IOV) on %s: %s", *instance.InstanceId, err_iov) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + + // Set EnaSupport to true. + // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge + ui.Say("Enabling Enhanced Networking (ENA)...") + truthy := true + _, err_ena := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{ + InstanceId: instance.InstanceId, + EnaSupport: &ec2.AttributeBooleanValue{Value: &truthy}, + }) + if err_ena != nil { + err := fmt.Errorf("Error enabling Enhanced Networking (ENA) on %s: %s", *instance.InstanceId, err_ena) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt diff --git a/builder/amazon/common/step_source_ami_info.go b/builder/amazon/common/step_source_ami_info.go index b83b31d74..bd03fcdf8 100644 --- a/builder/amazon/common/step_source_ami_info.go +++ b/builder/amazon/common/step_source_ami_info.go @@ -101,7 +101,7 @@ func (s *StepSourceAMIInfo) Run(state multistep.StateBag) multistep.StepAction { ui.Message(fmt.Sprintf("Found Image ID: %s", *image.ImageId)) - // Enhanced Networking (SriovNetSupport) can only be enabled on HVM AMIs. + // Enhanced Networking can only be enabled on HVM AMIs. // See http://goo.gl/icuXh5 if s.EnhancedNetworking && *image.VirtualizationType != "hvm" { err := fmt.Errorf("Cannot enable enhanced networking, source AMI '%s' is not HVM", s.SourceAmi) diff --git a/builder/amazon/ebssurrogate/step_register_ami.go b/builder/amazon/ebssurrogate/step_register_ami.go index 26dc36bd2..975854b96 100644 --- a/builder/amazon/ebssurrogate/step_register_ami.go +++ b/builder/amazon/ebssurrogate/step_register_ami.go @@ -35,9 +35,14 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction { BlockDeviceMappings: blockDevices, } - // Set SriovNetSupport to "simple". See http://goo.gl/icuXh5 if config.AMIEnhancedNetworking { + // Set SriovNetSupport to "simple". See http://goo.gl/icuXh5 + // As of February 2017, this applies to C3, C4, D2, I2, R3, and M4 (excluding m4.16xlarge) registerOpts.SriovNetSupport = aws.String("simple") + + // Set EnaSupport to true + // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge + registerOpts.EnaSupport = aws.Bool(true) } registerResp, err := ec2conn.RegisterImage(registerOpts) diff --git a/builder/amazon/instance/step_register_ami.go b/builder/amazon/instance/step_register_ami.go index 3f040d77e..c21c618ed 100644 --- a/builder/amazon/instance/step_register_ami.go +++ b/builder/amazon/instance/step_register_ami.go @@ -29,9 +29,14 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction { registerOpts.VirtualizationType = aws.String(config.AMIVirtType) } - // Set SriovNetSupport to "simple". See http://goo.gl/icuXh5 if config.AMIEnhancedNetworking { + // Set SriovNetSupport to "simple". See http://goo.gl/icuXh5 + // As of February 2017, this applies to C3, C4, D2, I2, R3, and M4 (excluding m4.16xlarge) registerOpts.SriovNetSupport = aws.String("simple") + + // Set EnaSupport to true. + // As of February 2017, this applies to C5, I3, P2, R4, X1, and m4.16xlarge + registerOpts.EnaSupport = aws.Bool(true) } registerResp, err := ec2conn.RegisterImage(registerOpts)