From 66cf27fe316206a54a589c1271b87a967ebf2919 Mon Sep 17 00:00:00 2001 From: Marin Salinas Date: Fri, 22 Feb 2019 09:50:46 -0600 Subject: [PATCH] feature: add step check root device step in chrrot builder --- builder/osc/chroot/builder.go | 13 ++++++++ builder/osc/chroot/step_check_root_device.go | 32 ++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 builder/osc/chroot/step_check_root_device.go diff --git a/builder/osc/chroot/builder.go b/builder/osc/chroot/builder.go index 12a83bc0c..6843ad179 100644 --- a/builder/osc/chroot/builder.go +++ b/builder/osc/chroot/builder.go @@ -225,6 +225,19 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &StepVmInfo{}, } + if !b.config.FromScratch { + steps = append(steps, + &osccommon.StepSourceOMIInfo{ + SourceOmi: b.config.SourceOMI, + EnableOMISriovNetSupport: b.config.OMISriovNetSupport, + EnableOMIENASupport: b.config.OMIENASupport, + OmiFilters: b.config.SourceOMIFilter, + OMIVirtType: b.config.OMIVirtType, + }, + &StepCheckRootDevice{}, + ) + } + // Run! b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) b.runner.Run(state) diff --git a/builder/osc/chroot/step_check_root_device.go b/builder/osc/chroot/step_check_root_device.go new file mode 100644 index 000000000..e251a1ff5 --- /dev/null +++ b/builder/osc/chroot/step_check_root_device.go @@ -0,0 +1,32 @@ +package chroot + +import ( + "context" + "fmt" + + "github.com/hashicorp/packer/helper/multistep" + "github.com/hashicorp/packer/packer" + "github.com/outscale/osc-go/oapi" +) + +// StepCheckRootDevice makes sure the root device on the AMI is EBS-backed. +type StepCheckRootDevice struct{} + +func (s *StepCheckRootDevice) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { + image := state.Get("source_image").(oapi.Image) + ui := state.Get("ui").(packer.Ui) + + ui.Say("Checking the root device on source AMI...") + + // It must be EBS-backed otherwise the build won't work + if image.RootDeviceType != "ebs" { + err := fmt.Errorf("The root device of the source AMI must be EBS-backed.") + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + + return multistep.ActionContinue +} + +func (s *StepCheckRootDevice) Cleanup(multistep.StateBag) {}