warn about dangling segments.
The client offers no way to bulk delete keys, so for now let's just warn users. The issue is tracked upstream here: https://github.com/hashicorp/go-oracle-terraform/issues/172
This commit is contained in:
parent
ce30e1053e
commit
be91c99d29
|
@ -97,8 +97,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
&stepAddKeysToAPI{},
|
||||
&stepSecurity{},
|
||||
&stepCreatePVMaster{
|
||||
name: fmt.Sprintf("master-instance_%s", runID),
|
||||
volumeName: fmt.Sprintf("master-storage_%s", runID),
|
||||
Name: fmt.Sprintf("master-instance_%s", runID),
|
||||
VolumeName: fmt.Sprintf("master-storage_%s", runID),
|
||||
},
|
||||
&communicator.StepConnect{
|
||||
Config: &b.config.Comm,
|
||||
|
@ -108,13 +108,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
&common.StepProvision{},
|
||||
&stepTerminatePVMaster{},
|
||||
&stepCreatePVBuilder{
|
||||
name: fmt.Sprintf("builder-instance_%s", runID),
|
||||
builderVolumeName: fmt.Sprintf("builder-storage_%s", runID),
|
||||
Name: fmt.Sprintf("builder-instance_%s", runID),
|
||||
BuilderVolumeName: fmt.Sprintf("builder-storage_%s", runID),
|
||||
},
|
||||
&stepAttachVolume{
|
||||
volumeName: fmt.Sprintf("master-storage_%s", runID),
|
||||
index: 2,
|
||||
instanceInfoKey: "builder_instance_info",
|
||||
VolumeName: fmt.Sprintf("master-storage_%s", runID),
|
||||
Index: 2,
|
||||
InstanceInfoKey: "builder_instance_info",
|
||||
},
|
||||
&communicator.StepConnect{
|
||||
Config: &builderCommConfig,
|
||||
|
@ -122,7 +122,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
SSHConfig: b.config.Comm.SSHConfigFunc(),
|
||||
},
|
||||
&stepUploadImage{
|
||||
uploadImageCommand: b.config.BuilderUploadImageCommand,
|
||||
UploadImageCommand: b.config.BuilderUploadImageCommand,
|
||||
},
|
||||
&stepCreateImage{},
|
||||
&stepListImages{},
|
||||
|
|
|
@ -10,21 +10,21 @@ import (
|
|||
)
|
||||
|
||||
type stepAttachVolume struct {
|
||||
index int
|
||||
volumeName string
|
||||
instanceInfoKey string
|
||||
Index int
|
||||
VolumeName string
|
||||
InstanceInfoKey string
|
||||
}
|
||||
|
||||
func (s *stepAttachVolume) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
client := state.Get("client").(*compute.ComputeClient)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
instanceInfo := state.Get(s.instanceInfoKey).(*compute.InstanceInfo)
|
||||
instanceInfo := state.Get(s.InstanceInfoKey).(*compute.InstanceInfo)
|
||||
|
||||
saClient := client.StorageAttachments()
|
||||
saInput := &compute.CreateStorageAttachmentInput{
|
||||
Index: s.index,
|
||||
Index: s.Index,
|
||||
InstanceName: instanceInfo.Name + "/" + instanceInfo.ID,
|
||||
StorageVolumeName: s.volumeName,
|
||||
StorageVolumeName: s.VolumeName,
|
||||
}
|
||||
|
||||
sa, err := saClient.CreateStorageAttachment(saInput)
|
||||
|
@ -35,14 +35,14 @@ func (s *stepAttachVolume) Run(_ context.Context, state multistep.StateBag) mult
|
|||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
state.Put(s.instanceInfoKey+"/attachment", sa)
|
||||
state.Put(s.InstanceInfoKey+"/attachment", sa)
|
||||
|
||||
ui.Message("Volume attached to instance.")
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepAttachVolume) Cleanup(state multistep.StateBag) {
|
||||
sa, ok := state.GetOk(s.instanceInfoKey + "/attachment")
|
||||
sa, ok := state.GetOk(s.InstanceInfoKey + "/attachment")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ import (
|
|||
)
|
||||
|
||||
type stepCreatePVBuilder struct {
|
||||
name string
|
||||
builderVolumeName string
|
||||
Name string
|
||||
BuilderVolumeName string
|
||||
}
|
||||
|
||||
func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
|
@ -30,7 +30,7 @@ func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) m
|
|||
|
||||
// Instances Input
|
||||
input := &compute.CreateInstanceInput{
|
||||
Name: s.name,
|
||||
Name: s.Name,
|
||||
Shape: config.Shape,
|
||||
Networking: map[string]compute.NetworkingInfo{
|
||||
"eth0": compute.NetworkingInfo{
|
||||
|
@ -40,7 +40,7 @@ func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) m
|
|||
},
|
||||
Storage: []compute.StorageAttachmentInput{
|
||||
{
|
||||
Volume: s.builderVolumeName,
|
||||
Volume: s.BuilderVolumeName,
|
||||
Index: 1,
|
||||
},
|
||||
},
|
||||
|
@ -80,7 +80,7 @@ func (s *stepCreatePVBuilder) Cleanup(state multistep.StateBag) {
|
|||
|
||||
instanceClient := client.Instances()
|
||||
input := &compute.DeleteInstanceInput{
|
||||
Name: s.name,
|
||||
Name: s.Name,
|
||||
ID: instanceID.(string),
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
)
|
||||
|
||||
type stepCreatePVMaster struct {
|
||||
name string
|
||||
volumeName string
|
||||
Name string
|
||||
VolumeName string
|
||||
}
|
||||
|
||||
func (s *stepCreatePVMaster) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
|
@ -29,7 +29,7 @@ func (s *stepCreatePVMaster) Run(_ context.Context, state multistep.StateBag) mu
|
|||
|
||||
// Instances Input
|
||||
input := &compute.CreateInstanceInput{
|
||||
Name: s.name,
|
||||
Name: s.Name,
|
||||
Shape: config.Shape,
|
||||
Networking: map[string]compute.NetworkingInfo{
|
||||
"eth0": compute.NetworkingInfo{
|
||||
|
@ -39,7 +39,7 @@ func (s *stepCreatePVMaster) Run(_ context.Context, state multistep.StateBag) mu
|
|||
},
|
||||
Storage: []compute.StorageAttachmentInput{
|
||||
{
|
||||
Volume: s.volumeName,
|
||||
Volume: s.VolumeName,
|
||||
Index: 1,
|
||||
},
|
||||
},
|
||||
|
@ -81,7 +81,7 @@ func (s *stepCreatePVMaster) Cleanup(state multistep.StateBag) {
|
|||
|
||||
instanceClient := client.Instances()
|
||||
input := &compute.DeleteInstanceInput{
|
||||
Name: s.name,
|
||||
Name: s.Name,
|
||||
ID: instanceID.(string),
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package classic
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
|
@ -11,7 +12,8 @@ import (
|
|||
)
|
||||
|
||||
type stepUploadImage struct {
|
||||
uploadImageCommand string
|
||||
UploadImageCommand string
|
||||
segmentPath string
|
||||
}
|
||||
|
||||
type uploadCmdData struct {
|
||||
|
@ -30,15 +32,16 @@ func (s *stepUploadImage) Run(_ context.Context, state multistep.StateBag) multi
|
|||
|
||||
imageFile := fmt.Sprintf("%s.tar.gz", config.ImageName)
|
||||
state.Put("image_file", imageFile)
|
||||
s.segmentPath = fmt.Sprintf("compute_images_segments/%s/_segment_/%s", imageFile, runID)
|
||||
|
||||
config.ctx.Data = uploadCmdData{
|
||||
Username: config.Username,
|
||||
Password: config.Password,
|
||||
AccountID: config.IdentityDomain,
|
||||
ImageFile: imageFile,
|
||||
SegmentPath: fmt.Sprintf("compute_images_segments/%s/_segment_/%s", imageFile, runID),
|
||||
SegmentPath: s.segmentPath,
|
||||
}
|
||||
uploadImageCmd, err := interpolate.Render(s.uploadImageCommand, &config.ctx)
|
||||
uploadImageCmd, err := interpolate.Render(s.UploadImageCommand, &config.ctx)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error processing image upload command: %s", err)
|
||||
state.Put("error", err)
|
||||
|
@ -80,4 +83,11 @@ func (s *stepUploadImage) Run(_ context.Context, state multistep.StateBag) multi
|
|||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepUploadImage) Cleanup(state multistep.StateBag) {}
|
||||
func (s *stepUploadImage) Cleanup(state multistep.StateBag) {
|
||||
_, cancelled := state.GetOk(multistep.StateCancelled)
|
||||
_, halted := state.GetOk(multistep.StateHalted)
|
||||
if !cancelled && !halted {
|
||||
return
|
||||
}
|
||||
log.Printf("Some segments may need to be manually cleaned at '%s'", s.segmentPath)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue