diff --git a/builder/parallels/common/prlctl_post_config.go b/builder/parallels/common/prlctl_post_config.go new file mode 100644 index 000000000..23c2d5520 --- /dev/null +++ b/builder/parallels/common/prlctl_post_config.go @@ -0,0 +1,28 @@ +package common + +import ( + "fmt" + "github.com/mitchellh/packer/packer" +) + +type PrlctlPostConfig struct { + PrlctlPost [][]string `mapstructure:"prlctl_post"` +} + +func (c *PrlctlPostConfig) Prepare(t *packer.ConfigTemplate) []error { + if c.PrlctlPost == nil { + c.PrlctlPost = make([][]string, 0) + } + + errs := make([]error, 0) + for i, args := range c.PrlctlPost { + for j, arg := range args { + if err := t.Validate(arg); err != nil { + errs = append(errs, + fmt.Errorf("Error processing prlctl_post[%d][%d]: %s", i, j, err)) + } + } + } + + return errs +} diff --git a/builder/parallels/common/prlctl_post_config_test.go b/builder/parallels/common/prlctl_post_config_test.go new file mode 100644 index 000000000..c091a1a92 --- /dev/null +++ b/builder/parallels/common/prlctl_post_config_test.go @@ -0,0 +1,37 @@ +package common + +import ( + "reflect" + "testing" +) + +func TestPrlctlPostConfigPrepare_PrlctlPost(t *testing.T) { + // Test with empty + c := new(PrlctlPostConfig) + errs := c.Prepare(testConfigTemplate(t)) + if len(errs) > 0 { + t.Fatalf("err: %#v", errs) + } + + if !reflect.DeepEqual(c.PrlctlPost, [][]string{}) { + t.Fatalf("bad: %#v", c.PrlctlPost) + } + + // Test with a good one + c = new(PrlctlPostConfig) + c.PrlctlPost = [][]string{ + {"foo", "bar", "baz"}, + } + errs = c.Prepare(testConfigTemplate(t)) + if len(errs) > 0 { + t.Fatalf("err: %#v", errs) + } + + expected := [][]string{ + []string{"foo", "bar", "baz"}, + } + + if !reflect.DeepEqual(c.PrlctlPost, expected) { + t.Fatalf("bad: %#v", c.PrlctlPost) + } +} diff --git a/builder/parallels/iso/builder.go b/builder/parallels/iso/builder.go index fdab718bc..0c3bc0384 100644 --- a/builder/parallels/iso/builder.go +++ b/builder/parallels/iso/builder.go @@ -27,6 +27,7 @@ type Config struct { parallelscommon.FloppyConfig `mapstructure:",squash"` parallelscommon.OutputConfig `mapstructure:",squash"` parallelscommon.PrlctlConfig `mapstructure:",squash"` + parallelscommon.PrlctlPostConfig `mapstructure:",squash"` parallelscommon.PrlctlVersionConfig `mapstructure:",squash"` parallelscommon.RunConfig `mapstructure:",squash"` parallelscommon.ShutdownConfig `mapstructure:",squash"` @@ -78,6 +79,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { errs, 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.PrlctlConfig.Prepare(&b.config.ctx)...) + errs = packer.MultiErrorAppend(errs, b.config.PrlctlPostConfig.Prepare(&b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.PrlctlVersionConfig.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)...) @@ -266,6 +268,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Command: b.config.ShutdownCommand, Timeout: b.config.ShutdownTimeout, }, + ¶llelscommon.StepPrlctl{ + Commands: b.config.PrlctlPost, + Tpl: b.config.tpl, + }, } // Setup the state bag diff --git a/builder/parallels/pvm/builder.go b/builder/parallels/pvm/builder.go index 0e71ea0f2..87a92989a 100644 --- a/builder/parallels/pvm/builder.go +++ b/builder/parallels/pvm/builder.go @@ -101,6 +101,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Command: b.config.ShutdownCommand, Timeout: b.config.ShutdownTimeout, }, + ¶llelscommon.StepPrlctl{ + Commands: b.config.PrlctlPost, + Tpl: b.config.tpl, + }, } // Run the steps. diff --git a/builder/parallels/pvm/config.go b/builder/parallels/pvm/config.go index a4b5f10b5..767ed913c 100644 --- a/builder/parallels/pvm/config.go +++ b/builder/parallels/pvm/config.go @@ -17,6 +17,7 @@ type Config struct { parallelscommon.FloppyConfig `mapstructure:",squash"` parallelscommon.OutputConfig `mapstructure:",squash"` parallelscommon.PrlctlConfig `mapstructure:",squash"` + parallelscommon.PrlctlPostConfig `mapstructure:",squash"` parallelscommon.PrlctlVersionConfig `mapstructure:",squash"` parallelscommon.RunConfig `mapstructure:",squash"` parallelscommon.SSHConfig `mapstructure:",squash"` @@ -57,6 +58,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(&c.ctx)...) errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(&c.ctx, &c.PackerConfig)...) errs = packer.MultiErrorAppend(errs, c.PrlctlConfig.Prepare(&c.ctx)...) + errs = packer.MultiErrorAppend(errs, c.PrlctlPostConfig.Prepare(&c.tpl)...) errs = packer.MultiErrorAppend(errs, c.PrlctlVersionConfig.Prepare(&c.ctx)...) errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(&c.ctx)...) errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...) diff --git a/website/source/docs/builders/parallels-iso.html.markdown b/website/source/docs/builders/parallels-iso.html.markdown index b84123f8b..b7e2af527 100644 --- a/website/source/docs/builders/parallels-iso.html.markdown +++ b/website/source/docs/builders/parallels-iso.html.markdown @@ -172,6 +172,10 @@ each category, the available options are alphabetized and described. where the `Name` variable is replaced with the VM name. More details on how to use `prlctl` are below. +* `prlctl_post` (array of array of strings) - Identical to `prlctl`, + except that it is run after the virtual machine is shutdown, and before the + virtual machine is exported. + * `prlctl_version_file` (string) - The path within the virtual machine to upload a file that contains the `prlctl` version that was used to create the machine. This information can be useful for provisioning. By default this is diff --git a/website/source/docs/builders/parallels-pvm.html.markdown b/website/source/docs/builders/parallels-pvm.html.markdown index 434bda8e7..fea19fa83 100644 --- a/website/source/docs/builders/parallels-pvm.html.markdown +++ b/website/source/docs/builders/parallels-pvm.html.markdown @@ -115,6 +115,10 @@ each category, the available options are alphabetized and described. where the `Name` variable is replaced with the VM name. More details on how to use `prlctl` are below. +* `prlctl_post` (array of array of strings) - Identical to `prlctl`, + except that it is run after the virtual machine is shutdown, and before the + virtual machine is exported. + * `prlctl_version_file` (string) - The path within the virtual machine to upload a file that contains the `prlctl` version that was used to create the machine. This information can be useful for provisioning. By default this is