diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index d744d00bf..d486e5fcc 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -76,17 +76,18 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe steps = []multistep.Step{ &stepCreatePersistentVolume{ - volumeSize: fmt.Sprintf("%d", b.config.PersistentVolumeSize), - volumeName: fmt.Sprintf("master-storage_%s", runID), - sourceImageList: b.config.SourceImageList, - bootable: true, + VolumeSize: fmt.Sprintf("%d", b.config.PersistentVolumeSize), + VolumeName: fmt.Sprintf("master-storage_%s", runID), + ImageList: b.config.SourceImageList, + ImageListEntry: b.config.SourceImageListEntry, + Bootable: true, }, &stepCreatePersistentVolume{ - // We multiple the master volume size by 2, because we need - // room to tarball the disk image. We also need to chunk the - // tar ball, but we can remove the original disk image first. - volumeSize: fmt.Sprintf("%d", b.config.PersistentVolumeSize*2), - volumeName: fmt.Sprintf("builder-storage_%s", runID), + // We double the master volume size because we need room to + // tarball the disk image. We also need to chunk the tar ball, + // but we can remove the original disk image first. + VolumeSize: fmt.Sprintf("%d", b.config.PersistentVolumeSize*2), + VolumeName: fmt.Sprintf("builder-storage_%s", runID), }, &ocommon.StepKeyPair{ Debug: b.config.PackerDebug, diff --git a/builder/oracle/classic/config.go b/builder/oracle/classic/config.go index 804508140..59eafa2d4 100644 --- a/builder/oracle/classic/config.go +++ b/builder/oracle/classic/config.go @@ -30,11 +30,12 @@ type Config struct { apiEndpointURL *url.URL // Image - ImageName string `mapstructure:"image_name"` - Shape string `mapstructure:"shape"` - SourceImageList string `mapstructure:"source_image_list"` - SnapshotTimeout time.Duration `mapstructure:"snapshot_timeout"` - DestImageList string `mapstructure:"dest_image_list"` + ImageName string `mapstructure:"image_name"` + Shape string `mapstructure:"shape"` + SourceImageList string `mapstructure:"source_image_list"` + SourceImageListEntry int `mapstructure:"source_image_list_entry"` + SnapshotTimeout time.Duration `mapstructure:"snapshot_timeout"` + DestImageList string `mapstructure:"dest_image_list"` // Attributes and Attributes file are both optional and mutually exclusive. Attributes string `mapstructure:"attributes"` AttributesFile string `mapstructure:"attributes_file"` diff --git a/builder/oracle/classic/pv_config.go b/builder/oracle/classic/pv_config.go index 300c5393e..9626603c9 100644 --- a/builder/oracle/classic/pv_config.go +++ b/builder/oracle/classic/pv_config.go @@ -1,18 +1,24 @@ package classic import ( + "fmt" + "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/template/interpolate" ) +const imageListDefault = "/oracle/public/OL_7.2_UEKR4_x86_64" + type PVConfig struct { // PersistentVolumeSize lets us control the volume size by using persistent boot storage PersistentVolumeSize int `mapstructure:"persistent_volume_size"` - BuilderImageList string `mapstructure:"builder_image_list"` BuilderUploadImageCommand string `mapstructure:"builder_upload_image_command"` + + // Builder Image + BuilderShape string `mapstructure:"builder_shape"` + BuilderImageList string `mapstructure:"builder_image_list"` + BuilderImageListEntry int `mapstructure:"builder_image_list_entry"` /* TODO: - default to OL image - make sure if set then PVS is above some way to choose which connection to use for master possible ignore everything for builder and always use SSH keys */ @@ -25,7 +31,29 @@ func (c *PVConfig) IsPV() bool { func (c *PVConfig) Prepare(ctx *interpolate.Context) (errs *packer.MultiError) { if !c.IsPV() { - return nil + if c.BuilderShape != "" { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("`builder_shape` has no meaning when `persistent_volume_size` is not set.")) + } + if c.BuilderImageList != "" { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("`builder_shape_image_list` has no meaning when `persistent_volume_size` is not set.")) + } + return errs + } + + if c.BuilderShape == "" { + c.BuilderShape = "oc3" + } + + if c.BuilderImageList == "" { + c.BuilderImageList = imageListDefault + } + + // Entry 5 is a working default, so let's set it if the entry is unset and + // we're using the default image list + if c.BuilderImageList == imageListDefault && c.BuilderImageListEntry == 0 { + c.BuilderImageListEntry = 5 } if c.BuilderUploadImageCommand == "" { diff --git a/builder/oracle/classic/step_create_instance.go b/builder/oracle/classic/step_create_instance.go index d481f5d3b..3edd014e9 100644 --- a/builder/oracle/classic/step_create_instance.go +++ b/builder/oracle/classic/step_create_instance.go @@ -34,6 +34,7 @@ func (s *stepCreateInstance) Run(_ context.Context, state multistep.StateBag) mu Name: config.ImageName, Shape: config.Shape, ImageList: config.SourceImageList, + Entry: config.SourceImageListEntry, Networking: map[string]compute.NetworkingInfo{"eth0": netInfo}, Attributes: config.attribs, } diff --git a/builder/oracle/classic/step_create_persistent_volume.go b/builder/oracle/classic/step_create_persistent_volume.go index 24e8dcdf5..177b7e6b1 100644 --- a/builder/oracle/classic/step_create_persistent_volume.go +++ b/builder/oracle/classic/step_create_persistent_volume.go @@ -10,10 +10,11 @@ import ( ) type stepCreatePersistentVolume struct { - volumeSize string - volumeName string - bootable bool - sourceImageList string + VolumeSize string + VolumeName string + Bootable bool + ImageList string + ImageListEntry int } func (s *stepCreatePersistentVolume) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { @@ -23,11 +24,12 @@ func (s *stepCreatePersistentVolume) Run(_ context.Context, state multistep.Stat ui.Say("Creating Volume...") c := &compute.CreateStorageVolumeInput{ - Name: s.volumeName, - Size: s.volumeSize, - ImageList: s.sourceImageList, - Properties: []string{"/oracle/public/storage/default"}, - Bootable: s.bootable, + Name: s.VolumeName, + Size: s.VolumeSize, + ImageList: s.ImageList, + ImageListEntry: s.ImageListEntry, + Properties: []string{"/oracle/public/storage/default"}, + Bootable: s.Bootable, } sc := client.StorageVolumes() @@ -59,7 +61,7 @@ func (s *stepCreatePersistentVolume) Cleanup(state multistep.StateBag) { ui.Say("Cleaning up Volume...") c := &compute.DeleteStorageVolumeInput{ - Name: s.volumeName, + Name: s.VolumeName, } sc := client.StorageVolumes() @@ -69,5 +71,5 @@ func (s *stepCreatePersistentVolume) Cleanup(state multistep.StateBag) { return } - ui.Message(fmt.Sprintf("Deleted volume: %s", s.volumeName)) + ui.Message(fmt.Sprintf("Deleted volume: %s", s.VolumeName)) } diff --git a/builder/oracle/classic/step_create_pv_builder.go b/builder/oracle/classic/step_create_pv_builder.go index 2d3cb3693..a2109586d 100644 --- a/builder/oracle/classic/step_create_pv_builder.go +++ b/builder/oracle/classic/step_create_pv_builder.go @@ -31,7 +31,7 @@ func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) m // Instances Input input := &compute.CreateInstanceInput{ Name: s.Name, - Shape: config.Shape, + Shape: config.BuilderShape, Networking: map[string]compute.NetworkingInfo{ "eth0": compute.NetworkingInfo{ Nat: []string{ipAddName}, @@ -44,10 +44,9 @@ func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) m Index: 1, }, }, - ImageList: config.SourceImageList, - Attributes: config.attribs, - SSHKeys: []string{config.Comm.SSHKeyPairName}, - Entry: 5, + ImageList: config.BuilderImageList, + SSHKeys: []string{config.Comm.SSHKeyPairName}, + Entry: config.BuilderImageListEntry, } instanceInfo, err := instanceClient.CreateInstance(input)