add exported files to VSphere artifact (#9020)

* add exported files to VSphere artifact

* clean up grammar for vsphere template docs

* add to vsphere clone
This commit is contained in:
Megan Marsh 2020-04-30 12:22:57 -07:00 committed by GitHub
parent 86ac132056
commit 3f8ee2b426
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 11 deletions

View File

@ -108,5 +108,9 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
VM: state.Get("vm").(*driver.VirtualMachine),
StateData: map[string]interface{}{"generated_data": state.Get("generated_data")},
}
if b.config.Export != nil {
artifact.Outconfig = &b.config.Export.OutputDir
}
return artifact, nil
}

View File

@ -1,12 +1,15 @@
package common
import (
"os"
"github.com/hashicorp/packer/builder/vsphere/driver"
)
const BuilderId = "jetbrains.vsphere"
type Artifact struct {
Outconfig *OutputConfig
Name string
VM *driver.VirtualMachine
@ -20,6 +23,10 @@ func (a *Artifact) BuilderId() string {
}
func (a *Artifact) Files() []string {
if a.Outconfig != nil {
files, _ := a.Outconfig.ListFiles()
return files
}
return []string{}
}
@ -36,5 +43,8 @@ func (a *Artifact) State(name string) interface{} {
}
func (a *Artifact) Destroy() error {
if a.Outconfig != nil {
os.RemoveAll(a.Outconfig.OutputDir)
}
return a.VM.Destroy()
}

View File

@ -5,6 +5,8 @@ package common
import (
"fmt"
"os"
"path/filepath"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/template/interpolate"
@ -28,3 +30,20 @@ func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig
return nil
}
// Stolen from output_dir_local.go in vmware builder.
func (c *OutputConfig) ListFiles() ([]string, error) {
files := make([]string, 0, 10)
visit := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
files = append(files, path)
}
return nil
}
return files, filepath.Walk(c.OutputDir, visit)
}

View File

@ -56,6 +56,7 @@ type ExportConfig struct {
Images bool `mapstructure:"images"`
// generate manifest using sha1, sha256, sha512. Defaults to 'sha256'. Use 'none' for no manifest.
Manifest string `mapstructure:"manifest"`
// Directory on the computer running Packer to export files to
OutputDir OutputConfig `mapstructure:",squash"`
// Advanced ovf export options. Options can include:
// * mac - MAC address is exported for all ethernet devices

View File

@ -153,10 +153,16 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
if _, ok := state.GetOk("vm"); !ok {
return nil, nil
}
artifact := &common.Artifact{
Name: b.config.VMName,
VM: state.Get("vm").(*driver.VirtualMachine),
StateData: map[string]interface{}{"generated_data": state.Get("generated_data")},
}
if b.config.Export != nil {
artifact.Outconfig = &b.config.Export.OutputDir
}
return artifact, nil
}

View File

@ -1,13 +1,9 @@
---
description: >
The Packer vSphere Template post-processor takes an artifact from the
VMware-iso builder, built on ESXi (i.e. remote) or an artifact from the
vSphere
post-processor and allows to mark a VM as a template and leaving it in a path
of choice.
[vSphere](/docs/post-processors/vsphere) post-processor, marks the VM as a
template, and leaves it in the path of your choice.
layout: docs
page_title: vSphere Template - Post-Processors
sidebar_title: vSphere Template
@ -19,8 +15,8 @@ Type: `vsphere-template`
The Packer vSphere Template post-processor takes an artifact from the
VMware-iso builder, built on ESXi (i.e. remote) or an artifact from the
[vSphere](/docs/post-processors/vsphere) post-processor and allows to mark
a VM as a template and leaving it in a path of choice.
[vSphere](/docs/post-processors/vsphere) post-processor, marks the VM as a
template, and leaves it in the path of your choice.
## Example