2013-12-24 00:58:41 -05:00
|
|
|
package iso
|
2013-06-04 18:00:58 -04:00
|
|
|
|
|
|
|
import (
|
2013-06-06 17:46:48 -04:00
|
|
|
"errors"
|
2013-06-06 17:38:14 -04:00
|
|
|
"fmt"
|
2013-08-27 20:23:22 -04:00
|
|
|
"io/ioutil"
|
2013-06-05 20:52:37 -04:00
|
|
|
"log"
|
2013-06-06 18:12:54 -04:00
|
|
|
"os"
|
2017-11-08 13:57:34 -05:00
|
|
|
"strconv"
|
2013-06-06 12:10:14 -04:00
|
|
|
"time"
|
2015-05-27 17:16:28 -04:00
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
|
|
|
"github.com/hashicorp/packer/common"
|
2018-04-18 17:53:59 -04:00
|
|
|
"github.com/hashicorp/packer/common/bootcommand"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/helper/communicator"
|
|
|
|
"github.com/hashicorp/packer/helper/config"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2013-06-04 18:00:58 -04:00
|
|
|
)
|
|
|
|
|
2013-11-18 19:10:55 -05:00
|
|
|
const BuilderIdESX = "mitchellh.vmware-esx"
|
2013-06-04 18:00:58 -04:00
|
|
|
|
|
|
|
type Builder struct {
|
2015-05-27 17:16:28 -04:00
|
|
|
config Config
|
2013-06-04 18:00:58 -04:00
|
|
|
runner multistep.Runner
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
type Config struct {
|
2013-12-26 17:31:23 -05:00
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
2015-11-01 17:29:24 -05:00
|
|
|
common.HTTPConfig `mapstructure:",squash"`
|
2015-10-20 19:27:47 -04:00
|
|
|
common.ISOConfig `mapstructure:",squash"`
|
2016-07-26 15:42:04 -04:00
|
|
|
common.FloppyConfig `mapstructure:",squash"`
|
2018-04-18 17:10:28 -04:00
|
|
|
bootcommand.VNCConfig `mapstructure:",squash"`
|
2013-12-27 10:37:39 -05:00
|
|
|
vmwcommon.DriverConfig `mapstructure:",squash"`
|
2013-12-26 17:31:23 -05:00
|
|
|
vmwcommon.OutputConfig `mapstructure:",squash"`
|
|
|
|
vmwcommon.RunConfig `mapstructure:",squash"`
|
|
|
|
vmwcommon.ShutdownConfig `mapstructure:",squash"`
|
|
|
|
vmwcommon.SSHConfig `mapstructure:",squash"`
|
2014-05-09 20:24:19 -04:00
|
|
|
vmwcommon.ToolsConfig `mapstructure:",squash"`
|
2013-12-26 17:31:23 -05:00
|
|
|
vmwcommon.VMXConfig `mapstructure:",squash"`
|
2013-12-26 17:14:19 -05:00
|
|
|
|
2015-11-11 07:39:06 -05:00
|
|
|
// disk drives
|
2017-02-27 16:34:53 -05:00
|
|
|
AdditionalDiskSize []uint `mapstructure:"disk_additional_size"`
|
2017-12-25 15:08:08 -05:00
|
|
|
DiskAdapterType string `mapstructure:"disk_adapter_type"`
|
2017-02-27 16:34:53 -05:00
|
|
|
DiskName string `mapstructure:"vmdk_name"`
|
|
|
|
DiskSize uint `mapstructure:"disk_size"`
|
|
|
|
DiskTypeId string `mapstructure:"disk_type_id"`
|
|
|
|
Format string `mapstructure:"format"`
|
2015-11-11 07:39:06 -05:00
|
|
|
|
2018-01-16 14:17:37 -05:00
|
|
|
// cdrom drive
|
|
|
|
CdromAdapterType string `mapstructure:"cdrom_adapter_type"`
|
|
|
|
|
2015-11-11 07:39:06 -05:00
|
|
|
// platform information
|
2017-02-27 16:34:53 -05:00
|
|
|
GuestOSType string `mapstructure:"guest_os_type"`
|
|
|
|
Version string `mapstructure:"version"`
|
|
|
|
VMName string `mapstructure:"vm_name"`
|
2015-11-11 07:39:06 -05:00
|
|
|
|
2018-01-16 14:17:37 -05:00
|
|
|
// Network adapter and type
|
|
|
|
NetworkAdapterType string `mapstructure:"network_adapter_type"`
|
|
|
|
Network string `mapstructure:"network"`
|
2015-11-11 07:39:06 -05:00
|
|
|
|
|
|
|
// device presence
|
2017-02-27 16:34:53 -05:00
|
|
|
Sound bool `mapstructure:"sound"`
|
|
|
|
USB bool `mapstructure:"usb"`
|
2015-11-11 07:39:06 -05:00
|
|
|
|
|
|
|
// communication ports
|
2017-02-27 16:34:53 -05:00
|
|
|
Serial string `mapstructure:"serial"`
|
|
|
|
Parallel string `mapstructure:"parallel"`
|
2015-11-11 07:39:06 -05:00
|
|
|
|
|
|
|
// booting a guest
|
2016-03-16 18:17:35 -04:00
|
|
|
KeepRegistered bool `mapstructure:"keep_registered"`
|
2017-02-10 03:22:02 -05:00
|
|
|
OVFToolOptions []string `mapstructure:"ovftool_options"`
|
2015-06-15 15:40:34 -04:00
|
|
|
SkipCompaction bool `mapstructure:"skip_compaction"`
|
2017-01-10 06:44:11 -05:00
|
|
|
SkipExport bool `mapstructure:"skip_export"`
|
2015-06-15 15:40:34 -04:00
|
|
|
VMXDiskTemplatePath string `mapstructure:"vmx_disk_template_path"`
|
2017-02-10 03:22:02 -05:00
|
|
|
VMXTemplatePath string `mapstructure:"vmx_template_path"`
|
2013-06-06 12:10:14 -04:00
|
|
|
|
2015-11-11 07:39:06 -05:00
|
|
|
// remote vsphere
|
2014-09-10 01:10:06 -04:00
|
|
|
RemoteType string `mapstructure:"remote_type"`
|
|
|
|
RemoteDatastore string `mapstructure:"remote_datastore"`
|
|
|
|
RemoteCacheDatastore string `mapstructure:"remote_cache_datastore"`
|
|
|
|
RemoteCacheDirectory string `mapstructure:"remote_cache_directory"`
|
|
|
|
RemoteHost string `mapstructure:"remote_host"`
|
|
|
|
RemotePort uint `mapstructure:"remote_port"`
|
|
|
|
RemoteUser string `mapstructure:"remote_username"`
|
|
|
|
RemotePassword string `mapstructure:"remote_password"`
|
2015-11-03 22:08:35 -05:00
|
|
|
RemotePrivateKey string `mapstructure:"remote_private_key_file"`
|
2013-09-19 20:07:04 -04:00
|
|
|
|
2016-08-19 07:02:55 -04:00
|
|
|
CommConfig communicator.Config `mapstructure:",squash"`
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
ctx interpolate.Context
|
2013-06-04 18:00:58 -04:00
|
|
|
}
|
|
|
|
|
2013-11-03 00:03:59 -04:00
|
|
|
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
2015-05-27 17:16:28 -04:00
|
|
|
err := config.Decode(&b.config, &config.DecodeOpts{
|
2015-06-22 12:22:42 -04:00
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &b.config.ctx,
|
2015-05-27 17:16:28 -04:00
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
|
|
|
Exclude: []string{
|
|
|
|
"boot_command",
|
|
|
|
"tools_upload_path",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, raws...)
|
2013-08-08 19:18:01 -04:00
|
|
|
if err != nil {
|
2013-11-03 00:03:59 -04:00
|
|
|
return nil, err
|
2013-08-08 19:18:01 -04:00
|
|
|
}
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
// Accumulate any errors and warnings
|
|
|
|
var errs *packer.MultiError
|
2015-10-20 19:27:47 -04:00
|
|
|
warnings := make([]string, 0)
|
|
|
|
|
|
|
|
isoWarnings, isoErrs := b.config.ISOConfig.Prepare(&b.config.ctx)
|
|
|
|
warnings = append(warnings, isoWarnings...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, isoErrs...)
|
2015-11-01 17:29:24 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.HTTPConfig.Prepare(&b.config.ctx)...)
|
2015-05-27 17:16:28 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.DriverConfig.Prepare(&b.config.ctx)...)
|
2013-12-25 18:01:57 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs,
|
2015-05-27 17:16:28 -04:00
|
|
|
b.config.OutputConfig.Prepare(&b.config.ctx, &b.config.PackerConfig)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.ShutdownConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.SSHConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.ToolsConfig.Prepare(&b.config.ctx)...)
|
2016-02-02 15:41:42 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.VMXConfig.Prepare(&b.config.ctx)...)
|
2016-07-26 15:42:04 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(&b.config.ctx)...)
|
2018-04-18 17:10:28 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.VNCConfig.Prepare(&b.config.ctx)...)
|
2013-07-13 20:28:56 -04:00
|
|
|
|
2013-06-04 19:52:59 -04:00
|
|
|
if b.config.DiskName == "" {
|
|
|
|
b.config.DiskName = "disk"
|
|
|
|
}
|
|
|
|
|
2013-06-23 18:07:19 -04:00
|
|
|
if b.config.DiskSize == 0 {
|
|
|
|
b.config.DiskSize = 40000
|
|
|
|
}
|
|
|
|
|
2017-12-25 15:08:08 -05:00
|
|
|
if b.config.DiskAdapterType == "" {
|
|
|
|
// Default is lsilogic
|
|
|
|
b.config.DiskAdapterType = "lsilogic"
|
|
|
|
}
|
|
|
|
|
2018-06-27 11:35:26 -04:00
|
|
|
if !b.config.SkipCompaction {
|
|
|
|
if b.config.RemoteType == "esx5" {
|
|
|
|
if b.config.DiskTypeId == "" {
|
|
|
|
b.config.SkipCompaction = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-22 14:40:56 -04:00
|
|
|
if b.config.DiskTypeId == "" {
|
|
|
|
// Default is growable virtual disk split in 2GB files.
|
|
|
|
b.config.DiskTypeId = "1"
|
2013-11-07 23:57:05 -05:00
|
|
|
|
|
|
|
if b.config.RemoteType == "esx5" {
|
|
|
|
b.config.DiskTypeId = "zeroedthick"
|
|
|
|
}
|
2013-08-22 14:40:56 -04:00
|
|
|
}
|
|
|
|
|
2018-06-27 11:35:26 -04:00
|
|
|
if b.config.RemoteType == "esx5" {
|
|
|
|
if b.config.DiskTypeId != "thin" && !b.config.SkipCompaction {
|
|
|
|
errs = packer.MultiErrorAppend(
|
|
|
|
errs, fmt.Errorf("skip_compaction must be 'true' for disk_type_id: %s", b.config.DiskTypeId))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-08 00:54:08 -04:00
|
|
|
if b.config.GuestOSType == "" {
|
|
|
|
b.config.GuestOSType = "other"
|
|
|
|
}
|
|
|
|
|
2013-06-04 19:52:59 -04:00
|
|
|
if b.config.VMName == "" {
|
2013-07-01 14:11:31 -04:00
|
|
|
b.config.VMName = fmt.Sprintf("packer-%s", b.config.PackerBuildName)
|
2013-06-04 19:52:59 -04:00
|
|
|
}
|
|
|
|
|
2014-09-25 00:20:35 -04:00
|
|
|
if b.config.Version == "" {
|
|
|
|
b.config.Version = "9"
|
|
|
|
}
|
|
|
|
|
2013-11-07 15:00:27 -05:00
|
|
|
if b.config.RemoteUser == "" {
|
|
|
|
b.config.RemoteUser = "root"
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.config.RemoteDatastore == "" {
|
|
|
|
b.config.RemoteDatastore = "datastore1"
|
|
|
|
}
|
|
|
|
|
2014-09-10 01:10:06 -04:00
|
|
|
if b.config.RemoteCacheDatastore == "" {
|
|
|
|
b.config.RemoteCacheDatastore = b.config.RemoteDatastore
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.config.RemoteCacheDirectory == "" {
|
|
|
|
b.config.RemoteCacheDirectory = "packer_cache"
|
|
|
|
}
|
|
|
|
|
2013-11-07 15:00:27 -05:00
|
|
|
if b.config.RemotePort == 0 {
|
|
|
|
b.config.RemotePort = 22
|
|
|
|
}
|
2017-10-09 20:12:33 -04:00
|
|
|
|
2013-08-27 20:23:22 -04:00
|
|
|
if b.config.VMXTemplatePath != "" {
|
|
|
|
if err := b.validateVMXTemplatePath(); err != nil {
|
|
|
|
errs = packer.MultiErrorAppend(
|
|
|
|
errs, fmt.Errorf("vmx_template_path is invalid: %s", err))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:39:06 -05:00
|
|
|
if b.config.Network == "" {
|
|
|
|
b.config.Network = "nat"
|
|
|
|
}
|
|
|
|
|
|
|
|
if !b.config.Sound {
|
|
|
|
b.config.Sound = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if !b.config.USB {
|
|
|
|
b.config.USB = false
|
|
|
|
}
|
|
|
|
|
2013-11-07 15:00:27 -05:00
|
|
|
// Remote configuration validation
|
|
|
|
if b.config.RemoteType != "" {
|
|
|
|
if b.config.RemoteHost == "" {
|
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("remote_host must be specified"))
|
|
|
|
}
|
2017-02-15 16:04:28 -05:00
|
|
|
if b.config.RemoteType != "esx5" {
|
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("Only 'esx5' value is accepted for remote_type"))
|
|
|
|
}
|
2013-11-07 15:00:27 -05:00
|
|
|
}
|
|
|
|
|
2017-02-10 03:49:47 -05:00
|
|
|
if b.config.Format == "" {
|
|
|
|
b.config.Format = "ovf"
|
|
|
|
}
|
|
|
|
|
|
|
|
if !(b.config.Format == "ova" || b.config.Format == "ovf" || b.config.Format == "vmx") {
|
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("format must be one of ova, ovf, or vmx"))
|
2015-10-23 19:50:14 -04:00
|
|
|
}
|
|
|
|
|
2018-06-08 05:49:17 -04:00
|
|
|
if b.config.RemoteType == "esx5" && b.config.SkipExport != true && b.config.RemotePassword == "" {
|
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("exporting the vm (with ovftool) requires that you set a value for remote_password"))
|
|
|
|
}
|
|
|
|
|
2013-11-03 00:17:21 -04:00
|
|
|
// Warnings
|
|
|
|
if b.config.ShutdownCommand == "" {
|
|
|
|
warnings = append(warnings,
|
|
|
|
"A shutdown_command was not specified. Without a shutdown command, Packer\n"+
|
|
|
|
"will forcibly halt the virtual machine, which may result in data loss.")
|
|
|
|
}
|
|
|
|
|
2017-10-09 20:12:33 -04:00
|
|
|
if b.config.Headless && b.config.DisableVNC {
|
|
|
|
warnings = append(warnings,
|
|
|
|
"Headless mode uses VNC to retrieve output. Since VNC has been disabled,\n"+
|
|
|
|
"you won't be able to see any output.")
|
|
|
|
}
|
|
|
|
|
2013-07-19 19:08:25 -04:00
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
2013-11-03 00:17:21 -04:00
|
|
|
return warnings, errs
|
2013-06-06 15:19:38 -04:00
|
|
|
}
|
|
|
|
|
2013-11-03 00:17:21 -04:00
|
|
|
return warnings, nil
|
2013-06-04 18:00:58 -04:00
|
|
|
}
|
|
|
|
|
2013-06-12 19:06:56 -04:00
|
|
|
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
2013-11-07 15:00:27 -05:00
|
|
|
driver, err := NewDriver(&b.config)
|
2013-08-13 11:54:12 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Failed creating VMware driver: %s", err)
|
|
|
|
}
|
|
|
|
|
2013-12-24 13:21:02 -05:00
|
|
|
// Determine the output dir implementation
|
|
|
|
var dir OutputDir
|
|
|
|
switch d := driver.(type) {
|
|
|
|
case OutputDir:
|
|
|
|
dir = d
|
|
|
|
default:
|
|
|
|
dir = new(vmwcommon.LocalOutputDir)
|
|
|
|
}
|
2017-02-24 07:46:00 -05:00
|
|
|
|
2017-03-10 03:20:48 -05:00
|
|
|
exportOutputPath := b.config.OutputDir
|
|
|
|
|
2017-02-10 03:49:47 -05:00
|
|
|
if b.config.RemoteType != "" {
|
2015-02-13 05:13:58 -05:00
|
|
|
b.config.OutputDir = b.config.VMName
|
|
|
|
}
|
2013-12-24 13:21:02 -05:00
|
|
|
dir.SetOutputDir(b.config.OutputDir)
|
|
|
|
|
|
|
|
// Setup the state bag
|
|
|
|
state := new(multistep.BasicStateBag)
|
|
|
|
state.Put("cache", cache)
|
|
|
|
state.Put("config", &b.config)
|
2016-05-17 03:50:00 -04:00
|
|
|
state.Put("debug", b.config.PackerDebug)
|
2013-12-24 13:21:02 -05:00
|
|
|
state.Put("dir", dir)
|
|
|
|
state.Put("driver", driver)
|
|
|
|
state.Put("hook", hook)
|
|
|
|
state.Put("ui", ui)
|
|
|
|
|
2013-06-04 18:00:58 -04:00
|
|
|
steps := []multistep.Step{
|
2014-05-09 20:24:19 -04:00
|
|
|
&vmwcommon.StepPrepareTools{
|
2014-05-10 00:12:14 -04:00
|
|
|
RemoteType: b.config.RemoteType,
|
2014-05-09 20:24:19 -04:00
|
|
|
ToolsUploadFlavor: b.config.ToolsUploadFlavor,
|
|
|
|
},
|
2013-08-15 14:17:10 -04:00
|
|
|
&common.StepDownload{
|
|
|
|
Checksum: b.config.ISOChecksum,
|
|
|
|
ChecksumType: b.config.ISOChecksumType,
|
|
|
|
Description: "ISO",
|
2016-12-17 05:49:54 -05:00
|
|
|
Extension: b.config.TargetExtension,
|
2015-10-20 19:27:47 -04:00
|
|
|
ResultKey: "iso_path",
|
2015-07-28 07:45:02 -04:00
|
|
|
TargetPath: b.config.TargetPath,
|
2015-10-20 19:27:47 -04:00
|
|
|
Url: b.config.ISOUrls,
|
2013-08-15 14:17:10 -04:00
|
|
|
},
|
2013-12-24 13:21:02 -05:00
|
|
|
&vmwcommon.StepOutputDir{
|
|
|
|
Force: b.config.PackerForce,
|
|
|
|
},
|
2013-07-08 23:56:23 -04:00
|
|
|
&common.StepCreateFloppy{
|
2016-10-11 17:43:50 -04:00
|
|
|
Files: b.config.FloppyConfig.FloppyFiles,
|
2016-09-28 00:31:42 -04:00
|
|
|
Directories: b.config.FloppyConfig.FloppyDirectories,
|
2013-07-08 23:56:23 -04:00
|
|
|
},
|
2014-05-03 05:23:20 -04:00
|
|
|
&stepRemoteUpload{
|
2017-03-17 20:02:43 -04:00
|
|
|
Key: "floppy_path",
|
|
|
|
Message: "Uploading Floppy to remote machine...",
|
|
|
|
DoCleanup: true,
|
2014-05-03 05:23:20 -04:00
|
|
|
},
|
2013-11-07 15:28:41 -05:00
|
|
|
&stepRemoteUpload{
|
|
|
|
Key: "iso_path",
|
|
|
|
Message: "Uploading ISO to remote machine...",
|
|
|
|
},
|
2013-06-04 18:00:58 -04:00
|
|
|
&stepCreateDisk{},
|
2013-06-04 19:52:59 -04:00
|
|
|
&stepCreateVMX{},
|
2013-12-24 01:07:43 -05:00
|
|
|
&vmwcommon.StepConfigureVMX{
|
2013-12-23 17:38:54 -05:00
|
|
|
CustomData: b.config.VMXData,
|
|
|
|
},
|
2013-12-24 16:26:44 -05:00
|
|
|
&vmwcommon.StepSuppressMessages{},
|
2015-11-01 17:29:24 -05:00
|
|
|
&common.StepHTTPServer{
|
2014-09-05 14:59:46 -04:00
|
|
|
HTTPDir: b.config.HTTPDir,
|
|
|
|
HTTPPortMin: b.config.HTTPPortMin,
|
|
|
|
HTTPPortMax: b.config.HTTPPortMax,
|
|
|
|
},
|
2014-09-05 15:10:40 -04:00
|
|
|
&vmwcommon.StepConfigureVNC{
|
2017-10-09 20:12:33 -04:00
|
|
|
Enabled: !b.config.DisableVNC,
|
2016-08-19 06:49:23 -04:00
|
|
|
VNCBindAddress: b.config.VNCBindAddress,
|
|
|
|
VNCPortMin: b.config.VNCPortMin,
|
|
|
|
VNCPortMax: b.config.VNCPortMax,
|
|
|
|
VNCDisablePassword: b.config.VNCDisablePassword,
|
2014-09-05 15:10:40 -04:00
|
|
|
},
|
2015-02-13 05:13:58 -05:00
|
|
|
&StepRegister{
|
|
|
|
Format: b.config.Format,
|
|
|
|
},
|
2013-12-24 20:12:43 -05:00
|
|
|
&vmwcommon.StepRun{
|
|
|
|
DurationBeforeStop: 5 * time.Second,
|
|
|
|
Headless: b.config.Headless,
|
|
|
|
},
|
2014-05-12 22:02:30 -04:00
|
|
|
&vmwcommon.StepTypeBootCommand{
|
2018-04-11 02:05:46 -04:00
|
|
|
BootWait: b.config.BootWait,
|
2017-10-09 20:12:33 -04:00
|
|
|
VNCEnabled: !b.config.DisableVNC,
|
2018-04-18 17:10:28 -04:00
|
|
|
BootCommand: b.config.FlatBootCommand(),
|
2014-05-12 22:02:30 -04:00
|
|
|
VMName: b.config.VMName,
|
2015-05-27 17:16:28 -04:00
|
|
|
Ctx: b.config.ctx,
|
2018-08-22 14:25:43 -04:00
|
|
|
KeyInterval: b.config.VNCConfig.BootKeyInterval,
|
2014-05-12 22:02:30 -04:00
|
|
|
},
|
2015-06-13 18:52:44 -04:00
|
|
|
&communicator.StepConnect{
|
2015-06-13 19:23:33 -04:00
|
|
|
Config: &b.config.SSHConfig.Comm,
|
|
|
|
Host: driver.CommHost,
|
2018-08-22 11:02:23 -04:00
|
|
|
SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(),
|
2013-07-15 01:22:13 -04:00
|
|
|
},
|
2014-05-09 20:24:19 -04:00
|
|
|
&vmwcommon.StepUploadTools{
|
2014-05-10 00:12:14 -04:00
|
|
|
RemoteType: b.config.RemoteType,
|
2014-05-09 20:24:19 -04:00
|
|
|
ToolsUploadFlavor: b.config.ToolsUploadFlavor,
|
2014-05-10 00:12:14 -04:00
|
|
|
ToolsUploadPath: b.config.ToolsUploadPath,
|
2015-05-27 17:16:28 -04:00
|
|
|
Ctx: b.config.ctx,
|
2014-05-09 20:24:19 -04:00
|
|
|
},
|
2013-07-16 02:44:41 -04:00
|
|
|
&common.StepProvision{},
|
2018-09-14 14:03:23 -04:00
|
|
|
&common.StepCleanupTempKeys{
|
|
|
|
Comm: &b.config.SSHConfig.Comm,
|
|
|
|
},
|
2013-12-25 01:33:49 -05:00
|
|
|
&vmwcommon.StepShutdown{
|
|
|
|
Command: b.config.ShutdownCommand,
|
2013-12-26 17:31:23 -05:00
|
|
|
Timeout: b.config.ShutdownTimeout,
|
2013-12-25 01:33:49 -05:00
|
|
|
},
|
2013-12-24 20:17:58 -05:00
|
|
|
&vmwcommon.StepCleanFiles{},
|
2015-09-04 12:37:48 -04:00
|
|
|
&vmwcommon.StepCompactDisk{
|
|
|
|
Skip: b.config.SkipCompaction,
|
|
|
|
},
|
2014-05-09 12:25:15 -04:00
|
|
|
&vmwcommon.StepConfigureVMX{
|
|
|
|
CustomData: b.config.VMXDataPost,
|
2014-09-04 00:27:54 -04:00
|
|
|
SkipFloppy: true,
|
2014-05-09 12:25:15 -04:00
|
|
|
},
|
2017-05-24 19:44:35 -04:00
|
|
|
&vmwcommon.StepCleanVMX{
|
|
|
|
RemoveEthernetInterfaces: b.config.VMXConfig.VMXRemoveEthernet,
|
2017-10-12 19:38:18 -04:00
|
|
|
VNCEnabled: !b.config.DisableVNC,
|
2017-05-24 19:44:35 -04:00
|
|
|
},
|
2014-11-16 13:31:08 -05:00
|
|
|
&StepUploadVMX{
|
2015-05-27 17:16:28 -04:00
|
|
|
RemoteType: b.config.RemoteType,
|
2014-11-16 13:31:08 -05:00
|
|
|
},
|
2015-02-13 05:13:58 -05:00
|
|
|
&StepExport{
|
2017-01-10 06:44:11 -05:00
|
|
|
Format: b.config.Format,
|
|
|
|
SkipExport: b.config.SkipExport,
|
2017-03-10 05:43:45 -05:00
|
|
|
OutputDir: exportOutputPath,
|
2015-02-13 05:13:58 -05:00
|
|
|
},
|
2013-06-04 18:00:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run!
|
2016-09-13 20:04:18 -04:00
|
|
|
b.runner = common.NewRunnerWithPauseFn(steps, b.config.PackerConfig, ui, state)
|
2013-06-04 18:00:58 -04:00
|
|
|
b.runner.Run(state)
|
|
|
|
|
2013-06-20 00:20:48 -04:00
|
|
|
// If there was an error, return that
|
2013-08-31 15:50:25 -04:00
|
|
|
if rawErr, ok := state.GetOk("error"); ok {
|
2013-06-20 00:20:48 -04:00
|
|
|
return nil, rawErr.(error)
|
|
|
|
}
|
|
|
|
|
2013-06-06 18:12:54 -04:00
|
|
|
// If we were interrupted or cancelled, then just exit.
|
2013-08-31 15:50:25 -04:00
|
|
|
if _, ok := state.GetOk(multistep.StateCancelled); ok {
|
2013-06-20 00:20:48 -04:00
|
|
|
return nil, errors.New("Build was cancelled.")
|
2013-06-06 18:12:54 -04:00
|
|
|
}
|
|
|
|
|
2013-08-31 15:50:25 -04:00
|
|
|
if _, ok := state.GetOk(multistep.StateHalted); ok {
|
2013-06-20 00:20:48 -04:00
|
|
|
return nil, errors.New("Build was halted.")
|
2013-06-06 18:12:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compile the artifact list
|
2015-02-13 05:13:58 -05:00
|
|
|
var files []string
|
2017-11-08 13:57:34 -05:00
|
|
|
if b.config.RemoteType != "" && b.config.Format != "" && !b.config.SkipExport {
|
2015-02-13 05:13:58 -05:00
|
|
|
dir = new(vmwcommon.LocalOutputDir)
|
2017-03-10 03:20:48 -05:00
|
|
|
dir.SetOutputDir(exportOutputPath)
|
2015-02-13 05:13:58 -05:00
|
|
|
files, err = dir.ListFiles()
|
|
|
|
} else {
|
|
|
|
files, err = state.Get("dir").(OutputDir).ListFiles()
|
|
|
|
}
|
2013-11-12 15:49:57 -05:00
|
|
|
if err != nil {
|
2013-06-12 19:06:56 -04:00
|
|
|
return nil, err
|
2013-06-06 18:12:54 -04:00
|
|
|
}
|
|
|
|
|
2013-11-18 19:10:55 -05:00
|
|
|
// Set the proper builder ID
|
2013-12-25 13:27:53 -05:00
|
|
|
builderId := vmwcommon.BuilderId
|
2013-11-18 19:10:55 -05:00
|
|
|
if b.config.RemoteType != "" {
|
|
|
|
builderId = BuilderIdESX
|
|
|
|
}
|
|
|
|
|
2017-11-08 13:57:34 -05:00
|
|
|
config := make(map[string]string)
|
|
|
|
config[ArtifactConfKeepRegistered] = strconv.FormatBool(b.config.KeepRegistered)
|
|
|
|
config[ArtifactConfFormat] = b.config.Format
|
|
|
|
config[ArtifactConfSkipExport] = strconv.FormatBool(b.config.SkipExport)
|
|
|
|
|
2013-11-18 19:10:55 -05:00
|
|
|
return &Artifact{
|
|
|
|
builderId: builderId,
|
2017-07-27 20:59:11 -04:00
|
|
|
id: b.config.VMName,
|
2013-12-25 13:27:53 -05:00
|
|
|
dir: dir,
|
2013-11-18 19:10:55 -05:00
|
|
|
f: files,
|
2017-11-08 13:57:34 -05:00
|
|
|
config: config,
|
2013-11-18 19:10:55 -05:00
|
|
|
}, nil
|
2013-06-04 18:00:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Builder) Cancel() {
|
2013-06-05 20:52:37 -04:00
|
|
|
if b.runner != nil {
|
|
|
|
log.Println("Cancelling the step runner...")
|
|
|
|
b.runner.Cancel()
|
|
|
|
}
|
2013-06-04 18:00:58 -04:00
|
|
|
}
|
2013-08-27 20:23:22 -04:00
|
|
|
|
|
|
|
func (b *Builder) validateVMXTemplatePath() error {
|
|
|
|
f, err := os.Open(b.config.VMXTemplatePath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
data, err := ioutil.ReadAll(f)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
return interpolate.Validate(string(data), &b.config.ctx)
|
2013-08-27 20:23:22 -04:00
|
|
|
}
|