oracle-classic variable volume size WIP
This commit is contained in:
parent
a1d6c7c916
commit
e271e88b49
|
@ -60,8 +60,19 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
state.Put("ui", ui)
|
state.Put("ui", ui)
|
||||||
state.Put("client", client)
|
state.Put("client", client)
|
||||||
|
|
||||||
|
var steps []multistep.Step
|
||||||
|
if b.config.PersistentVolumeSize != "" {
|
||||||
|
steps = []multistep.Step{
|
||||||
|
&stepCreatePersistentVolume{
|
||||||
|
volumeSize: b.config.PersistentVolumeSize,
|
||||||
|
volumeName: b.config.PersistentVolumeName,
|
||||||
|
latencyStorage: b.config.PersistentVolumeLatencyStorage,
|
||||||
|
sourceImageList: b.config.SourceImageList,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// Build the steps
|
// Build the steps
|
||||||
steps := []multistep.Step{
|
steps = []multistep.Step{
|
||||||
&ocommon.StepKeyPair{
|
&ocommon.StepKeyPair{
|
||||||
Debug: b.config.PackerDebug,
|
Debug: b.config.PackerDebug,
|
||||||
Comm: &b.config.Comm,
|
Comm: &b.config.Comm,
|
||||||
|
@ -86,6 +97,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
&stepSnapshot{},
|
&stepSnapshot{},
|
||||||
&stepListImages{},
|
&stepListImages{},
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Run the steps
|
// Run the steps
|
||||||
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
|
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
|
||||||
|
|
|
@ -29,6 +29,11 @@ type Config struct {
|
||||||
apiEndpointURL *url.URL
|
apiEndpointURL *url.URL
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
|
// PersistentVolumeSize lets us control the volume size by using persistent boot storage
|
||||||
|
PersistentVolumeSize string `mapstructure:"persistent_volume_size"`
|
||||||
|
PersistentVolumeName string `mapstructure:"persistent_volume_name"`
|
||||||
|
PersistentVolumeLatencyStorage bool `mapstructure:"persistent_volume_latency_storage"`
|
||||||
|
|
||||||
ImageName string `mapstructure:"image_name"`
|
ImageName string `mapstructure:"image_name"`
|
||||||
Shape string `mapstructure:"shape"`
|
Shape string `mapstructure:"shape"`
|
||||||
SourceImageList string `mapstructure:"source_image_list"`
|
SourceImageList string `mapstructure:"source_image_list"`
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
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 {
|
||||||
|
volumeSize string
|
||||||
|
volumeName string
|
||||||
|
latencyStorage bool
|
||||||
|
sourceImageList string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepCreatePersistentVolume) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
|
client := state.Get("client").(*compute.ComputeClient)
|
||||||
|
|
||||||
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
ui.Say("Creating Volume...")
|
||||||
|
|
||||||
|
var properties string
|
||||||
|
if s.latencyStorage {
|
||||||
|
properties = "/oracle/public/storage/latency"
|
||||||
|
} else {
|
||||||
|
properties = "/oracle/public/storage/default"
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &compute.CreateStorageVolumeInput{
|
||||||
|
Name: s.volumeName,
|
||||||
|
Size: s.volumeSize,
|
||||||
|
Properties: []string{properties},
|
||||||
|
ImageList: s.sourceImageList,
|
||||||
|
Bootable: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
sc := client.StorageVolumes()
|
||||||
|
cc, err := sc.CreateStorageVolume(c)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Error creating persistent volume: %s", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
state.Put("error", err)
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: wait to become available
|
||||||
|
|
||||||
|
ui.Message(fmt.Sprintf("Created volume: %s", cc.Name))
|
||||||
|
return multistep.ActionContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepCreatePersistentVolume) Cleanup(state multistep.StateBag) {
|
||||||
|
}
|
Loading…
Reference in New Issue