REFACTOR: do not pass comm ref through statebag
This commit is contained in:
parent
fdda18e392
commit
cd3bdc9e38
|
@ -4,7 +4,6 @@ import (
|
|||
proxmoxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/hcl/v2/hcldec"
|
||||
proxmox "github.com/hashicorp/packer/builder/proxmox/common"
|
||||
"github.com/hashicorp/packer/helper/communicator"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
|
||||
|
@ -31,13 +30,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
|
|||
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("clone-config", &b.config)
|
||||
state.Put("comm", &b.config.Comm)
|
||||
|
||||
preSteps := []multistep.Step{
|
||||
&StepSshKeyPair{
|
||||
Debug: b.config.PackerDebug,
|
||||
DebugKeyPath: fmt.Sprintf("%s.pem", b.config.PackerBuildName),
|
||||
Comm: &b.config.Comm,
|
||||
},
|
||||
}
|
||||
postSteps := []multistep.Step{}
|
||||
|
@ -51,7 +48,7 @@ type cloneVMCreator struct{}
|
|||
func (*cloneVMCreator) Create(vmRef *proxmoxapi.VmRef, config proxmoxapi.ConfigQemu, state multistep.StateBag) error {
|
||||
client := state.Get("proxmoxClient").(*proxmoxapi.Client)
|
||||
c := state.Get("clone-config").(*Config)
|
||||
comm := state.Get("comm").(*communicator.Config)
|
||||
comm := state.Get("config").(*proxmox.Config).Comm
|
||||
|
||||
fullClone := 1
|
||||
if c.FullClone.False() {
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
common "github.com/hashicorp/packer/builder/proxmox/common"
|
||||
"github.com/hashicorp/packer/common/uuid"
|
||||
"github.com/hashicorp/packer/helper/communicator"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/helper/ssh"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
|
@ -17,19 +17,19 @@ import (
|
|||
type StepSshKeyPair struct {
|
||||
Debug bool
|
||||
DebugKeyPath string
|
||||
Comm *communicator.Config
|
||||
}
|
||||
|
||||
func (s *StepSshKeyPair) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
c := state.Get("config").(*common.Config)
|
||||
|
||||
if s.Comm.SSHPassword != "" {
|
||||
if c.Comm.SSHPassword != "" {
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
if s.Comm.SSHPrivateKeyFile != "" {
|
||||
if c.Comm.SSHPrivateKeyFile != "" {
|
||||
ui.Say("Using existing SSH private key for the communicator...")
|
||||
privateKeyBytes, err := s.Comm.ReadSSHPrivateKeyFile()
|
||||
privateKeyBytes, err := c.Comm.ReadSSHPrivateKeyFile()
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
|
@ -44,15 +44,15 @@ func (s *StepSshKeyPair) Run(ctx context.Context, state multistep.StateBag) mult
|
|||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
s.Comm.SSHPrivateKey = privateKeyBytes
|
||||
s.Comm.SSHKeyPairName = kp.Comment
|
||||
s.Comm.SSHTemporaryKeyPairName = kp.Comment
|
||||
s.Comm.SSHPublicKey = kp.PublicKeyAuthorizedKeysLine
|
||||
c.Comm.SSHPrivateKey = privateKeyBytes
|
||||
c.Comm.SSHKeyPairName = kp.Comment
|
||||
c.Comm.SSHTemporaryKeyPairName = kp.Comment
|
||||
c.Comm.SSHPublicKey = kp.PublicKeyAuthorizedKeysLine
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
if s.Comm.SSHAgentAuth {
|
||||
if c.Comm.SSHAgentAuth {
|
||||
ui.Say("Using local SSH Agent to authenticate connections for the communicator...")
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
@ -67,11 +67,11 @@ func (s *StepSshKeyPair) Run(ctx context.Context, state multistep.StateBag) mult
|
|||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
s.Comm.SSHKeyPairName = kp.Comment
|
||||
s.Comm.SSHTemporaryKeyPairName = kp.Comment
|
||||
s.Comm.SSHPrivateKey = kp.PrivateKeyPemBlock
|
||||
s.Comm.SSHPublicKey = kp.PublicKeyAuthorizedKeysLine
|
||||
s.Comm.SSHClearAuthorizedKeys = true
|
||||
c.Comm.SSHKeyPairName = kp.Comment
|
||||
c.Comm.SSHTemporaryKeyPairName = kp.Comment
|
||||
c.Comm.SSHPrivateKey = kp.PrivateKeyPemBlock
|
||||
c.Comm.SSHPublicKey = kp.PublicKeyAuthorizedKeysLine
|
||||
c.Comm.SSHClearAuthorizedKeys = true
|
||||
|
||||
ui.Say("Created ephemeral SSH key pair for communicator")
|
||||
|
||||
|
|
|
@ -55,9 +55,6 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook, state
|
|||
state.Put("ui", ui)
|
||||
|
||||
comm := &b.config.Comm
|
||||
if state.Get("comm") != nil {
|
||||
comm = state.Get("comm").(*communicator.Config)
|
||||
}
|
||||
|
||||
// Build the steps
|
||||
coreSteps := []multistep.Step{
|
||||
|
|
Loading…
Reference in New Issue