mirror of https://github.com/hashicorp/packer
Fixes #2080 Add prlctl_post in builder Parallels
This adds config option prlctl_post for builder parallels-iso/pvm. It allows additional prlctl commands to run after the VM has been shutdown just before being exported.pull/2126/head
parent
c8b3dfff5f
commit
1365627e31
@ -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
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue