cleanup to make it actually build after that monstrous rebase
This commit is contained in:
parent
77abb3afd4
commit
290f4a7c4c
@ -3,6 +3,7 @@ package common
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
)
|
)
|
||||||
@ -11,6 +12,12 @@ import (
|
|||||||
const BuilderId = "mitchellh.vmware"
|
const BuilderId = "mitchellh.vmware"
|
||||||
const BuilderIdESX = "mitchellh.vmware-esx"
|
const BuilderIdESX = "mitchellh.vmware-esx"
|
||||||
|
|
||||||
|
const (
|
||||||
|
ArtifactConfFormat = "artifact.conf.format"
|
||||||
|
ArtifactConfKeepRegistered = "artifact.conf.keep_registered"
|
||||||
|
ArtifactConfSkipExport = "artifact.conf.skip_export"
|
||||||
|
)
|
||||||
|
|
||||||
// Artifact is the result of running the VMware builder, namely a set
|
// Artifact is the result of running the VMware builder, namely a set
|
||||||
// of files associated with the resulting machine.
|
// of files associated with the resulting machine.
|
||||||
type artifact struct {
|
type artifact struct {
|
||||||
@ -48,7 +55,7 @@ func NewLocalArtifact(id string, dir string) (packer.Artifact, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewArtifact(dir OutputDir, files []string, esxi bool) (packer.Artifact, err) {
|
func NewArtifact(dir OutputDir, files []string, config map[string]string, esxi bool) (packer.Artifact, error) {
|
||||||
builderID := BuilderId
|
builderID := BuilderId
|
||||||
if esxi {
|
if esxi {
|
||||||
builderID = BuilderIdESX
|
builderID = BuilderIdESX
|
||||||
@ -69,7 +76,7 @@ func (a *artifact) Files() []string {
|
|||||||
return a.f
|
return a.f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*artifact) Id() string {
|
func (a *artifact) Id() string {
|
||||||
return a.id
|
return a.id
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +85,7 @@ func (a *artifact) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *artifact) State(name string) interface{} {
|
func (a *artifact) State(name string) interface{} {
|
||||||
return nil
|
return a.config[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *artifact) Destroy() error {
|
func (a *artifact) Destroy() error {
|
||||||
|
@ -84,6 +84,7 @@ type Driver interface {
|
|||||||
// system, or an error if the driver couldn't be initialized.
|
// system, or an error if the driver couldn't be initialized.
|
||||||
func NewDriver(dconfig *DriverConfig, config *SSHConfig, commConfig *communicator.Config, vmName string) (Driver, error) {
|
func NewDriver(dconfig *DriverConfig, config *SSHConfig, commConfig *communicator.Config, vmName string) (Driver, error) {
|
||||||
drivers := []Driver{}
|
drivers := []Driver{}
|
||||||
|
|
||||||
if dconfig.RemoteType != "" {
|
if dconfig.RemoteType != "" {
|
||||||
drivers = []Driver{
|
drivers = []Driver{
|
||||||
&ESX5Driver{
|
&ESX5Driver{
|
||||||
@ -91,7 +92,7 @@ func NewDriver(dconfig *DriverConfig, config *SSHConfig, commConfig *communicato
|
|||||||
Port: dconfig.RemotePort,
|
Port: dconfig.RemotePort,
|
||||||
Username: dconfig.RemoteUser,
|
Username: dconfig.RemoteUser,
|
||||||
Password: dconfig.RemotePassword,
|
Password: dconfig.RemotePassword,
|
||||||
PrivateKey: dconfig.RemotePrivateKey,
|
PrivateKeyFile: dconfig.RemotePrivateKey,
|
||||||
Datastore: dconfig.RemoteDatastore,
|
Datastore: dconfig.RemoteDatastore,
|
||||||
CacheDatastore: dconfig.RemoteCacheDatastore,
|
CacheDatastore: dconfig.RemoteCacheDatastore,
|
||||||
CacheDirectory: dconfig.RemoteCacheDirectory,
|
CacheDirectory: dconfig.RemoteCacheDirectory,
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
commonssh "github.com/hashicorp/packer/common/ssh"
|
|
||||||
"github.com/hashicorp/packer/communicator/ssh"
|
"github.com/hashicorp/packer/communicator/ssh"
|
||||||
"github.com/hashicorp/packer/helper/communicator"
|
"github.com/hashicorp/packer/helper/communicator"
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
@ -28,7 +27,7 @@ import (
|
|||||||
// ESX5 driver talks to an ESXi5 hypervisor remotely over SSH to build
|
// ESX5 driver talks to an ESXi5 hypervisor remotely over SSH to build
|
||||||
// virtual machines. This driver can only manage one machine at a time.
|
// virtual machines. This driver can only manage one machine at a time.
|
||||||
type ESX5Driver struct {
|
type ESX5Driver struct {
|
||||||
base vmwcommon.VmwareDriver
|
base VmwareDriver
|
||||||
|
|
||||||
Host string
|
Host string
|
||||||
Port uint
|
Port uint
|
||||||
@ -184,13 +183,13 @@ func (d *ESX5Driver) IsDestroyed() (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType string) (string, error) {
|
func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType string) (string, error) {
|
||||||
finalPath := d.cachePath(localPath)
|
finalPath := d.CachePath(localPath)
|
||||||
if err := d.mkdir(filepath.ToSlash(filepath.Dir(finalPath))); err != nil {
|
if err := d.mkdir(filepath.ToSlash(filepath.Dir(finalPath))); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Verifying checksum of %s", finalPath)
|
log.Printf("Verifying checksum of %s", finalPath)
|
||||||
if d.verifyChecksum(checksumType, checksum, finalPath) {
|
if d.VerifyChecksum(checksumType, checksum, finalPath) {
|
||||||
log.Println("Initial checksum matched, no upload needed.")
|
log.Println("Initial checksum matched, no upload needed.")
|
||||||
return finalPath, nil
|
return finalPath, nil
|
||||||
}
|
}
|
||||||
@ -203,7 +202,7 @@ func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *ESX5Driver) RemoveCache(localPath string) error {
|
func (d *ESX5Driver) RemoveCache(localPath string) error {
|
||||||
finalPath := d.cachePath(localPath)
|
finalPath := d.CachePath(localPath)
|
||||||
log.Printf("Removing remote cache path %s (local %s)", finalPath, localPath)
|
log.Printf("Removing remote cache path %s (local %s)", finalPath, localPath)
|
||||||
return d.sh("rm", "-f", strconv.Quote(finalPath))
|
return d.sh("rm", "-f", strconv.Quote(finalPath))
|
||||||
}
|
}
|
||||||
@ -564,7 +563,7 @@ func (d *ESX5Driver) datastorePath(path string) string {
|
|||||||
return filepath.ToSlash(filepath.Join("/vmfs/volumes", d.Datastore, dirPath, filepath.Base(path)))
|
return filepath.ToSlash(filepath.Join("/vmfs/volumes", d.Datastore, dirPath, filepath.Base(path)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ESX5Driver) cachePath(path string) string {
|
func (d *ESX5Driver) CachePath(path string) string {
|
||||||
return filepath.ToSlash(filepath.Join("/vmfs/volumes", d.CacheDatastore, d.CacheDirectory, filepath.Base(path)))
|
return filepath.ToSlash(filepath.Join("/vmfs/volumes", d.CacheDatastore, d.CacheDirectory, filepath.Base(path)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -662,7 +661,7 @@ func (d *ESX5Driver) Download(src, dst string) error {
|
|||||||
return d.comm.Download(d.datastorePath(src), file)
|
return d.comm.Download(d.datastorePath(src), file)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ESX5Driver) verifyChecksum(ctype string, hash string, file string) bool {
|
func (d *ESX5Driver) VerifyChecksum(ctype string, hash string, file string) bool {
|
||||||
if ctype == "none" {
|
if ctype == "none" {
|
||||||
if err := d.sh("stat", strconv.Quote(file)); err != nil {
|
if err := d.sh("stat", strconv.Quote(file)); err != nil {
|
||||||
return false
|
return false
|
||||||
@ -731,7 +730,7 @@ func (d *ESX5Driver) esxcli(args ...string) (*esxcliReader, error) {
|
|||||||
return &esxcliReader{r, header}, nil
|
return &esxcliReader{r, header}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ESX5Driver) GetVmwareDriver() vmwcommon.VmwareDriver {
|
func (d *ESX5Driver) GetVmwareDriver() VmwareDriver {
|
||||||
return d.base
|
return d.base
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package common
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/mitchellh/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ExportConfig struct {
|
type ExportConfig struct {
|
||||||
|
@ -4,12 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
ArtifactConfFormat = "artifact.conf.format"
|
|
||||||
ArtifactConfKeepRegistered = "artifact.conf.keep_registered"
|
|
||||||
ArtifactConfSkipExport = "artifact.conf.skip_export"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Artifact is the result of running the VMware builder, namely a set
|
// Artifact is the result of running the VMware builder, namely a set
|
||||||
// of files associated with the resulting machine.
|
// of files associated with the resulting machine.
|
||||||
type RemoteArtifact struct {
|
type RemoteArtifact struct {
|
||||||
@ -28,7 +22,7 @@ func (a *RemoteArtifact) Files() []string {
|
|||||||
return a.f
|
return a.f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*RemoteArtifact) Id() string {
|
func (a *RemoteArtifact) Id() string {
|
||||||
return a.id
|
return a.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@ -29,7 +28,6 @@ type StepConfigureVMX struct {
|
|||||||
func (s *StepConfigureVMX) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepConfigureVMX) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
log.Printf("Configuring VMX...\n")
|
log.Printf("Configuring VMX...\n")
|
||||||
|
|
||||||
var vmxContents []byte
|
|
||||||
var err error
|
var err error
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ func (s *StepExport) Run(_ context.Context, state multistep.StateBag) multistep.
|
|||||||
|
|
||||||
// Export the VM
|
// Export the VM
|
||||||
if s.OutputDir == "" {
|
if s.OutputDir == "" {
|
||||||
s.OutputDir = c.VMName + "." + s.Format
|
s.OutputDir = s.VMName + "." + s.Format
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Format == "ova" {
|
if s.Format == "ova" {
|
||||||
|
@ -13,11 +13,13 @@ type StepRegister struct {
|
|||||||
registeredPath string
|
registeredPath string
|
||||||
Format string
|
Format string
|
||||||
KeepRegistered bool
|
KeepRegistered bool
|
||||||
|
SkipExport bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepRegister) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepRegister) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
driver := state.Get("driver").(Driver)
|
driver := state.Get("driver").(Driver)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
vmxPath := state.Get("vmx_path").(string)
|
vmxPath := state.Get("vmx_path").(string)
|
||||||
|
|
||||||
if remoteDriver, ok := driver.(RemoteDriver); ok {
|
if remoteDriver, ok := driver.(RemoteDriver); ok {
|
||||||
@ -51,7 +53,7 @@ func (s *StepRegister) Cleanup(state multistep.StateBag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if remoteDriver, ok := driver.(RemoteDriver); ok {
|
if remoteDriver, ok := driver.(RemoteDriver); ok {
|
||||||
if s.Format == "" || config.SkipExport {
|
if s.Format == "" || s.SkipExport {
|
||||||
ui.Say("Unregistering virtual machine...")
|
ui.Say("Unregistering virtual machine...")
|
||||||
if err := remoteDriver.Unregister(s.registeredPath); err != nil {
|
if err := remoteDriver.Unregister(s.registeredPath); err != nil {
|
||||||
ui.Error(fmt.Sprintf("Error unregistering VM: %s", err))
|
ui.Error(fmt.Sprintf("Error unregistering VM: %s", err))
|
||||||
|
@ -318,6 +318,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||||||
&vmwcommon.StepRegister{
|
&vmwcommon.StepRegister{
|
||||||
Format: b.config.Format,
|
Format: b.config.Format,
|
||||||
KeepRegistered: b.config.KeepRegistered,
|
KeepRegistered: b.config.KeepRegistered,
|
||||||
|
SkipExport: b.config.SkipExport,
|
||||||
},
|
},
|
||||||
&vmwcommon.StepRun{
|
&vmwcommon.StepRun{
|
||||||
DurationBeforeStop: 5 * time.Second,
|
DurationBeforeStop: 5 * time.Second,
|
||||||
@ -405,7 +406,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return vmwcommon.NewArtifact(dir, files, b.config.RemoteType != ""), nil
|
config := make(map[string]string)
|
||||||
|
config[vmwcommon.ArtifactConfKeepRegistered] = strconv.FormatBool(b.config.KeepRegistered)
|
||||||
|
config[vmwcommon.ArtifactConfFormat] = b.config.Format
|
||||||
|
config[vmwcommon.ArtifactConfSkipExport] = strconv.FormatBool(b.config.SkipExport)
|
||||||
|
|
||||||
|
return vmwcommon.NewArtifact(dir, files, config, b.config.RemoteType != "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) Cancel() {
|
func (b *Builder) Cancel() {
|
||||||
|
@ -36,10 +36,10 @@ func (s *stepRemoteUpload) Run(_ context.Context, state multistep.StateBag) mult
|
|||||||
checksum := config.ISOChecksum
|
checksum := config.ISOChecksum
|
||||||
checksumType := config.ISOChecksumType
|
checksumType := config.ISOChecksumType
|
||||||
|
|
||||||
if esx5, ok := remote.(*ESX5Driver); ok {
|
if esx5, ok := remote.(*vmwcommon.ESX5Driver); ok {
|
||||||
remotePath := esx5.cachePath(path)
|
remotePath := esx5.CachePath(path)
|
||||||
|
|
||||||
if esx5.verifyChecksum(checksumType, checksum, remotePath) {
|
if esx5.VerifyChecksum(checksumType, checksum, remotePath) {
|
||||||
ui.Say("Remote cache was verified skipping remote upload...")
|
ui.Say("Remote cache was verified skipping remote upload...")
|
||||||
state.Put(s.Key, remotePath)
|
state.Put(s.Key, remotePath)
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
@ -68,7 +68,7 @@ func (s *stepRemoteUpload) Cleanup(state multistep.StateBag) {
|
|||||||
|
|
||||||
driver := state.Get("driver").(vmwcommon.Driver)
|
driver := state.Get("driver").(vmwcommon.Driver)
|
||||||
|
|
||||||
remote, ok := driver.(RemoteDriver)
|
remote, ok := driver.(vmwcommon.RemoteDriver)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
||||||
@ -105,6 +106,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||||||
&vmwcommon.StepRegister{
|
&vmwcommon.StepRegister{
|
||||||
Format: b.config.Format,
|
Format: b.config.Format,
|
||||||
KeepRegistered: b.config.KeepRegistered,
|
KeepRegistered: b.config.KeepRegistered,
|
||||||
|
SkipExport: b.config.SkipExport,
|
||||||
},
|
},
|
||||||
&vmwcommon.StepRun{
|
&vmwcommon.StepRun{
|
||||||
DurationBeforeStop: 5 * time.Second,
|
DurationBeforeStop: 5 * time.Second,
|
||||||
@ -191,7 +193,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return vmwcommon.NewArtifact(dir, files, b.config.RemoteType != ""), nil
|
config := make(map[string]string)
|
||||||
|
config[vmwcommon.ArtifactConfKeepRegistered] = strconv.FormatBool(b.config.KeepRegistered)
|
||||||
|
config[vmwcommon.ArtifactConfFormat] = b.config.Format
|
||||||
|
config[vmwcommon.ArtifactConfSkipExport] = strconv.FormatBool(b.config.SkipExport)
|
||||||
|
|
||||||
|
return vmwcommon.NewArtifact(dir, files, config, b.config.RemoteType != "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel.
|
// Cancel.
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/builder/vmware/iso"
|
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
||||||
"github.com/hashicorp/packer/common"
|
"github.com/hashicorp/packer/common"
|
||||||
"github.com/hashicorp/packer/helper/config"
|
"github.com/hashicorp/packer/helper/config"
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
@ -20,7 +20,7 @@ import (
|
|||||||
|
|
||||||
var builtins = map[string]string{
|
var builtins = map[string]string{
|
||||||
vsphere.BuilderId: "vmware",
|
vsphere.BuilderId: "vmware",
|
||||||
iso.BuilderIdESX: "vmware",
|
vmwcommon.BuilderIdESX: "vmware",
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@ -96,9 +96,9 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
|
|||||||
"Artifact type %s does not fit this requirement", artifact.BuilderId())
|
"Artifact type %s does not fit this requirement", artifact.BuilderId())
|
||||||
}
|
}
|
||||||
|
|
||||||
f := artifact.State(iso.ArtifactConfFormat)
|
f := artifact.State(vmwcommon.ArtifactConfFormat)
|
||||||
k := artifact.State(iso.ArtifactConfKeepRegistered)
|
k := artifact.State(vmwcommon.ArtifactConfKeepRegistered)
|
||||||
s := artifact.State(iso.ArtifactConfSkipExport)
|
s := artifact.State(vmwcommon.ArtifactConfSkipExport)
|
||||||
|
|
||||||
if f != "" && k != "true" && s == "false" {
|
if f != "" && k != "true" && s == "false" {
|
||||||
return nil, false, errors.New("To use this post-processor with exporting behavior you need set keep_registered as true")
|
return nil, false, errors.New("To use this post-processor with exporting behavior you need set keep_registered as true")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user