Merge branch 'issue_2080' of https://github.com/rickard-von-essen/packer into rickard-von-essen-issue_2080
This commit is contained in:
commit
13c2c4660d
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)...)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue