oracle-classic variable volume size WIP
This commit is contained in:
parent
a1d6c7c916
commit
e271e88b49
|
@ -60,31 +60,43 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
state.Put("ui", ui)
|
||||
state.Put("client", client)
|
||||
|
||||
// Build the steps
|
||||
steps := []multistep.Step{
|
||||
&ocommon.StepKeyPair{
|
||||
Debug: b.config.PackerDebug,
|
||||
Comm: &b.config.Comm,
|
||||
DebugKeyPath: fmt.Sprintf("oci_classic_%s.pem", b.config.PackerBuildName),
|
||||
},
|
||||
&stepCreateIPReservation{},
|
||||
&stepAddKeysToAPI{},
|
||||
&stepSecurity{},
|
||||
&stepCreateInstance{},
|
||||
&communicator.StepConnect{
|
||||
Config: &b.config.Comm,
|
||||
Host: ocommon.CommHost,
|
||||
SSHConfig: b.config.Comm.SSHConfigFunc(),
|
||||
},
|
||||
&common.StepProvision{},
|
||||
&common.StepCleanupTempKeys{
|
||||
Comm: &b.config.Comm,
|
||||
},
|
||||
&common.StepCleanupTempKeys{
|
||||
Comm: &b.config.Comm,
|
||||
},
|
||||
&stepSnapshot{},
|
||||
&stepListImages{},
|
||||
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
|
||||
steps = []multistep.Step{
|
||||
&ocommon.StepKeyPair{
|
||||
Debug: b.config.PackerDebug,
|
||||
Comm: &b.config.Comm,
|
||||
DebugKeyPath: fmt.Sprintf("oci_classic_%s.pem", b.config.PackerBuildName),
|
||||
},
|
||||
&stepCreateIPReservation{},
|
||||
&stepAddKeysToAPI{},
|
||||
&stepSecurity{},
|
||||
&stepCreateInstance{},
|
||||
&communicator.StepConnect{
|
||||
Config: &b.config.Comm,
|
||||
Host: ocommon.CommHost,
|
||||
SSHConfig: b.config.Comm.SSHConfigFunc(),
|
||||
},
|
||||
&common.StepProvision{},
|
||||
&common.StepCleanupTempKeys{
|
||||
Comm: &b.config.Comm,
|
||||
},
|
||||
&common.StepCleanupTempKeys{
|
||||
Comm: &b.config.Comm,
|
||||
},
|
||||
&stepSnapshot{},
|
||||
&stepListImages{},
|
||||
}
|
||||
}
|
||||
|
||||
// Run the steps
|
||||
|
|
|
@ -29,6 +29,11 @@ type Config struct {
|
|||
apiEndpointURL *url.URL
|
||||
|
||||
// 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"`
|
||||
Shape string `mapstructure:"shape"`
|
||||
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