code cleanup
This commit is contained in:
parent
2a43e5039e
commit
84af7f5583
|
@ -60,10 +60,11 @@ Destination:
|
||||||
|
|
||||||
Hardware customization:
|
Hardware customization:
|
||||||
* `CPUs` - number of CPU sockets. Inherited from source VM by default.
|
* `CPUs` - number of CPU sockets. Inherited from source VM by default.
|
||||||
* `ram` - Amount of RAM in megabytes. Inherited from source VM by default.
|
* `RAM` - Amount of RAM in megabytes. Inherited from source VM by default.
|
||||||
|
|
||||||
Post-processing:
|
Post-processing:
|
||||||
* `shutdown_command` - VMware guest tools are used by default.
|
* `shutdown_command` - VMware guest tools are used by default.
|
||||||
|
* `shutdown_timeout` - [Duration](https://golang.org/pkg/time/#ParseDuration) how long to wait for a graceful shutdown. 5 minutes by default.
|
||||||
* `create_snapshot` - add a snapshot, so VM can be used as a base for linked clones. `false` by default.
|
* `create_snapshot` - add a snapshot, so VM can be used as a base for linked clones. `false` by default.
|
||||||
* `convert_to_template` - convert VM to a template. `false` by default.
|
* `convert_to_template` - convert VM to a template. `false` by default.
|
||||||
|
|
||||||
|
@ -93,12 +94,13 @@ Post-processing:
|
||||||
"linked_clone": true,
|
"linked_clone": true,
|
||||||
|
|
||||||
"CPUs": 2,
|
"CPUs": 2,
|
||||||
"ram": 8192,
|
"RAM": 8192,
|
||||||
|
|
||||||
"ssh_username": "root",
|
"ssh_username": "root",
|
||||||
"ssh_password": "{{user `guest_password`}}",
|
"ssh_password": "{{user `guest_password`}}",
|
||||||
|
|
||||||
"shutdown_command": "echo '{{user `guest_password`}}' | sudo -S shutdown -P now",
|
"shutdown_command": "echo '{{user `guest_password`}}' | sudo -S shutdown -P now",
|
||||||
|
"shutdown_timeout": "5m",
|
||||||
"create_snapshot": true,
|
"create_snapshot": true,
|
||||||
"convert_to_template": true
|
"convert_to_template": true
|
||||||
}
|
}
|
||||||
|
|
70
config.go
70
config.go
|
@ -14,45 +14,49 @@ import (
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
common.PackerConfig `mapstructure:",squash"`
|
common.PackerConfig `mapstructure:",squash"`
|
||||||
communicator.Config `mapstructure:",squash"`
|
|
||||||
|
|
||||||
|
// Connection
|
||||||
VCenterHost string `mapstructure:"vcenter_host"`
|
VCenterHost string `mapstructure:"vcenter_host"`
|
||||||
|
Datacenter string `mapstructure:"datacenter"`
|
||||||
Username string `mapstructure:"username"`
|
Username string `mapstructure:"username"`
|
||||||
Password string `mapstructure:"password"`
|
Password string `mapstructure:"password"`
|
||||||
|
|
||||||
// Location
|
// Location
|
||||||
Template string `mapstructure:"template"`
|
Template string `mapstructure:"template"`
|
||||||
VMName string `mapstructure:"vm_name"`
|
|
||||||
FolderName string `mapstructure:"folder"`
|
FolderName string `mapstructure:"folder"`
|
||||||
Datacenter string `mapstructure:"datacenter"`
|
VMName string `mapstructure:"vm_name"`
|
||||||
Host string `mapstructure:"host"`
|
Host string `mapstructure:"host"`
|
||||||
ResourcePool string `mapstructure:"resource_pool"`
|
ResourcePool string `mapstructure:"resource_pool"`
|
||||||
Datastore string `mapstructure:"datastore"`
|
Datastore string `mapstructure:"datastore"`
|
||||||
|
LinkedClone bool `mapstructure:"linked_clone"`
|
||||||
// Settings
|
|
||||||
LinkedClone bool `mapstructure:"linked_clone"`
|
|
||||||
ConvertToTemplate bool `mapstructure:"convert_to_template"`
|
|
||||||
RawShutdownTimeout string `mapstructure:"shutdown_timeout"`
|
|
||||||
ShutdownTimeout time.Duration
|
|
||||||
|
|
||||||
// Customization
|
// Customization
|
||||||
CPUs string `mapstructure:"CPUs"`
|
CPUs string `mapstructure:"CPUs"`
|
||||||
ShutdownCommand string `mapstructure:"shutdown_command"`
|
RAM string `mapstructure:"RAM"`
|
||||||
Ram string `mapstructure:"RAM"`
|
|
||||||
CreateSnapshot bool `mapstructure:"create_snapshot"`
|
|
||||||
|
|
||||||
|
// Provisioning
|
||||||
|
communicator.Config `mapstructure:",squash"`
|
||||||
|
|
||||||
ctx interpolate.Context
|
// Post-processing
|
||||||
|
ShutdownCommand string `mapstructure:"shutdown_command"`
|
||||||
|
RawShutdownTimeout string `mapstructure:"shutdown_timeout"`
|
||||||
|
ShutdownTimeout time.Duration
|
||||||
|
CreateSnapshot bool `mapstructure:"create_snapshot"`
|
||||||
|
ConvertToTemplate bool `mapstructure:"convert_to_template"`
|
||||||
|
|
||||||
|
ctx interpolate.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
c := new(Config)
|
c := new(Config)
|
||||||
err := config.Decode(c, &config.DecodeOpts{
|
{
|
||||||
Interpolate: true,
|
err := config.Decode(c, &config.DecodeOpts{
|
||||||
InterpolateContext: &c.ctx,
|
Interpolate: true,
|
||||||
}, raws...)
|
InterpolateContext: &c.ctx,
|
||||||
if err != nil {
|
}, raws...)
|
||||||
return nil, nil, err
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accumulate any errors
|
// Accumulate any errors
|
||||||
|
@ -84,26 +88,24 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
|
|
||||||
// Verify numeric parameters if present
|
// Verify numeric parameters if present
|
||||||
if c.CPUs != "" {
|
if c.CPUs != "" {
|
||||||
if _, err = strconv.Atoi(c.CPUs); err != nil {
|
if _, err := strconv.Atoi(c.CPUs); err != nil {
|
||||||
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Invalid number of CPU sockets"))
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Invalid number of CPU sockets"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.Ram != "" {
|
if c.RAM != "" {
|
||||||
if _, err = strconv.Atoi(c.Ram); err != nil {
|
if _, err := strconv.Atoi(c.RAM); err != nil {
|
||||||
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Invalid number for Ram"))
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Invalid number for RAM"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.RawShutdownTimeout == "" {
|
if c.RawShutdownTimeout != "" {
|
||||||
c.RawShutdownTimeout = "5m"
|
timeout, err := time.ParseDuration(c.RawShutdownTimeout)
|
||||||
|
if err != nil {
|
||||||
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Failed parsing shutdown_timeout: %s", err))
|
||||||
|
}
|
||||||
|
c.ShutdownTimeout = timeout
|
||||||
|
} else {
|
||||||
|
c.ShutdownTimeout = 5 * time.Minute
|
||||||
}
|
}
|
||||||
c.ShutdownTimeout, err = time.ParseDuration(c.RawShutdownTimeout)
|
|
||||||
if err != nil {
|
|
||||||
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Failed parsing shutdown_timeout: %s", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
//if c.Datastore == "" {
|
|
||||||
// warnings = append(warnings, "Datastore is not specified, will try to find the default one")
|
|
||||||
//}
|
|
||||||
|
|
||||||
if len(errs.Errors) > 0 {
|
if len(errs.Errors) > 0 {
|
||||||
return nil, warnings, errs
|
return nil, warnings, errs
|
||||||
|
|
|
@ -35,8 +35,8 @@ func (s *StepConfigureHW) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
confSpec.NumCPUs = int32(CPUs)
|
confSpec.NumCPUs = int32(CPUs)
|
||||||
parametersFlag.NumCPUsPtr = &(confSpec.NumCPUs)
|
parametersFlag.NumCPUsPtr = &(confSpec.NumCPUs)
|
||||||
}
|
}
|
||||||
if s.config.Ram != "" {
|
if s.config.RAM != "" {
|
||||||
ram, err := strconv.Atoi(s.config.Ram)
|
ram, err := strconv.Atoi(s.config.RAM)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
|
Loading…
Reference in New Issue