remove redundant config; CommConfig was already a part of the SSSHConfig struct

This commit is contained in:
Megan Marsh 2018-10-29 11:24:26 -07:00
parent fa12113eaf
commit f18bb19f96
7 changed files with 22 additions and 34 deletions

View File

@ -15,7 +15,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
) )
@ -82,7 +81,7 @@ type Driver interface {
// NewDriver returns a new driver implementation for this operating // NewDriver returns a new driver implementation for this operating
// system, or an error if the driver couldn't be initialized. // system, or an error if the driver couldn't be initialized.
func NewDriver(dconfig *DriverConfig, config *SSHConfig, commConfig *communicator.Config, vmName string) (Driver, error) { func NewDriver(dconfig *DriverConfig, config *SSHConfig, vmName string) (Driver, error) {
drivers := []Driver{} drivers := []Driver{}
if dconfig.RemoteType != "" { if dconfig.RemoteType != "" {
@ -97,7 +96,7 @@ func NewDriver(dconfig *DriverConfig, config *SSHConfig, commConfig *communicato
CacheDatastore: dconfig.RemoteCacheDatastore, CacheDatastore: dconfig.RemoteCacheDatastore,
CacheDirectory: dconfig.RemoteCacheDirectory, CacheDirectory: dconfig.RemoteCacheDirectory,
VMName: vmName, VMName: vmName,
CommConfig: *commConfig, CommConfig: *(&config.Comm),
}, },
} }

View File

@ -11,6 +11,7 @@ type ExportConfig struct {
OVFToolOptions []string `mapstructure:"ovftool_options"` OVFToolOptions []string `mapstructure:"ovftool_options"`
SkipExport bool `mapstructure:"skip_export"` SkipExport bool `mapstructure:"skip_export"`
KeepRegistered bool `mapstructure:"keep_registered"` KeepRegistered bool `mapstructure:"keep_registered"`
SkipCompaction bool `mapstructure:"skip_compaction"`
} }
func (c *ExportConfig) Prepare(ctx *interpolate.Context) []error { func (c *ExportConfig) Prepare(ctx *interpolate.Context) []error {

View File

@ -26,7 +26,7 @@ type StepExport struct {
OutputDir string OutputDir string
} }
func (s *StepExport) generateArgs(c *DriverConfig, displayName string, outputPath string, hidePassword bool) []string { func (s *StepExport) generateArgs(c *DriverConfig, displayName string, hidePassword bool) []string {
password := url.QueryEscape(c.RemotePassword) password := url.QueryEscape(c.RemotePassword)
if hidePassword { if hidePassword {
password = "****" password = "****"
@ -37,7 +37,7 @@ func (s *StepExport) generateArgs(c *DriverConfig, displayName string, outputPat
"-tt=" + s.Format, "-tt=" + s.Format,
"vi://" + c.RemoteUser + ":" + password + "@" + c.RemoteHost + "/" + displayName, "vi://" + c.RemoteUser + ":" + password + "@" + c.RemoteHost + "/" + displayName,
outputPath, s.OutputDir,
} }
return append(s.OVFToolOptions, args...) return append(s.OVFToolOptions, args...)
} }

View File

@ -66,17 +66,9 @@ type Config struct {
Serial string `mapstructure:"serial"` Serial string `mapstructure:"serial"`
Parallel string `mapstructure:"parallel"` Parallel string `mapstructure:"parallel"`
// booting a guest
KeepRegistered bool `mapstructure:"keep_registered"`
OVFToolOptions []string `mapstructure:"ovftool_options"`
SkipCompaction bool `mapstructure:"skip_compaction"`
SkipExport bool `mapstructure:"skip_export"`
VMXDiskTemplatePath string `mapstructure:"vmx_disk_template_path"` VMXDiskTemplatePath string `mapstructure:"vmx_disk_template_path"`
VMXTemplatePath string `mapstructure:"vmx_template_path"` VMXTemplatePath string `mapstructure:"vmx_template_path"`
CommConfig communicator.Config `mapstructure:",squash"`
ctx interpolate.Context ctx interpolate.Context
} }
@ -232,7 +224,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
driver, err := vmwcommon.NewDriver(&b.config.DriverConfig, &b.config.SSHConfig, &b.config.CommConfig, b.config.VMName) driver, err := vmwcommon.NewDriver(&b.config.DriverConfig, &b.config.SSHConfig, b.config.VMName)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed creating VMware driver: %s", err) return nil, fmt.Errorf("Failed creating VMware driver: %s", err)
} }
@ -369,6 +361,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SkipExport: b.config.SkipExport, SkipExport: b.config.SkipExport,
VMName: b.config.VMName, VMName: b.config.VMName,
OVFToolOptions: b.config.OVFToolOptions, OVFToolOptions: b.config.OVFToolOptions,
OutputDir: b.config.OutputDir,
}, },
} }

