From f01346d305a670bb01f2dce506acb87e320c08d8 Mon Sep 17 00:00:00 2001 From: ktruong7 Date: Thu, 7 Nov 2013 11:13:52 -0500 Subject: [PATCH] Added a description field for the vmware builder that is written to the vm after a build --- builder/vmware/builder.go | 5 +++++ builder/vmware/builder_test.go | 28 ++++++++++++++++++++++++++++ builder/vmware/step_create_vmx.go | 2 ++ 3 files changed, 35 insertions(+) diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index f75014459..47bbcd124 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -54,6 +54,7 @@ type config struct { VMXTemplatePath string `mapstructure:"vmx_template_path"` VNCPortMin uint `mapstructure:"vnc_port_min"` VNCPortMax uint `mapstructure:"vnc_port_max"` + Description string `mapstructure:"description"` RawBootWait string `mapstructure:"boot_wait"` RawSingleISOUrl string `mapstructure:"iso_url"` @@ -138,6 +139,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { if b.config.ToolsUploadPath == "" { b.config.ToolsUploadPath = "{{ .Flavor }}.iso" } + + if b.config.Description == "" { + b.config.Description = "" + } // Errors templates := map[string]*string{ diff --git a/builder/vmware/builder_test.go b/builder/vmware/builder_test.go index 893970768..b13d114c7 100644 --- a/builder/vmware/builder_test.go +++ b/builder/vmware/builder_test.go @@ -744,6 +744,34 @@ func TestBuilderPrepare_VNCPort(t *testing.T) { } } +func TestBuilderPrepare_Description(t *testing.T) { + var b Builder + config := testConfig() + + // Test with no description field + config["description"] = "" + warns, err := b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err != nil { + t.Fatalf("err: %s", err) + } + if b.config.Description != "" { + t.Fatalf("Wrong value: %s", b.config.Description) + } + + // Test with a description field + config["description"] = "VM description" + warns, err = b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if b.config.Description != "VM description" { + t.Fatalf("Wrong value: %s", b.config.Description) + } +} + func TestBuilderPrepare_VMXData(t *testing.T) { var b Builder config := testConfig() diff --git a/builder/vmware/step_create_vmx.go b/builder/vmware/step_create_vmx.go index e2f7c028a..9f873b46e 100644 --- a/builder/vmware/step_create_vmx.go +++ b/builder/vmware/step_create_vmx.go @@ -90,6 +90,8 @@ func (stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction { // Set this so that no dialogs ever appear from Packer. vmxData["msg.autoAnswer"] = "true" + // prints the template description into the "notes" field on VMWare + vmxData["annotation"] = config.Description vmxPath := filepath.Join(config.OutputDir, config.VMName+".vmx") if err := WriteVMX(vmxPath, vmxData); err != nil {