2019-05-31 08:27:41 -04:00
|
|
|
//go:generate struct-markdown
|
2019-10-14 10:43:59 -04:00
|
|
|
//go:generate mapstructure-to-hcl2 -type Config
|
2019-05-31 08:27:41 -04:00
|
|
|
|
2015-06-21 07:36:07 -04:00
|
|
|
package iso
|
|
|
|
|
|
|
|
import (
|
2019-03-22 09:53:28 -04:00
|
|
|
"context"
|
2015-06-21 07:36:07 -04:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2016-06-30 15:21:57 -04:00
|
|
|
"log"
|
2017-05-21 12:29:26 -04:00
|
|
|
"path/filepath"
|
2017-05-29 20:16:03 -04:00
|
|
|
"strings"
|
2016-06-30 15:21:57 -04:00
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2017-04-04 16:39:01 -04:00
|
|
|
hypervcommon "github.com/hashicorp/packer/builder/hyperv/common"
|
|
|
|
"github.com/hashicorp/packer/common"
|
2018-04-18 19:26:48 -04:00
|
|
|
"github.com/hashicorp/packer/common/bootcommand"
|
2019-06-13 11:23:21 -04:00
|
|
|
"github.com/hashicorp/packer/common/shutdowncommand"
|
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"
|
2015-06-21 07:36:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-10-30 15:57:27 -04:00
|
|
|
DefaultDiskSize = 40 * 1024 // ~40GB
|
|
|
|
MinDiskSize = 256 // 256MB
|
2015-10-18 12:11:38 -04:00
|
|
|
MaxDiskSize = 64 * 1024 * 1024 // 64TB
|
2018-04-20 15:13:12 -04:00
|
|
|
MaxVHDSize = 2040 * 1024 // 2040GB
|
2015-06-21 07:36:07 -04:00
|
|
|
|
2018-02-23 14:19:26 -05:00
|
|
|
DefaultDiskBlockSize = 32 // 32MB
|
|
|
|
MinDiskBlockSize = 1 // 1MB
|
|
|
|
MaxDiskBlockSize = 256 // 256MB
|
|
|
|
|
2016-08-07 07:26:27 -04:00
|
|
|
DefaultRamSize = 1 * 1024 // 1GB
|
|
|
|
MinRamSize = 32 // 32MB
|
|
|
|
MaxRamSize = 32 * 1024 // 32GB
|
|
|
|
MinNestedVirtualizationRamSize = 4 * 1024 // 4GB
|
2015-06-21 07:36:07 -04:00
|
|
|
|
2016-07-24 13:07:43 -04:00
|
|
|
LowRam = 256 // 256MB
|
2015-06-21 07:36:07 -04:00
|
|
|
|
2016-11-06 08:14:39 -05:00
|
|
|
DefaultUsername = ""
|
|
|
|
DefaultPassword = ""
|
2015-06-21 07:36:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Builder implements packer.Builder and builds the actual Hyperv
|
|
|
|
// images.
|
|
|
|
type Builder struct {
|
2015-06-21 09:06:27 -04:00
|
|
|
config Config
|
2015-06-21 07:36:07 -04:00
|
|
|
runner multistep.Runner
|
|
|
|
}
|
|
|
|
|
2015-06-21 09:06:27 -04:00
|
|
|
type Config struct {
|
2019-06-13 11:23:21 -04:00
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
|
|
|
common.HTTPConfig `mapstructure:",squash"`
|
|
|
|
common.ISOConfig `mapstructure:",squash"`
|
|
|
|
bootcommand.BootConfig `mapstructure:",squash"`
|
|
|
|
hypervcommon.OutputConfig `mapstructure:",squash"`
|
|
|
|
hypervcommon.SSHConfig `mapstructure:",squash"`
|
2019-10-18 16:01:22 -04:00
|
|
|
hypervcommon.CommonConfig `mapstructure:",squash"`
|
2019-06-13 11:23:21 -04:00
|
|
|
shutdowncommand.ShutdownConfig `mapstructure:",squash"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The size, in megabytes, of the hard disk to create
|
2019-06-06 10:29:25 -04:00
|
|
|
// for the VM. By default, this is 40 GB.
|
2019-05-28 11:50:58 -04:00
|
|
|
DiskSize uint `mapstructure:"disk_size" required:"false"`
|
|
|
|
// If true use a legacy network adapter as the NIC.
|
2019-06-06 10:29:25 -04:00
|
|
|
// This defaults to false. A legacy network adapter is fully emulated NIC, and is thus
|
|
|
|
// supported by various exotic operating systems, but this emulation requires
|
|
|
|
// additional overhead and should only be used if absolutely necessary.
|
|
|
|
UseLegacyNetworkAdapter bool `mapstructure:"use_legacy_network_adapter" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// If true enables differencing disks. Only
|
2019-06-06 10:29:25 -04:00
|
|
|
// the changes will be written to the new disk. This is especially useful if
|
|
|
|
// your source is a VHD/VHDX. This defaults to false.
|
2019-05-28 11:50:58 -04:00
|
|
|
DifferencingDisk bool `mapstructure:"differencing_disk" required:"false"`
|
|
|
|
// If true, creates the boot disk on the
|
2019-06-06 10:29:25 -04:00
|
|
|
// virtual machine as a fixed VHD format disk. The default is false, which
|
|
|
|
// creates a dynamic VHDX format disk. This option requires setting
|
|
|
|
// generation to 1, skip_compaction to true, and
|
|
|
|
// differencing_disk to false. Additionally, any value entered for
|
|
|
|
// disk_block_size will be ignored. The most likely use case for this
|
|
|
|
// option is outputing a disk that is in the format required for upload to
|
|
|
|
// Azure.
|
2019-05-28 11:50:58 -04:00
|
|
|
FixedVHD bool `mapstructure:"use_fixed_vhd_format" required:"false"`
|
2018-05-05 17:54:58 -04:00
|
|
|
|
2015-06-21 09:06:27 -04:00
|
|
|
ctx interpolate.Context
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() }
|
|
|
|
|
2019-12-17 00:23:05 -05:00
|
|
|
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
|
2015-06-21 09:06:27 -04:00
|
|
|
err := config.Decode(&b.config, &config.DecodeOpts{
|
2017-08-08 09:21:53 -04:00
|
|
|
Interpolate: true,
|
2017-07-27 10:53:15 -04:00
|
|
|
InterpolateContext: &b.config.ctx,
|
2015-06-21 09:06:27 -04:00
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
2015-06-27 17:36:39 -04:00
|
|
|
Exclude: []string{
|
|
|
|
"boot_command",
|
|
|
|
},
|
2015-06-21 09:06:27 -04:00
|
|
|
},
|
|
|
|
}, raws...)
|
2015-06-21 07:36:07 -04:00
|
|
|
if err != nil {
|
2019-12-17 00:23:05 -05:00
|
|
|
return nil, nil, err
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accumulate any errors and warnings
|
2015-06-21 09:06:27 -04:00
|
|
|
var errs *packer.MultiError
|
2016-06-29 17:53:29 -04:00
|
|
|
warnings := make([]string, 0)
|
|
|
|
|
|
|
|
isoWarnings, isoErrs := b.config.ISOConfig.Prepare(&b.config.ctx)
|
|
|
|
warnings = append(warnings, isoWarnings...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, isoErrs...)
|
2017-05-29 20:16:03 -04:00
|
|
|
|
2018-04-18 19:26:48 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.BootConfig.Prepare(&b.config.ctx)...)
|
2016-01-25 17:43:40 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.HTTPConfig.Prepare(&b.config.ctx)...)
|
2015-06-21 09:06:27 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.OutputConfig.Prepare(&b.config.ctx, &b.config.PackerConfig)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.SSHConfig.Prepare(&b.config.ctx)...)
|
2017-05-28 21:36:01 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.ShutdownConfig.Prepare(&b.config.ctx)...)
|
2015-06-21 07:36:07 -04:00
|
|
|
|
2019-10-18 16:01:22 -04:00
|
|
|
commonErrs, commonWarns := b.config.CommonConfig.Prepare(&b.config.ctx, &b.config.PackerConfig)
|
|
|
|
packer.MultiErrorAppend(errs, commonErrs...)
|
|
|
|
warnings = append(warnings, commonWarns...)
|
|
|
|
|
2018-07-09 12:20:38 -04:00
|
|
|
if len(b.config.ISOConfig.ISOUrls) < 1 ||
|
|
|
|
(strings.ToLower(filepath.Ext(b.config.ISOConfig.ISOUrls[0])) != ".vhd" &&
|
|
|
|
strings.ToLower(filepath.Ext(b.config.ISOConfig.ISOUrls[0])) != ".vhdx") {
|
2017-05-21 12:29:26 -04:00
|
|
|
//We only create a new hard drive if an existing one to copy from does not exist
|
|
|
|
err = b.checkDiskSize()
|
|
|
|
if err != nil {
|
|
|
|
errs = packer.MultiErrorAppend(errs, err)
|
|
|
|
}
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
|
|
|
|
2015-06-21 14:35:32 -04:00
|
|
|
if b.config.Cpu < 1 {
|
|
|
|
b.config.Cpu = 1
|
|
|
|
}
|
|
|
|
|
2015-07-12 12:19:29 -04:00
|
|
|
if b.config.Generation == 2 {
|
2018-12-18 06:50:16 -05:00
|
|
|
if b.config.UseLegacyNetworkAdapter {
|
|
|
|
err = errors.New("Generation 2 vms don't support legacy network adapters.")
|
|
|
|
errs = packer.MultiErrorAppend(errs, err)
|
|
|
|
}
|
2015-07-12 12:19:29 -04:00
|
|
|
}
|
|
|
|
|
2015-06-21 07:36:07 -04:00
|
|
|
// Errors
|
2017-05-21 12:29:26 -04:00
|
|
|
|
2018-04-20 15:13:12 -04:00
|
|
|
if b.config.Generation > 1 && b.config.FixedVHD {
|
|
|
|
err = errors.New("Fixed VHD disks are only supported on Generation 1 virtual machines.")
|
|
|
|
errs = packer.MultiErrorAppend(errs, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !b.config.SkipCompaction && b.config.FixedVHD {
|
|
|
|
err = errors.New("Fixed VHD disks do not support compaction.")
|
|
|
|
errs = packer.MultiErrorAppend(errs, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.config.DifferencingDisk && b.config.FixedVHD {
|
|
|
|
err = errors.New("Fixed VHD disks are not supported with differencing disks.")
|
|
|
|
errs = packer.MultiErrorAppend(errs, err)
|
|
|
|
}
|
|
|
|
|
2015-06-21 07:36:07 -04:00
|
|
|
// Warnings
|
2015-06-21 09:06:27 -04:00
|
|
|
|
2015-06-21 07:36:07 -04:00
|
|
|
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.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
2019-12-17 00:23:05 -05:00
|
|
|
return nil, warnings, errs
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
|
|
|
|
2019-12-17 00:23:05 -05:00
|
|
|
return nil, warnings, nil
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run executes a Packer build and returns a packer.Artifact representing
|
|
|
|
// a Hyperv appliance.
|
2019-03-22 09:53:28 -04:00
|
|
|
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
|
2015-06-21 07:36:07 -04:00
|
|
|
// Create the driver that we'll use to communicate with Hyperv
|
|
|
|
driver, err := hypervcommon.NewHypervPS4Driver()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Failed creating Hyper-V driver: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the state.
|
|
|
|
state := new(multistep.BasicStateBag)
|
2016-06-29 17:53:29 -04:00
|
|
|
state.Put("debug", b.config.PackerDebug)
|
2015-06-21 07:36:07 -04:00
|
|
|
state.Put("driver", driver)
|
|
|
|
state.Put("hook", hook)
|
|
|
|
state.Put("ui", ui)
|
|
|
|
|
2015-10-30 15:57:27 -04:00
|
|
|
steps := []multistep.Step{
|
2018-07-08 17:24:06 -04:00
|
|
|
&hypervcommon.StepCreateBuildDir{
|
2018-07-08 06:16:02 -04:00
|
|
|
TempPath: b.config.TempPath,
|
2017-06-30 19:19:27 -04:00
|
|
|
},
|
2019-01-11 18:06:36 -05:00
|
|
|
&common.StepOutputDir{
|
2015-06-21 07:36:07 -04:00
|
|
|
Force: b.config.PackerForce,
|
|
|
|
Path: b.config.OutputDir,
|
|
|
|
},
|
2015-10-30 13:19:25 -04:00
|
|
|
&common.StepDownload{
|
2020-05-28 05:02:09 -04:00
|
|
|
Checksum: b.config.ISOChecksum,
|
|
|
|
Description: "ISO",
|
|
|
|
ResultKey: "iso_path",
|
|
|
|
Url: b.config.ISOUrls,
|
|
|
|
Extension: b.config.TargetExtension,
|
|
|
|
TargetPath: b.config.TargetPath,
|
2015-10-30 15:57:27 -04:00
|
|
|
},
|
2015-06-21 07:36:07 -04:00
|
|
|
&common.StepCreateFloppy{
|
2017-06-15 08:12:39 -04:00
|
|
|
Files: b.config.FloppyConfig.FloppyFiles,
|
|
|
|
Directories: b.config.FloppyConfig.FloppyDirectories,
|
2019-09-12 08:25:22 -04:00
|
|
|
Label: b.config.FloppyConfig.FloppyLabel,
|
2015-06-21 07:36:07 -04:00
|
|
|
},
|
2016-01-25 17:43:40 -05:00
|
|
|
&common.StepHTTPServer{
|
2015-06-27 17:36:39 -04:00
|
|
|
HTTPDir: b.config.HTTPDir,
|
|
|
|
HTTPPortMin: b.config.HTTPPortMin,
|
|
|
|
HTTPPortMax: b.config.HTTPPortMax,
|
2020-05-27 16:34:24 -04:00
|
|
|
HTTPAddress: b.config.HTTPAddress,
|
2015-06-27 17:36:39 -04:00
|
|
|
},
|
2015-06-21 07:36:07 -04:00
|
|
|
&hypervcommon.StepCreateSwitch{
|
|
|
|
SwitchName: b.config.SwitchName,
|
|
|
|
},
|
|
|
|
&hypervcommon.StepCreateVM{
|
2016-08-07 07:26:27 -04:00
|
|
|
VMName: b.config.VMName,
|
|
|
|
SwitchName: b.config.SwitchName,
|
2016-11-06 09:07:46 -05:00
|
|
|
RamSize: b.config.RamSize,
|
2016-08-07 07:26:27 -04:00
|
|
|
DiskSize: b.config.DiskSize,
|
2018-02-23 14:19:26 -05:00
|
|
|
DiskBlockSize: b.config.DiskBlockSize,
|
2016-08-07 07:26:27 -04:00
|
|
|
Generation: b.config.Generation,
|
|
|
|
Cpu: b.config.Cpu,
|
|
|
|
EnableMacSpoofing: b.config.EnableMacSpoofing,
|
|
|
|
EnableDynamicMemory: b.config.EnableDynamicMemory,
|
|
|
|
EnableSecureBoot: b.config.EnableSecureBoot,
|
2018-05-10 13:00:35 -04:00
|
|
|
SecureBootTemplate: b.config.SecureBootTemplate,
|
2016-08-06 02:09:33 -04:00
|
|
|
EnableVirtualizationExtensions: b.config.EnableVirtualizationExtensions,
|
2018-12-18 06:50:16 -05:00
|
|
|
UseLegacyNetworkAdapter: b.config.UseLegacyNetworkAdapter,
|
2017-10-19 18:29:17 -04:00
|
|
|
AdditionalDiskSize: b.config.AdditionalDiskSize,
|
2017-10-12 06:35:31 -04:00
|
|
|
DifferencingDisk: b.config.DifferencingDisk,
|
2018-04-24 20:38:57 -04:00
|
|
|
MacAddress: b.config.MacAddress,
|
2018-04-20 15:13:12 -04:00
|
|
|
FixedVHD: b.config.FixedVHD,
|
2018-12-19 19:30:57 -05:00
|
|
|
Version: b.config.Version,
|
2019-04-12 18:59:09 -04:00
|
|
|
KeepRegistered: b.config.KeepRegistered,
|
2015-06-21 07:36:07 -04:00
|
|
|
},
|
|
|
|
&hypervcommon.StepEnableIntegrationService{},
|
|
|
|
|
|
|
|
&hypervcommon.StepMountDvdDrive{
|
2020-02-21 02:07:58 -05:00
|
|
|
Generation: b.config.Generation,
|
|
|
|
FirstBootDevice: b.config.FirstBootDevice,
|
2015-10-30 13:19:25 -04:00
|
|
|
},
|
|
|
|
&hypervcommon.StepMountFloppydrive{
|
|
|
|
Generation: b.config.Generation,
|
|
|
|
},
|
|
|
|
|
|
|
|
&hypervcommon.StepMountGuestAdditions{
|
|
|
|
GuestAdditionsMode: b.config.GuestAdditionsMode,
|
|
|
|
GuestAdditionsPath: b.config.GuestAdditionsPath,
|
2015-10-30 15:57:27 -04:00
|
|
|
Generation: b.config.Generation,
|
2015-06-21 07:36:07 -04:00
|
|
|
},
|
2020-08-19 17:09:08 -04:00
|
|
|
&common.StepCreateCD{
|
|
|
|
Files: b.config.CDConfig.CDFiles,
|
|
|
|
Label: b.config.CDConfig.CDLabel,
|
|
|
|
},
|
2015-07-12 12:19:29 -04:00
|
|
|
&hypervcommon.StepMountSecondaryDvdImages{
|
2015-10-30 15:57:27 -04:00
|
|
|
IsoPaths: b.config.SecondaryDvdImages,
|
2015-07-12 13:57:42 -04:00
|
|
|
Generation: b.config.Generation,
|
2015-07-12 12:19:29 -04:00
|
|
|
},
|
2016-09-29 14:37:07 -04:00
|
|
|
|
2016-09-21 14:31:06 -04:00
|
|
|
&hypervcommon.StepConfigureVlan{
|
2016-09-29 14:37:07 -04:00
|
|
|
VlanId: b.config.VlanId,
|
|
|
|
SwitchVlanId: b.config.SwitchVlanId,
|
2016-09-21 14:31:06 -04:00
|
|
|
},
|
2015-06-21 07:36:07 -04:00
|
|
|
|
2020-04-30 07:31:41 -04:00
|
|
|
&hypervcommon.StepSetBootOrder{
|
|
|
|
BootOrder: b.config.BootOrder,
|
|
|
|
},
|
2020-02-21 02:01:09 -05:00
|
|
|
&hypervcommon.StepSetFirstBootDevice{
|
|
|
|
Generation: b.config.Generation,
|
|
|
|
FirstBootDevice: b.config.FirstBootDevice,
|
|
|
|
},
|
|
|
|
|
2018-05-05 17:54:58 -04:00
|
|
|
&hypervcommon.StepRun{
|
2019-08-10 15:03:08 -04:00
|
|
|
Headless: b.config.Headless,
|
|
|
|
SwitchName: b.config.SwitchName,
|
2018-05-05 17:54:58 -04:00
|
|
|
},
|
2015-06-27 17:36:39 -04:00
|
|
|
|
|
|
|
&hypervcommon.StepTypeBootCommand{
|
2018-08-22 14:25:43 -04:00
|
|
|
BootCommand: b.config.FlatBootCommand(),
|
|
|
|
BootWait: b.config.BootWait,
|
|
|
|
SwitchName: b.config.SwitchName,
|
|
|
|
Ctx: b.config.ctx,
|
|
|
|
GroupInterval: b.config.BootConfig.BootGroupInterval,
|
2015-06-21 07:36:07 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// configure the communicator ssh, winrm
|
|
|
|
&communicator.StepConnect{
|
|
|
|
Config: &b.config.SSHConfig.Comm,
|
2018-12-27 03:33:58 -05:00
|
|
|
Host: hypervcommon.CommHost(b.config.SSHConfig.Comm.SSHHost),
|
2018-08-22 11:02:23 -04:00
|
|
|
SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(),
|
2015-06-21 07:36:07 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// provision requires communicator to be setup
|
|
|
|
&common.StepProvision{},
|
|
|
|
|
2018-09-14 14:03:23 -04:00
|
|
|
// Remove ephemeral key from authorized_hosts if using SSH communicator
|
|
|
|
&common.StepCleanupTempKeys{
|
|
|
|
Comm: &b.config.SSHConfig.Comm,
|
|
|
|
},
|
|
|
|
|
2015-06-21 07:36:07 -04:00
|
|
|
&hypervcommon.StepShutdown{
|
|
|
|
Command: b.config.ShutdownCommand,
|
|
|
|
Timeout: b.config.ShutdownTimeout,
|
|
|
|
},
|
|
|
|
|
2015-06-21 14:35:32 -04:00
|
|
|
// wait for the vm to be powered off
|
|
|
|
&hypervcommon.StepWaitForPowerOff{},
|
2015-10-30 15:57:27 -04:00
|
|
|
|
2015-10-30 13:19:25 -04:00
|
|
|
// remove the secondary dvd images
|
2015-06-24 14:52:42 -04:00
|
|
|
// after we power down
|
|
|
|
&hypervcommon.StepUnmountSecondaryDvdImages{},
|
2015-10-30 13:19:25 -04:00
|
|
|
&hypervcommon.StepUnmountGuestAdditions{},
|
|
|
|
&hypervcommon.StepUnmountDvdDrive{},
|
2015-07-14 02:51:03 -04:00
|
|
|
&hypervcommon.StepUnmountFloppyDrive{
|
|
|
|
Generation: b.config.Generation,
|
|
|
|
},
|
2018-07-07 07:42:22 -04:00
|
|
|
&hypervcommon.StepCompactDisk{
|
2015-06-27 17:36:39 -04:00
|
|
|
SkipCompaction: b.config.SkipCompaction,
|
2018-07-07 07:42:22 -04:00
|
|
|
},
|
2015-06-21 07:36:07 -04:00
|
|
|
&hypervcommon.StepExportVm{
|
2018-07-07 07:27:09 -04:00
|
|
|
OutputDir: b.config.OutputDir,
|
|
|
|
SkipExport: b.config.SkipExport,
|
2015-06-21 07:36:07 -04:00
|
|
|
},
|
2018-07-08 09:12:32 -04:00
|
|
|
&hypervcommon.StepCollateArtifacts{
|
|
|
|
OutputDir: b.config.OutputDir,
|
|
|
|
SkipExport: b.config.SkipExport,
|
2015-06-21 07:36:07 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// the clean up actions for each step will be executed reverse order
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run the steps.
|
2017-08-31 13:43:00 -04:00
|
|
|
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
|
2019-03-22 09:53:28 -04:00
|
|
|
b.runner.Run(ctx, state)
|
2015-06-21 07:36:07 -04:00
|
|
|
|
|
|
|
// Report any errors.
|
|
|
|
if rawErr, ok := state.GetOk("error"); ok {
|
|
|
|
return nil, rawErr.(error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we were interrupted or cancelled, then just exit.
|
|
|
|
if _, ok := state.GetOk(multistep.StateCancelled); ok {
|
|
|
|
return nil, errors.New("Build was cancelled.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := state.GetOk(multistep.StateHalted); ok {
|
|
|
|
return nil, errors.New("Build was halted.")
|
|
|
|
}
|
2020-01-30 05:27:58 -05:00
|
|
|
generatedData := map[string]interface{}{"generated_data": state.Get("generated_data")}
|
|
|
|
return hypervcommon.NewArtifact(b.config.OutputDir, generatedData)
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel.
|
|
|
|
|
|
|
|
func (b *Builder) checkDiskSize() error {
|
|
|
|
if b.config.DiskSize == 0 {
|
|
|
|
b.config.DiskSize = DefaultDiskSize
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println(fmt.Sprintf("%s: %v", "DiskSize", b.config.DiskSize))
|
|
|
|
|
|
|
|
if b.config.DiskSize < MinDiskSize {
|
2018-07-09 12:20:38 -04:00
|
|
|
return fmt.Errorf("disk_size: Virtual machine requires disk space >= %v GB, but defined: %v",
|
|
|
|
MinDiskSize, b.config.DiskSize/1024)
|
2018-04-20 15:13:12 -04:00
|
|
|
} else if b.config.DiskSize > MaxDiskSize && !b.config.FixedVHD {
|
2018-07-09 12:20:38 -04:00
|
|
|
return fmt.Errorf("disk_size: Virtual machine requires disk space <= %v GB, but defined: %v",
|
|
|
|
MaxDiskSize, b.config.DiskSize/1024)
|
2018-04-20 15:13:12 -04:00
|
|
|
} else if b.config.DiskSize > MaxVHDSize && b.config.FixedVHD {
|
2018-07-09 12:20:38 -04:00
|
|
|
return fmt.Errorf("disk_size: Virtual machine requires disk space <= %v GB, but defined: %v",
|
|
|
|
MaxVHDSize/1024, b.config.DiskSize/1024)
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|