View File

@ -459,13 +459,13 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
if b.config.CommConfig.WinRMUser != "username" { if b.config.SSHConfig.Comm.WinRMUser != "username" {
t.Errorf("bad winrm_username: %s", b.config.CommConfig.WinRMUser) t.Errorf("bad winrm_username: %s", b.config.SSHConfig.Comm.WinRMUser)
} }
if b.config.CommConfig.WinRMPassword != "password" { if b.config.SSHConfig.Comm.WinRMPassword != "password" {
t.Errorf("bad winrm_password: %s", b.config.CommConfig.WinRMPassword) t.Errorf("bad winrm_password: %s", b.config.SSHConfig.Comm.WinRMPassword)
} }
if host := b.config.CommConfig.Host(); host != "1.2.3.4" { if host := b.config.SSHConfig.Comm.Host(); host != "1.2.3.4" {
t.Errorf("bad host: %s", host) t.Errorf("bad host: %s", host)
} }
} }
@ -487,13 +487,13 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
if b.config.CommConfig.SSHUsername != "username" { if b.config.SSHConfig.Comm.SSHUsername != "username" {
t.Errorf("bad ssh_username: %s", b.config.CommConfig.SSHUsername) t.Errorf("bad ssh_username: %s", b.config.SSHConfig.Comm.SSHUsername)
} }
if b.config.CommConfig.SSHPassword != "password" { if b.config.SSHConfig.Comm.SSHPassword != "password" {
t.Errorf("bad ssh_password: %s", b.config.CommConfig.SSHPassword) t.Errorf("bad ssh_password: %s", b.config.SSHConfig.Comm.SSHPassword)
} }
if host := b.config.CommConfig.Host(); host != "1.2.3.4" { if host := b.config.SSHConfig.Comm.Host(); host != "1.2.3.4" {
t.Errorf("bad host: %s", host) t.Errorf("bad host: %s", host)
} }
} }

View File

@ -34,7 +34,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Run executes a Packer build and returns a packer.Artifact representing // Run executes a Packer build and returns a packer.Artifact representing
// a VMware image. // a VMware image.
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
driver, err := vmwcommon.NewDriver(&b.config.DriverConfig, &b.config.SSHConfig, &b.config.CommConfig, b.config.VMName) driver, err := vmwcommon.NewDriver(&b.config.DriverConfig, &b.config.SSHConfig, b.config.VMName)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed creating VMware driver: %s", err) return nil, fmt.Errorf("Failed creating VMware driver: %s", err)
} }

View File

@ -7,7 +7,6 @@ import (
vmwcommon "github.com/hashicorp/packer/builder/vmware/common" vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
"github.com/hashicorp/packer/common" "github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/common/bootcommand" "github.com/hashicorp/packer/common/bootcommand"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate" "github.com/hashicorp/packer/template/interpolate"
@ -28,14 +27,10 @@ type Config struct {
vmwcommon.VMXConfig `mapstructure:",squash"` vmwcommon.VMXConfig `mapstructure:",squash"`
vmwcommon.ExportConfig `mapstructure:",squash"` vmwcommon.ExportConfig `mapstructure:",squash"`
Linked bool `mapstructure:"linked"` Linked bool `mapstructure:"linked"`
RemoteType string `mapstructure:"remote_type"` RemoteType string `mapstructure:"remote_type"`
SkipCompaction bool `mapstructure:"skip_compaction"` SourcePath string `mapstructure:"source_path"`
BootCommand []string `mapstructure:"boot_command"` VMName string `mapstructure:"vm_name"`
SourcePath string `mapstructure:"source_path"`
VMName string `mapstructure:"vm_name"`
CommConfig communicator.Config `mapstructure:",squash"`
ctx interpolate.Context ctx interpolate.Context
} }