mirror of https://github.com/hashicorp/packer
parent
e271e88b49
commit
00ff187d77
@ -0,0 +1,45 @@
|
||||
package classic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type stepCreateImage struct{}
|
||||
|
||||
func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
//hook := state.Get("hook").(packer.Hook)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
comm := state.Get("communicator").(packer.Communicator)
|
||||
commands := []string{
|
||||
"mkdir ./builder",
|
||||
"sudo mkfs -t ext3 /dev/xvdb",
|
||||
"sudo mount /dev/xvdb ./builder",
|
||||
"sudo chown opc:opc ./builder",
|
||||
"cd ./builder",
|
||||
"sudo dd if=/dev/xvdc bs=8M status=progress | cp --sparse=always /dev/stdin diskimage.raw",
|
||||
"tar czSf ./diskimage.tar.gz ./diskimage.raw",
|
||||
}
|
||||
for _, c := range commands {
|
||||
cmd := packer.RemoteCmd{
|
||||
Command: c,
|
||||
}
|
||||
cmd.StartWithUi(comm, ui)
|
||||
}
|
||||
// comm.Start("
|
||||
|
||||
/*
|
||||
// Provision
|
||||
log.Println("Running the provision hook")
|
||||
if err := hook.Run(packer.HookProvision, ui, comm, nil); err != nil {
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
*/
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepCreateImage) Cleanup(state multistep.StateBag) {}
|
||||
@ -0,0 +1,98 @@
|
||||
package classic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/go-oracle-terraform/compute"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type stepCreatePVBuilder struct {
|
||||
name string
|
||||
masterVolumeName string
|
||||
builderVolumeName string
|
||||
}
|
||||
|
||||
func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
// get variables from state
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
ui.Say("Creating builder instance...")
|
||||
|
||||
config := state.Get("config").(*Config)
|
||||
client := state.Get("client").(*compute.ComputeClient)
|
||||
ipAddName := state.Get("ipres_name").(string)
|
||||
secListName := state.Get("security_list").(string)
|
||||
|
||||
// get instances client
|
||||
instanceClient := client.Instances()
|
||||
|
||||
// Instances Input
|
||||
input := &compute.CreateInstanceInput{
|
||||
Name: s.name,
|
||||
Shape: config.Shape,
|
||||
Networking: map[string]compute.NetworkingInfo{
|
||||
"eth0": compute.NetworkingInfo{
|
||||
Nat: []string{ipAddName},
|
||||
SecLists: []string{secListName},
|
||||
},
|
||||
},
|
||||
Storage: []compute.StorageAttachmentInput{
|
||||
{
|
||||
Volume: s.builderVolumeName,
|
||||
Index: 1,
|
||||
},
|
||||
{
|
||||
Volume: s.masterVolumeName,
|
||||
Index: 2,
|
||||
},
|
||||
},
|
||||
ImageList: config.SourceImageList,
|
||||
Attributes: config.attribs,
|
||||
SSHKeys: []string{config.Comm.SSHKeyPairName},
|
||||
}
|
||||
|
||||
instanceInfo, err := instanceClient.CreateInstance(input)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Problem creating instance: %s", err)
|
||||
ui.Error(err.Error())
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
state.Put("builder_instance_info", instanceInfo)
|
||||
state.Put("builder_instance_id", instanceInfo.ID)
|
||||
ui.Message(fmt.Sprintf("Created builder instance: %s.", instanceInfo.ID))
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepCreatePVBuilder) Cleanup(state multistep.StateBag) {
|
||||
instanceID, ok := state.GetOk("builder_instance_id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// terminate instance
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
client := state.Get("client").(*compute.ComputeClient)
|
||||
config := state.Get("config").(*Config)
|
||||
|
||||
ui.Say("Terminating builder instance...")
|
||||
|
||||
instanceClient := client.Instances()
|
||||
input := &compute.DeleteInstanceInput{
|
||||
Name: config.ImageName,
|
||||
ID: instanceID.(string),
|
||||
}
|
||||
|
||||
err := instanceClient.DeleteInstance(input)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Problem destroying instance: %s", err)
|
||||
ui.Error(err.Error())
|
||||
state.Put("error", err)
|
||||
return
|
||||
}
|
||||
// TODO wait for instance state to change to deleted?
|
||||
ui.Say("Terminated builder instance.")
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package classic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/go-oracle-terraform/compute"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type stepCreatePVMaster struct {
|
||||
name string
|
||||
volumeName string
|
||||
}
|
||||
|
||||
func (s *stepCreatePVMaster) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
// get variables from state
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
ui.Say("Creating master instance...")
|
||||
|
||||
config := state.Get("config").(*Config)
|
||||
client := state.Get("client").(*compute.ComputeClient)
|
||||
ipAddName := state.Get("ipres_name").(string)
|
||||
secListName := state.Get("security_list").(string)
|
||||
|
||||
// get instances client
|
||||
instanceClient := client.Instances()
|
||||
|
||||
// Instances Input
|
||||
input := &compute.CreateInstanceInput{
|
||||
Name: s.name,
|
||||
Shape: config.Shape,
|
||||
Networking: map[string]compute.NetworkingInfo{
|
||||
"eth0": compute.NetworkingInfo{
|
||||
Nat: []string{ipAddName},
|
||||
SecLists: []string{secListName},
|
||||
},
|
||||
},
|
||||
Storage: []compute.StorageAttachmentInput{
|
||||
{
|
||||
Volume: s.volumeName,
|
||||
Index: 1,
|
||||
},
|
||||
},
|
||||
BootOrder: []int{1},
|
||||
Attributes: config.attribs,
|
||||
SSHKeys: []string{config.Comm.SSHKeyPairName},
|
||||
}
|
||||
|
||||
instanceInfo, err := instanceClient.CreateInstance(input)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Problem creating instance: %s", err)
|
||||
ui.Error(err.Error())
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
state.Put("master_instance_info", instanceInfo)
|
||||
state.Put("master_instance_id", instanceInfo.ID)
|
||||
ui.Message(fmt.Sprintf("Created master instance: %s.", instanceInfo.ID))
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepCreatePVMaster) Cleanup(state multistep.StateBag) {
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package classic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/go-oracle-terraform/compute"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type stepTerminatePVMaster struct {
|
||||
}
|
||||
|
||||
func (s *stepTerminatePVMaster) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
// get variables from state
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
ui.Say("Deleting master Instance...")
|
||||
|
||||
client := state.Get("client").(*compute.ComputeClient)
|
||||
instanceInfo := state.Get("master_instance_info").(*compute.InstanceInfo)
|
||||
|
||||
// get instances client
|
||||
instanceClient := client.Instances()
|
||||
|
||||
// Instances Input
|
||||
input := &compute.DeleteInstanceInput{
|
||||
Name: instanceInfo.Name,
|
||||
ID: instanceInfo.ID,
|
||||
}
|
||||
|
||||
err := instanceClient.DeleteInstance(input)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Problem creating instance: %s", err)
|
||||
ui.Error(err.Error())
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
ui.Message(fmt.Sprintf("Deleted master instance: %s.", instanceInfo.ID))
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepTerminatePVMaster) Cleanup(state multistep.StateBag) {
|
||||
}
|
||||
Loading…
Reference in new issue