Restructure config
This commit is contained in:
parent
e671f722cb
commit
1241e64d93
@ -20,11 +20,7 @@ type CommonConfig struct {
|
||||
bootcommand.VNCConfig `mapstructure:",squash"`
|
||||
commonsteps.HTTPConfig `mapstructure:",squash"`
|
||||
|
||||
Username string `mapstructure:"remote_username"`
|
||||
Password string `mapstructure:"remote_password"`
|
||||
HostIp string `mapstructure:"remote_host"`
|
||||
HostPort int `mapstructure:"remote_port"`
|
||||
HostSSHPort int `mapstructure:"remote_ssh_port"`
|
||||
XenConfig `mapstructure:",squash"`
|
||||
|
||||
VMName string `mapstructure:"vm_name"`
|
||||
VMDescription string `mapstructure:"vm_description"`
|
||||
@ -34,10 +30,7 @@ type CommonConfig struct {
|
||||
NetworkNames []string `mapstructure:"network_names"`
|
||||
ExportNetworkNames []string `mapstructure:"export_network_names"`
|
||||
|
||||
VCPUsMax uint `mapstructure:"vcpus_max"`
|
||||
VCPUsAtStartup uint `mapstructure:"vcpus_atstartup"`
|
||||
VMMemory uint `mapstructure:"vm_memory"`
|
||||
PlatformArgs map[string]string `mapstructure:"platform_args"`
|
||||
PlatformArgs map[string]string `mapstructure:"platform_args"`
|
||||
|
||||
shutdowncommand.ShutdownConfig `mapstructure:",squash"`
|
||||
|
||||
@ -51,6 +44,7 @@ type CommonConfig struct {
|
||||
IPGetter string `mapstructure:"ip_getter"`
|
||||
|
||||
Firmware string `mapstructure:"firmware"`
|
||||
HardwareConfig
|
||||
|
||||
ctx interpolate.Context
|
||||
}
|
||||
@ -79,34 +73,10 @@ func (c *CommonConfig) Prepare(upper interface{}, raws ...interface{}) ([]string
|
||||
|
||||
// Set default values
|
||||
|
||||
if c.VCPUsMax == 0 {
|
||||
c.VCPUsMax = 1
|
||||
}
|
||||
|
||||
if c.VCPUsAtStartup == 0 {
|
||||
c.VCPUsAtStartup = 1
|
||||
}
|
||||
|
||||
if c.VCPUsAtStartup > c.VCPUsMax {
|
||||
c.VCPUsAtStartup = c.VCPUsMax
|
||||
}
|
||||
|
||||
if c.VMMemory == 0 {
|
||||
c.VMMemory = 1024
|
||||
}
|
||||
|
||||
if c.Firmware == "" {
|
||||
c.Firmware = "bios"
|
||||
}
|
||||
|
||||
if c.HostPort == 0 {
|
||||
c.HostPort = 443
|
||||
}
|
||||
|
||||
if c.HostSSHPort == 0 {
|
||||
c.HostSSHPort = 22
|
||||
}
|
||||
|
||||
if c.ToolsIsoName == "" {
|
||||
c.ToolsIsoName = "xs-tools.iso"
|
||||
}
|
||||
@ -156,18 +126,6 @@ func (c *CommonConfig) Prepare(upper interface{}, raws ...interface{}) ([]string
|
||||
|
||||
// Validation
|
||||
|
||||
if c.Username == "" {
|
||||
errs = packersdk.MultiErrorAppend(errs, errors.New("remote_username must be specified."))
|
||||
}
|
||||
|
||||
if c.Password == "" {
|
||||
errs = packersdk.MultiErrorAppend(errs, errors.New("remote_password must be specified."))
|
||||
}
|
||||
|
||||
if c.HostIp == "" {
|
||||
errs = packersdk.MultiErrorAppend(errs, errors.New("remote_host must be specified."))
|
||||
}
|
||||
|
||||
if c.HTTPPortMin > c.HTTPPortMax {
|
||||
errs = packersdk.MultiErrorAppend(errs, errors.New("the HTTP min port must be less than the max"))
|
||||
}
|
||||
@ -190,9 +148,17 @@ func (c *CommonConfig) Prepare(upper interface{}, raws ...interface{}) ([]string
|
||||
errs = packersdk.MultiErrorAppend(errs, errors.New("ip_getter must be one of 'auto', 'tools', 'http'"))
|
||||
}
|
||||
|
||||
commConfigWarnings, es := c.CommConfig.Prepare(&c.ctx)
|
||||
innerWarnings, es := c.CommConfig.Prepare(&c.ctx)
|
||||
errs = packersdk.MultiErrorAppend(errs, es...)
|
||||
warnings = append(warnings, commConfigWarnings...)
|
||||
warnings = append(warnings, innerWarnings...)
|
||||
|
||||
innerWarnings, es = c.XenConfig.Prepare(&c.ctx)
|
||||
errs = packersdk.MultiErrorAppend(errs, es...)
|
||||
warnings = append(warnings, innerWarnings...)
|
||||
|
||||
innerWarnings, es = c.HardwareConfig.Prepare(&c.ctx)
|
||||
errs = packersdk.MultiErrorAppend(errs, es...)
|
||||
warnings = append(warnings, innerWarnings...)
|
||||
|
||||
errs = packersdk.MultiErrorAppend(errs, c.VNCConfig.Prepare(&c.ctx)...)
|
||||
errs = packersdk.MultiErrorAppend(errs, c.HTTPConfig.Prepare(&c.ctx)...)
|
||||
|
35
builder/xenserver/common/config/hardware_config.go
Normal file
35
builder/xenserver/common/config/hardware_config.go
Normal file
@ -0,0 +1,35 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
|
||||
)
|
||||
|
||||
type HardwareConfig struct {
|
||||
VCPUsMax uint `mapstructure:"vcpus_max"`
|
||||
VCPUsAtStartup uint `mapstructure:"vcpus_atstartup"`
|
||||
VMMemory uint `mapstructure:"vm_memory"`
|
||||
}
|
||||
|
||||
func (c *HardwareConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs []error) {
|
||||
// Default values
|
||||
|
||||
if c.VCPUsMax == 0 {
|
||||
c.VCPUsMax = 1
|
||||
}
|
||||
|
||||
if c.VCPUsAtStartup == 0 {
|
||||
c.VCPUsAtStartup = 1
|
||||
}
|
||||
|
||||
if c.VCPUsAtStartup > c.VCPUsMax {
|
||||
c.VCPUsAtStartup = c.VCPUsMax
|
||||
}
|
||||
|
||||
if c.VMMemory == 0 {
|
||||
c.VMMemory = 1024
|
||||
}
|
||||
|
||||
// Validation
|
||||
|
||||
return
|
||||
}
|
42
builder/xenserver/common/config/xen_config.go
Normal file
42
builder/xenserver/common/config/xen_config.go
Normal file
@ -0,0 +1,42 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
|
||||
)
|
||||
|
||||
type XenConfig struct {
|
||||
Username string `mapstructure:"remote_username"`
|
||||
Password string `mapstructure:"remote_password"`
|
||||
HostIp string `mapstructure:"remote_host"`
|
||||
HostPort int `mapstructure:"remote_port"`
|
||||
HostSSHPort int `mapstructure:"remote_ssh_port"`
|
||||
}
|
||||
|
||||
func (c *XenConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs []error) {
|
||||
// Default values
|
||||
|
||||
if c.HostPort == 0 {
|
||||
c.HostPort = 443
|
||||
}
|
||||
|
||||
if c.HostSSHPort == 0 {
|
||||
c.HostSSHPort = 22
|
||||
}
|
||||
|
||||
// Validation
|
||||
|
||||
if c.Username == "" {
|
||||
errs = append(errs, errors.New("remote_username must be specified."))
|
||||
}
|
||||
|
||||
if c.Password == "" {
|
||||
errs = append(errs, errors.New("remote_password must be specified."))
|
||||
}
|
||||
|
||||
if c.HostIp == "" {
|
||||
errs = append(errs, errors.New("remote_host must be specified."))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue
Block a user