packer-cn/builder/oracle/classic/step_create_persistent_volu...

68 lines
1.7 KiB
Go
Raw Normal View History

package classic
import (
"context"
"fmt"
"github.com/hashicorp/go-oracle-terraform/compute"
2020-11-17 19:31:03 -05:00
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
)
type stepCreatePersistentVolume struct {
2018-10-24 17:40:32 -04:00
VolumeSize string
VolumeName string
Bootable bool
ImageList string
ImageListEntry int
}
func (s *stepCreatePersistentVolume) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
2018-10-24 17:08:11 -04:00
client := state.Get("client").(*compute.Client)
ui := state.Get("ui").(packersdk.Ui)
ui.Say("Creating Volume...")
c := &compute.CreateStorageVolumeInput{
2018-10-24 17:40:32 -04:00
Name: s.VolumeName,
Size: s.VolumeSize,
ImageList: s.ImageList,
ImageListEntry: s.ImageListEntry,
Properties: []string{"/oracle/public/storage/default"},
Bootable: s.Bootable,
}
sc := client.StorageVolumes()
cc, err := sc.CreateStorageVolume(c)
if err != nil {
2018-09-06 01:44:31 -04:00
err = fmt.Errorf("Error creating persistent storage volume: %s", err)
ui.Error(err.Error())
state.Put("error", err)
return multistep.ActionHalt
}
ui.Message(fmt.Sprintf("Created volume: %s", cc.Name))
return multistep.ActionContinue
}
func (s *stepCreatePersistentVolume) Cleanup(state multistep.StateBag) {
2018-10-24 17:08:11 -04:00
client := state.Get("client").(*compute.Client)
2018-09-06 01:44:31 -04:00
ui := state.Get("ui").(packersdk.Ui)
2018-09-06 01:44:31 -04:00
ui.Say("Cleaning up Volume...")
c := &compute.DeleteStorageVolumeInput{
2018-10-24 17:40:32 -04:00
Name: s.VolumeName,
2018-09-06 01:44:31 -04:00
}
sc := client.StorageVolumes()
if err := sc.DeleteStorageVolume(c); err != nil {
ui.Error(fmt.Sprintf("Error cleaning up persistent storage volume: %s", err))
return
}
2018-10-24 17:40:32 -04:00
ui.Message(fmt.Sprintf("Deleted volume: %s", s.VolumeName))
}