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