2018-09-05 18:01:14 -04:00
|
|
|
package classic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-oracle-terraform/compute"
|
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
ui := state.Get("ui").(packer.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,
|
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
|
|
|
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
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
|
|
|
}
|