From 84bb5d2f6f121197099318f79a0fd8cb749350b2 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Fri, 19 Oct 2018 22:51:58 -0700 Subject: [PATCH] create image list --- builder/oracle/classic/builder.go | 2 ++ builder/oracle/classic/step_create_image.go | 12 ++++++------ builder/oracle/classic/step_list_images.go | 4 ++-- builder/oracle/classic/step_snapshot.go | 1 + 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index 425487ff5..07f85f883 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -125,6 +125,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe uploadImageCommand: b.config.BuilderUploadImageCommand, imageName: b.config.ImageName, }, + &stepListImages{}, &common.StepCleanupTempKeys{ Comm: &b.config.Comm, }, @@ -164,6 +165,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe return nil, rawErr.(error) } + // TODO fix me // If there is no snapshot, then just return if _, ok := state.GetOk("snapshot"); !ok { return nil, nil diff --git a/builder/oracle/classic/step_create_image.go b/builder/oracle/classic/step_create_image.go index 70ba6f339..2c3a221ac 100644 --- a/builder/oracle/classic/step_create_image.go +++ b/builder/oracle/classic/step_create_image.go @@ -102,6 +102,7 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi return multistep.ActionHalt } log.Printf("Registered machine image: %+v", mi) + state.Put("machine_image", mi.Name) /* Registered machine image: &{ Account:/Compute-ptstest/cloud_storage @@ -120,16 +121,15 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi } */ /* TODO: - * POST /machineimage/ (DONE) - POST /imagelist/ - POST /imagelistentry/ + * POST /machineimage/ DONE + POST /imagelist/ DONE + POST /imagelistentry/ DONE in that order. - * re-use step_list_images + * re-use step_list_images DONE * Documentation * Configuration (master/builder images & entry, destination stuff, etc) * split master/builder image/connection config. i.e. build anything, master only linux - * correct artifact - * segments go in to sub-directory (entry) + * correct artifact DONE */ return multistep.ActionContinue diff --git a/builder/oracle/classic/step_list_images.go b/builder/oracle/classic/step_list_images.go index 1326bb480..ed453af5b 100644 --- a/builder/oracle/classic/step_list_images.go +++ b/builder/oracle/classic/step_list_images.go @@ -45,12 +45,12 @@ func (s *stepListImages) Run(_ context.Context, state multistep.StateBag) multis } // Now create and image list entry for the image into that list. - snap := state.Get("snapshot").(*compute.Snapshot) + machineImage := state.Get("machine_image").(string) version := len(imList.Entries) + 1 entriesClient := client.ImageListEntries() entriesInput := compute.CreateImageListEntryInput{ Name: config.DestImageList, - MachineImages: []string{config.Identifier(snap.MachineImage)}, + MachineImages: []string{config.Identifier(machineImage)}, Version: version, } entryInfo, err := entriesClient.CreateImageListEntry(&entriesInput) diff --git a/builder/oracle/classic/step_snapshot.go b/builder/oracle/classic/step_snapshot.go index 64058966d..83047ccfa 100644 --- a/builder/oracle/classic/step_snapshot.go +++ b/builder/oracle/classic/step_snapshot.go @@ -39,6 +39,7 @@ func (s *stepSnapshot) Run(_ context.Context, state multistep.StateBag) multiste return multistep.ActionHalt } state.Put("snapshot", snap) + state.Put("machine_image", snap.MachineImage) ui.Message(fmt.Sprintf("Created snapshot: %s.", snap.Name)) return multistep.ActionContinue }