* the very initial builder: just clones the VM * removed post-processor * builder now waits for IP address * more separated steps * clean up * added run and shutdown steps * added step connecting via ssh * changed the BuilderId to a proper one * added shutdown command, only echo works * added cleanup * removed wainting for VM to stop, removed error on the non-zero exit status * removed BuildSuccessFlag * refactored config structures; fixed interpolation of json template * the rest of configuration refactoring * removed duplicated parameters from Config * removed duplicated parameters drom Config * changed BuilderId and Artifact * create a dedicated step for VM hardware configuration * merged StepSetupCloningEnv into StepCloneVM * improved cleanup * added proper handling of 'disconnected' command exit status; added guest os shutdown before halting the machine [in case when no shutdown command is given] * refactored non-conventional variable and field names * removed redundant fields from Artifact * removed the success field at all * removed ArtifactFiles * removed unnecessary warnings * minor change in parameters structure
45 lines
915 B
Go
45 lines
915 B
Go
package main
|
|
|
|
import (
|
|
"github.com/mitchellh/multistep"
|
|
"github.com/hashicorp/packer/packer"
|
|
"strconv"
|
|
"github.com/vmware/govmomi/vim25/types"
|
|
)
|
|
|
|
type StepConfigureHW struct{
|
|
config *Config
|
|
}
|
|
|
|
func (s *StepConfigureHW) Run(state multistep.StateBag) multistep.StepAction {
|
|
ui := state.Get("ui").(packer.Ui)
|
|
ui.Say("configuring virtual hardware...")
|
|
|
|
var confSpec types.VirtualMachineConfigSpec
|
|
// configure HW
|
|
if s.config.Cpus != "" {
|
|
cpus, err := strconv.Atoi(s.config.Cpus)
|
|
if err != nil {
|
|
state.Put("error", err)
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
confSpec.NumCPUs = int32(cpus)
|
|
}
|
|
if s.config.Ram != "" {
|
|
ram, err := strconv.Atoi(s.config.Ram)
|
|
if err != nil {
|
|
state.Put("error", err)
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
confSpec.MemoryMB = int64(ram)
|
|
}
|
|
|
|
state.Put("confSpec", confSpec)
|
|
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
func (s *StepConfigureHW) Cleanup(multistep.StateBag) {}
|