2019-05-31 08:27:41 -04:00
|
|
|
//go:generate struct-markdown
|
|
|
|
|
2013-12-22 12:24:29 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2020-11-11 13:21:37 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
|
2013-12-22 12:24:29 -05:00
|
|
|
)
|
|
|
|
|
2020-08-20 09:43:38 -04:00
|
|
|
//In order to perform extra customization of the virtual machine, a template can
|
|
|
|
//define extra calls to `VBoxManage` to perform.
|
|
|
|
//[VBoxManage](https://www.virtualbox.org/manual/ch09.html) is the command-line
|
|
|
|
//interface to VirtualBox where you can completely control VirtualBox. It can be
|
|
|
|
//used to do things such as set RAM, CPUs, etc.
|
2013-12-22 12:24:29 -05:00
|
|
|
type VBoxManageConfig struct {
|
2019-06-19 11:07:23 -04:00
|
|
|
// Custom `VBoxManage` commands to execute in order to further customize
|
2020-08-20 09:43:38 -04:00
|
|
|
// the virtual machine being created. The example shown below sets the memory and number of CPUs
|
|
|
|
// within the virtual machine:
|
|
|
|
//
|
|
|
|
// In JSON:
|
|
|
|
// ```json
|
|
|
|
// "vboxmanage": [
|
|
|
|
// ["modifyvm", "{{.Name}}", "--memory", "1024"],
|
|
|
|
// ["modifyvm", "{{.Name}}", "--cpus", "2"]
|
|
|
|
// ]
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// In HCL2:
|
|
|
|
// ```hcl
|
|
|
|
// vboxmanage = [
|
|
|
|
// ["modifyvm", "{{.Name}}", "--memory", "1024"],
|
|
|
|
// ["modifyvm", "{{.Name}}", "--cpus", "2"],
|
|
|
|
// ]
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// The value of `vboxmanage` is an array of commands to execute. These commands are
|
|
|
|
// executed in the order defined. So in the above example, the memory will be set
|
|
|
|
// followed by the CPUs.
|
|
|
|
// Each command itself is an array of strings, where each string is an argument to
|
|
|
|
// `VBoxManage`. Each argument is treated as a [configuration
|
|
|
|
// template](/docs/templates/engine). The only available
|
|
|
|
// variable is `Name` which is replaced with the unique name of the VM, which is
|
|
|
|
// required for many VBoxManage calls.
|
2019-05-28 11:50:58 -04:00
|
|
|
VBoxManage [][]string `mapstructure:"vboxmanage" required:"false"`
|
2019-06-19 11:07:23 -04:00
|
|
|
// Identical to vboxmanage,
|
|
|
|
// except that it is run after the virtual machine is shutdown, and before the
|
|
|
|
// virtual machine is exported.
|
|
|
|
VBoxManagePost [][]string `mapstructure:"vboxmanage_post" required:"false"`
|
2013-12-22 12:24:29 -05:00
|
|
|
}
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
func (c *VBoxManageConfig) Prepare(ctx *interpolate.Context) []error {
|
2013-12-22 12:24:29 -05:00
|
|
|
if c.VBoxManage == nil {
|
|
|
|
c.VBoxManage = make([][]string, 0)
|
|
|
|
}
|
|
|
|
|
2019-06-19 11:07:23 -04:00
|
|
|
if c.VBoxManagePost == nil {
|
|
|
|
c.VBoxManagePost = make([][]string, 0)
|
|
|
|
}
|
|
|
|
|
2016-02-02 15:41:43 -05:00
|
|
|
return nil
|
2013-12-22 12:24:29 -05:00
|
|
|
}
|