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{},
|
&stepAddKeysToAPI{},
|
||||||
&stepSecurity{},
|
&stepSecurity{},
|
||||||
&stepCreatePVMaster{
|
&stepCreatePVMaster{
|
||||||
name: fmt.Sprintf("master-instance_%s", runID),
|
Name: fmt.Sprintf("master-instance_%s", runID),
|
||||||
volumeName: fmt.Sprintf("master-storage_%s", runID),
|
VolumeName: fmt.Sprintf("master-storage_%s", runID),
|
||||||
},
|
},
|
||||||
&communicator.StepConnect{
|
&communicator.StepConnect{
|
||||||
Config: &b.config.Comm,
|
Config: &b.config.Comm,
|
||||||
|
@ -108,13 +108,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
&common.StepProvision{},
|
&common.StepProvision{},
|
||||||
&stepTerminatePVMaster{},
|
&stepTerminatePVMaster{},
|
||||||
&stepCreatePVBuilder{
|
&stepCreatePVBuilder{
|
||||||
name: fmt.Sprintf("builder-instance_%s", runID),
|
Name: fmt.Sprintf("builder-instance_%s", runID),
|
||||||
builderVolumeName: fmt.Sprintf("builder-storage_%s", runID),
|
BuilderVolumeName: fmt.Sprintf("builder-storage_%s", runID),
|
||||||
},
|
},
|
||||||
&stepAttachVolume{
|
&stepAttachVolume{
|
||||||
volumeName: fmt.Sprintf("master-storage_%s", runID),
|
VolumeName: fmt.Sprintf("master-storage_%s", runID),
|
||||||
index: 2,
|
Index: 2,
|
||||||
instanceInfoKey: "builder_instance_info",
|
InstanceInfoKey: "builder_instance_info",
|
||||||
},
|
},
|
||||||
&communicator.StepConnect{
|
&communicator.StepConnect{
|
||||||
Config: &builderCommConfig,
|
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(),
|
SSHConfig: b.config.Comm.SSHConfigFunc(),
|
||||||
},
|
},
|
||||||
&stepUploadImage{
|
&stepUploadImage{
|
||||||
uploadImageCommand: b.config.BuilderUploadImageCommand,
|
UploadImageCommand: b.config.BuilderUploadImageCommand,
|
||||||
},
|
},
|
||||||
&stepCreateImage{},
|
&stepCreateImage{},
|
||||||
&stepListImages{},
|
&stepListImages{},
|
||||||
|
|
|
@ -10,21 +10,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type stepAttachVolume struct {
|
type stepAttachVolume struct {
|
||||||
index int
|
Index int
|
||||||
volumeName string
|
VolumeName string
|
||||||
instanceInfoKey string
|
InstanceInfoKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepAttachVolume) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *stepAttachVolume) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
client := state.Get("client").(*compute.ComputeClient)
|
client := state.Get("client").(*compute.ComputeClient)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
instanceInfo := state.Get(s.instanceInfoKey).(*compute.InstanceInfo)
|
instanceInfo := state.Get(s.InstanceInfoKey).(*compute.InstanceInfo)
|
||||||
|
|
||||||
saClient := client.StorageAttachments()
|
saClient := client.StorageAttachments()
|
||||||
saInput := &compute.CreateStorageAttachmentInput{
|
saInput := &compute.CreateStorageAttachmentInput{
|
||||||
Index: s.index,
|
Index: s.Index,
|
||||||
InstanceName: instanceInfo.Name + "/" + instanceInfo.ID,
|
InstanceName: instanceInfo.Name + "/" + instanceInfo.ID,
|
||||||
StorageVolumeName: s.volumeName,
|
StorageVolumeName: s.VolumeName,
|
||||||
}
|
}
|
||||||
|
|
||||||
sa, err := saClient.CreateStorageAttachment(saInput)
|
sa, err := saClient.CreateStorageAttachment(saInput)
|
||||||
|
@ -35,14 +35,14 @@ func (s *stepAttachVolume) Run(_ context.Context, state multistep.StateBag) mult
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
state.Put(s.instanceInfoKey+"/attachment", sa)
|
state.Put(s.InstanceInfoKey+"/attachment", sa)
|
||||||
|
|
||||||
ui.Message("Volume attached to instance.")
|
ui.Message("Volume attached to instance.")
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepAttachVolume) Cleanup(state multistep.StateBag) {
|
func (s *stepAttachVolume) Cleanup(state multistep.StateBag) {
|
||||||
sa, ok := state.GetOk(s.instanceInfoKey + "/attachment")
|
sa, ok := state.GetOk(s.InstanceInfoKey + "/attachment")
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type stepCreatePVBuilder struct {
|
type stepCreatePVBuilder struct {
|
||||||
name string
|
Name string
|
||||||
builderVolumeName string
|
BuilderVolumeName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
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
|
// Instances Input
|
||||||
input := &compute.CreateInstanceInput{
|
input := &compute.CreateInstanceInput{
|
||||||
Name: s.name,
|
Name: s.Name,
|
||||||
Shape: config.Shape,
|
Shape: config.Shape,
|
||||||
Networking: map[string]compute.NetworkingInfo{
|
Networking: map[string]compute.NetworkingInfo{
|
||||||
"eth0": compute.NetworkingInfo{
|
"eth0": compute.NetworkingInfo{
|
||||||
|
@ -40,7 +40,7 @@ func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) m
|
||||||
},
|
},
|
||||||
Storage: []compute.StorageAttachmentInput{
|
Storage: []compute.StorageAttachmentInput{
|
||||||
{
|
{
|
||||||
Volume: s.builderVolumeName,
|
Volume: s.BuilderVolumeName,
|
||||||
Index: 1,
|
Index: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -80,7 +80,7 @@ func (s *stepCreatePVBuilder) Cleanup(state multistep.StateBag) {
|
||||||
|
|
||||||
instanceClient := client.Instances()
|
instanceClient := client.Instances()
|
||||||
input := &compute.DeleteInstanceInput{
|
input := &compute.DeleteInstanceInput{
|
||||||
Name: s.name,
|
Name: s.Name,
|
||||||
ID: instanceID.(string),
|
ID: instanceID.(string),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type stepCreatePVMaster struct {
|
type stepCreatePVMaster struct {
|
||||||
name string
|
Name string
|
||||||
volumeName string
|
VolumeName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepCreatePVMaster) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
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
|
// Instances Input
|
||||||
input := &compute.CreateInstanceInput{
|
input := &compute.CreateInstanceInput{
|
||||||
Name: s.name,
|
Name: s.Name,
|
||||||
Shape: config.Shape,
|
Shape: config.Shape,
|
||||||
Networking: map[string]compute.NetworkingInfo{
|
Networking: map[string]compute.NetworkingInfo{
|
||||||
"eth0": compute.NetworkingInfo{
|
"eth0": compute.NetworkingInfo{
|
||||||
|
@ -39,7 +39,7 @@ func (s *stepCreatePVMaster) Run(_ context.Context, state multistep.StateBag) mu
|
||||||
},
|
},
|
||||||
Storage: []compute.StorageAttachmentInput{
|
Storage: []compute.StorageAttachmentInput{
|
||||||
{
|
{
|
||||||
Volume: s.volumeName,
|
Volume: s.VolumeName,
|
||||||
Index: 1,
|
Index: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -81,7 +81,7 @@ func (s *stepCreatePVMaster) Cleanup(state multistep.StateBag) {
|
||||||
|
|
||||||
instanceClient := client.Instances()
|
instanceClient := client.Instances()
|
||||||
input := &compute.DeleteInstanceInput{
|
input := &compute.DeleteInstanceInput{
|
||||||
Name: s.name,
|
Name: s.Name,
|
||||||
ID: instanceID.(string),
|
ID: instanceID.(string),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package classic
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
|
@ -11,7 +12,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type stepUploadImage struct {
|
type stepUploadImage struct {
|
||||||
uploadImageCommand string
|
UploadImageCommand string
|
||||||
|
segmentPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
type uploadCmdData struct {
|
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)
|
imageFile := fmt.Sprintf("%s.tar.gz", config.ImageName)
|
||||||
state.Put("image_file", imageFile)
|
state.Put("image_file", imageFile)
|
||||||
|
s.segmentPath = fmt.Sprintf("compute_images_segments/%s/_segment_/%s", imageFile, runID)
|
||||||
|
|
||||||
config.ctx.Data = uploadCmdData{
|
config.ctx.Data = uploadCmdData{
|
||||||
Username: config.Username,
|
Username: config.Username,
|
||||||
Password: config.Password,
|
Password: config.Password,
|
||||||
AccountID: config.IdentityDomain,
|
AccountID: config.IdentityDomain,
|
||||||
ImageFile: imageFile,
|
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 {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error processing image upload command: %s", err)
|
err := fmt.Errorf("Error processing image upload command: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
@ -80,4 +83,11 @@ func (s *stepUploadImage) Run(_ context.Context, state multistep.StateBag) multi
|
||||||
return multistep.ActionContinue
|
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