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"
"time"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/multistep"
)
@ -82,7 +81,7 @@ type Driver interface {
// NewDriver returns a new driver implementation for this operating
// 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{}
if dconfig.RemoteType != "" {
@ -97,7 +96,7 @@ func NewDriver(dconfig *DriverConfig, config *SSHConfig, commConfig *communicato
CacheDatastore: dconfig.RemoteCacheDatastore,
CacheDirectory: dconfig.RemoteCacheDirectory,
VMName: vmName,
CommConfig: *commConfig,
CommConfig: *(&config.Comm),
},
}

View File

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

View File

@ -26,7 +26,7 @@ type StepExport struct {
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)
if hidePassword {
password = "****"
@ -37,7 +37,7 @@ func (s *StepExport) generateArgs(c *DriverConfig, displayName string, outputPat
"-tt=" + s.Format,
"vi://" + c.RemoteUser + ":" + password + "@" + c.RemoteHost + "/" + displayName,
outputPath,
s.OutputDir,
}
return append(s.OVFToolOptions, args...)
}

View File

@ -66,17 +66,9 @@ type Config struct {
Serial string `mapstructure:"serial"`
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"`
VMXTemplatePath string `mapstructure:"vmx_template_path"`
CommConfig communicator.Config `mapstructure:",squash"`
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) {
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 {
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,
VMName: b.config.VMName,
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)
}
if b.config.CommConfig.WinRMUser != "username" {
t.Errorf("bad winrm_username: %s", b.config.CommConfig.WinRMUser)
if b.config.SSHConfig.Comm.WinRMUser != "username" {
t.Errorf("bad winrm_username: %s", b.config.SSHConfig.Comm.WinRMUser)
}
if b.config.CommConfig.WinRMPassword != "password" {
t.Errorf("bad winrm_password: %s", b.config.CommConfig.WinRMPassword)
if b.config.SSHConfig.Comm.WinRMPassword != "password" {
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)
}
}
@ -487,13 +487,13 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
t.Fatalf("should not have error: %s", err)
}
if b.config.CommConfig.SSHUsername != "username" {
t.Errorf("bad ssh_username: %s", b.config.CommConfig.SSHUsername)
if b.config.SSHConfig.Comm.SSHUsername != "username" {
t.Errorf("bad ssh_username: %s", b.config.SSHConfig.Comm.SSHUsername)
}
if b.config.CommConfig.SSHPassword != "password" {
t.Errorf("bad ssh_password: %s", b.config.CommConfig.SSHPassword)
if b.config.SSHConfig.Comm.SSHPassword != "password" {
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)
}
}

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
// a VMware image.
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 {
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"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/common/bootcommand"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
@ -30,13 +29,9 @@ type Config struct {
Linked bool `mapstructure:"linked"`
RemoteType string `mapstructure:"remote_type"`
SkipCompaction bool `mapstructure:"skip_compaction"`
BootCommand []string `mapstructure:"boot_command"`
SourcePath string `mapstructure:"source_path"`
VMName string `mapstructure:"vm_name"`
CommConfig communicator.Config `mapstructure:",squash"`
ctx interpolate.Context
}