Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 10 additions & 25 deletions builder/xenserver/common/common_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ type CommonConfig struct {
BootCommand []string `mapstructure:"boot_command"`
ShutdownCommand string `mapstructure:"shutdown_command"`

RawBootWait string `mapstructure:"boot_wait"`
BootWait time.Duration
RawDhcpWait string `mapstructure:"dhcp_wait"`
DhcpWait time.Duration
RawBootWait string `mapstructure:"boot_wait"`
BootWait time.Duration `mapstructure-to-hcl2:",skip"`
RawDhcpWait string `mapstructure:"dhcp_wait"`
DhcpWait time.Duration `mapstructure-to-hcl2:",skip"`

ToolsIsoName string `mapstructure:"tools_iso_name"`

Expand All @@ -57,14 +57,7 @@ type CommonConfig struct {

// SSHHostPortMin uint `mapstructure:"ssh_host_port_min"`
// SSHHostPortMax uint `mapstructure:"ssh_host_port_max"`
SSHKeyPath string `mapstructure:"ssh_key_path"`
SSHPassword string `mapstructure:"ssh_password"`
SSHPort uint `mapstructure:"ssh_port"`
SSHUser string `mapstructure:"ssh_username"`
SSHConfig `mapstructure:",squash"`

RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"`
SSHWaitTimeout time.Duration
SSHConfig `mapstructure:",squash"`

OutputDir string `mapstructure:"output_directory"`
Format string `mapstructure:"format"`
Expand Down Expand Up @@ -118,8 +111,8 @@ func (c *CommonConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig
c.HTTPPortMax = 9000
}

if c.RawSSHWaitTimeout == "" {
c.RawSSHWaitTimeout = "200m"
if c.Comm.SSHWaitTimeout == 0 {
c.Comm.SSHWaitTimeout = 200 * time.Minute
}

if c.FloppyFiles == nil {
Expand All @@ -136,13 +129,10 @@ func (c *CommonConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig
}
*/

if c.SSHPort == 0 {
c.SSHPort = 22
if c.Comm.SSHPort == 0 {
c.Comm.SSHPort = 22
}

if c.RawSSHWaitTimeout == "" {
c.RawSSHWaitTimeout = "20m"
}

if c.OutputDir == "" {
c.OutputDir = fmt.Sprintf("output-%s", pc.PackerBuildName)
Expand Down Expand Up @@ -211,15 +201,10 @@ func (c *CommonConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig
}
*/

if c.SSHUser == "" {
if c.Comm.SSHUsername == "" {
errs = append(errs, errors.New("An ssh_username must be specified."))
}

c.SSHWaitTimeout, err = time.ParseDuration(c.RawSSHWaitTimeout)
if err != nil {
errs = append(errs, fmt.Errorf("Failed to parse ssh_wait_timeout: %s", err))
}

switch c.Format {
case "xva", "xva_compressed", "vdi_raw", "vdi_vhd", "none":
default:
Expand Down
7 changes: 2 additions & 5 deletions builder/xenserver/common/config.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
//go:generate packer-sdc mapstructure-to-hcl2 -type Config
//go:generate packer-sdc mapstructure-to-hcl2 -type Config,DiskConfig
package common

import (
"time"

"github.com/hashicorp/packer-plugin-sdk/common"
"github.com/hashicorp/packer-plugin-sdk/communicator"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
)

type Config struct {
common.PackerConfig `mapstructure:",squash"`
CommonConfig `mapstructure:",squash"`
Comm communicator.Config `mapstructure:",squash"`

VCPUsMax uint `mapstructure:"vcpus_max"`
VCPUsAtStartup uint `mapstructure:"vcpus_atstartup"`
VMMemory uint `mapstructure:"vm_memory"`
CloneTemplate string `mapstructure:"clone_template"`
VMOtherConfig map[string]string `mapstructure:"vm_other_config"`
VMTags []string `mapstructure:"vm_tags"`

ISOChecksum string `mapstructure:"iso_checksum"`
ISOUrls []string `mapstructure:"iso_urls"`
Expand All @@ -29,7 +26,7 @@ type Config struct {
PlatformArgs map[string]string `mapstructure:"platform_args"`

RawInstallTimeout string `mapstructure:"install_timeout"`
InstallTimeout time.Duration ``
InstallTimeout time.Duration `mapstructure-to-hcl2:",skip"`
SourcePath string `mapstructure:"source_path"`

Firmware string `mapstructure:"firmware"`
Expand Down
92 changes: 52 additions & 40 deletions builder/xenserver/common/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions builder/xenserver/common/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*gossh.ClientConf
return func(state multistep.StateBag) (*gossh.ClientConfig, error) {
config := state.Get("commonconfig").(CommonConfig)
auth := []gossh.AuthMethod{
gossh.Password(config.SSHPassword),
gossh.Password(config.Comm.SSHPassword),
}

if config.SSHKeyPath != "" {
Expand All @@ -58,7 +58,7 @@ func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*gossh.ClientConf
}

return &gossh.ClientConfig{
User: config.SSHUser,
User: config.Comm.SSHUsername,
Auth: auth,
HostKeyCallback: gossh.InsecureIgnoreHostKey(),
}, nil
Expand Down
7 changes: 1 addition & 6 deletions builder/xenserver/common/ssh_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package common

import (
"errors"
"time"

"github.com/hashicorp/packer-plugin-sdk/communicator"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
Expand All @@ -17,8 +16,7 @@ type SSHConfig struct {

// These are deprecated, but we keep them around for BC
// TODO(@mitchellh): remove
SSHKeyPath string `mapstructure:"ssh_key_path"`
SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout"`
SSHKeyPath string `mapstructure:"ssh_key_path"`
}

func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
Expand All @@ -34,9 +32,6 @@ func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
if c.SSHKeyPath != "" {
c.Comm.SSHPrivateKeyFile = c.SSHKeyPath
}
if c.SSHWaitTimeout != 0 {
c.Comm.SSHTimeout = c.SSHWaitTimeout
}

errs := c.Comm.Prepare(ctx)
if c.SSHHostPortMin > c.SSHHostPortMax {
Expand Down
2 changes: 1 addition & 1 deletion builder/xenserver/common/step_start_on_himn.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ func HimnSSHIP(state multistep.StateBag) (string, error) {

func HimnSSHPort(state multistep.StateBag) (uint, error) {
config := state.Get("commonconfig").(CommonConfig)
return config.SSHPort, nil
return uint(config.Comm.SSHPort), nil
}