github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/builder/amazon/instance/step_bundle_volume.go (about) 1 package instance 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/goamz/ec2" 6 "github.com/mitchellh/multistep" 7 "github.com/mitchellh/packer/packer" 8 ) 9 10 type bundleCmdData struct { 11 AccountId string 12 Architecture string 13 CertPath string 14 Destination string 15 KeyPath string 16 Prefix string 17 PrivatePath string 18 } 19 20 type StepBundleVolume struct{} 21 22 func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepAction { 23 comm := state["communicator"].(packer.Communicator) 24 config := state["config"].(*Config) 25 instance := state["instance"].(*ec2.Instance) 26 ui := state["ui"].(packer.Ui) 27 x509RemoteCertPath := state["x509RemoteCertPath"].(string) 28 x509RemoteKeyPath := state["x509RemoteKeyPath"].(string) 29 30 // Verify the AMI tools are available 31 ui.Say("Checking for EC2 AMI tools...") 32 cmd := &packer.RemoteCmd{Command: "ec2-ami-tools-version"} 33 if err := comm.Start(cmd); err != nil { 34 state["error"] = fmt.Errorf("Error checking for AMI tools: %s", err) 35 ui.Error(state["error"].(error).Error()) 36 return multistep.ActionHalt 37 } 38 cmd.Wait() 39 40 if cmd.ExitStatus != 0 { 41 state["error"] = fmt.Errorf( 42 "The EC2 AMI tools could not be detected. These must be manually\n" + 43 "via a provisioner or some other means and are required for Packer\n" + 44 "to create an instance-store AMI.") 45 ui.Error(state["error"].(error).Error()) 46 return multistep.ActionHalt 47 } 48 49 // Bundle the volume 50 var err error 51 config.BundleVolCommand, err = config.tpl.Process(config.BundleVolCommand, bundleCmdData{ 52 AccountId: config.AccountId, 53 Architecture: instance.Architecture, 54 CertPath: x509RemoteCertPath, 55 Destination: config.BundleDestination, 56 KeyPath: x509RemoteKeyPath, 57 Prefix: config.BundlePrefix, 58 PrivatePath: config.X509UploadPath, 59 }) 60 if err != nil { 61 err := fmt.Errorf("Error processing bundle volume command: %s", err) 62 state["error"] = err 63 ui.Error(err.Error()) 64 return multistep.ActionHalt 65 } 66 67 ui.Say("Bundling the volume...") 68 cmd = new(packer.RemoteCmd) 69 cmd.Command = config.BundleVolCommand 70 if err := cmd.StartWithUi(comm, ui); err != nil { 71 state["error"] = fmt.Errorf("Error bundling volume: %s", err) 72 ui.Error(state["error"].(error).Error()) 73 return multistep.ActionHalt 74 } 75 76 if cmd.ExitStatus != 0 { 77 state["error"] = fmt.Errorf( 78 "Volume bundling failed. Please see the output above for more\n" + 79 "details on what went wrong.") 80 ui.Error(state["error"].(error).Error()) 81 return multistep.ActionHalt 82 } 83 84 // Store the manifest path 85 manifestName := config.BundlePrefix + ".manifest.xml" 86 state["manifest_name"] = manifestName 87 state["manifest_path"] = fmt.Sprintf( 88 "%s/%s", config.BundleDestination, manifestName) 89 90 return multistep.ActionContinue 91 } 92 93 func (s *StepBundleVolume) Cleanup(map[string]interface{}) {}