github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/builder/amazon/ebs/step_modify_instance.go (about)

     1  package ebs
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/mitchellh/goamz/ec2"
     7  	"github.com/mitchellh/multistep"
     8  	"github.com/mitchellh/packer/packer"
     9  )
    10  
    11  type stepModifyInstance struct{}
    12  
    13  func (s *stepModifyInstance) Run(state multistep.StateBag) multistep.StepAction {
    14  	config := state.Get("config").(config)
    15  	ec2conn := state.Get("ec2").(*ec2.EC2)
    16  	instance := state.Get("instance").(*ec2.Instance)
    17  	ui := state.Get("ui").(packer.Ui)
    18  
    19  	// Set SriovNetSupport to "simple". See http://goo.gl/icuXh5
    20  	if config.AMIEnhancedNetworking {
    21  		ui.Say("Enabling Enhanced Networking...")
    22  		_, err := ec2conn.ModifyInstance(
    23  			instance.InstanceId,
    24  			&ec2.ModifyInstance{SriovNetSupport: true},
    25  		)
    26  		if err != nil {
    27  			err := fmt.Errorf("Error enabling Enhanced Networking on %s: %s", instance.InstanceId, err)
    28  			state.Put("error", err)
    29  			ui.Error(err.Error())
    30  			return multistep.ActionHalt
    31  		}
    32  	}
    33  
    34  	return multistep.ActionContinue
    35  }
    36  
    37  func (s *stepModifyInstance) Cleanup(state multistep.StateBag) {
    38  	// No cleanup...
    39  }