2018-09-05 18:01:14 -04:00
|
|
|
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"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2018-09-05 18:01:14 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type stepCreatePersistentVolume struct {
|
2018-10-24 17:40:32 -04:00
|
|
|
VolumeSize string
|
|
|
|
VolumeName string
|
|
|
|
Bootable bool
|
|
|
|
ImageList string
|
|
|
|
ImageListEntry int
|
2018-09-05 18:01:14 -04:00
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
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)
|
2018-09-05 18:01:14 -04:00
|
|
|
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2018-09-05 18:01:14 -04:00
|
|
|
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,
|
2018-09-05 18:01:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2018-09-05 18:01:14 -04:00
|
|
|
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
|
|
|
|
2020-11-19 14:54:31 -05: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))
|
2018-09-05 18:01:14 -04:00
|
|
|
}
|