From 4023b618b4ad6c60fbb9ba1f55464ba47768db55 Mon Sep 17 00:00:00 2001 From: bugbuilder Date: Sun, 23 Jul 2017 01:31:46 -0400 Subject: [PATCH 1/9] Verify remote cache for ESXi --- builder/vmware/iso/builder.go | 19 ++++--- builder/vmware/iso/step_download.go | 72 ++++++++++++++++++++++++ builder/vmware/iso/step_remote_upload.go | 26 +++++---- 3 files changed, 98 insertions(+), 19 deletions(-) create mode 100644 builder/vmware/iso/step_download.go diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 42038b96a..5dba8de4e 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -220,15 +220,16 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe RemoteType: b.config.RemoteType, ToolsUploadFlavor: b.config.ToolsUploadFlavor, }, - &common.StepDownload{ - Checksum: b.config.ISOChecksum, - ChecksumType: b.config.ISOChecksumType, - Description: "ISO", - Extension: b.config.TargetExtension, - ResultKey: "iso_path", - TargetPath: b.config.TargetPath, - Url: b.config.ISOUrls, - }, + &stepDownload{ + step: &common.StepDownload{ + Checksum: b.config.ISOChecksum, + ChecksumType: b.config.ISOChecksumType, + Description: "ISO", + Extension: b.config.TargetExtension, + ResultKey: "iso_path", + TargetPath: b.config.TargetPath, + Url: b.config.ISOUrls, + }}, &vmwcommon.StepOutputDir{ Force: b.config.PackerForce, }, diff --git a/builder/vmware/iso/step_download.go b/builder/vmware/iso/step_download.go new file mode 100644 index 000000000..874a2a26e --- /dev/null +++ b/builder/vmware/iso/step_download.go @@ -0,0 +1,72 @@ +package iso + +import ( + "crypto/sha1" + "encoding/hex" + "fmt" + neturl "net/url" + + vmwcommon "github.com/hashicorp/packer/builder/vmware/common" + "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/packer" + "github.com/mitchellh/multistep" + "runtime" +) + +type stepDownload struct { + step *common.StepDownload +} + +func (s *stepDownload) Run(state multistep.StateBag) multistep.StepAction { + cache := state.Get("cache").(packer.Cache) + driver := state.Get("driver").(vmwcommon.Driver) + ui := state.Get("ui").(packer.Ui) + + if esx5, ok := driver.(*ESX5Driver); ok { + ui.Say("Verifying remote cache") + + targetPath := "" + for _, url := range s.step.Url { + targetPath = s.step.TargetPath + + if targetPath == "" { + if u, err := neturl.Parse(url); err == nil { + + if u.Scheme == "file" { + + if u.Path != "" { + targetPath = u.Path + } else if u.Opaque != "" { + targetPath = u.Opaque + } + + if runtime.GOOS == "windows" && len(targetPath) > 0 && targetPath[0] == '/' { + targetPath = targetPath[1:] + } + } + } + + if targetPath == "" { + hash := sha1.Sum([]byte(url)) + cacheKey := fmt.Sprintf("%s.%s", hex.EncodeToString(hash[:]), s.step.Extension) + targetPath = cache.Lock(cacheKey) + cache.Unlock(cacheKey) + } + } + + remotePath := esx5.cachePath(targetPath) + ui.Message(remotePath) + if esx5.verifyChecksum(s.step.ChecksumType, s.step.Checksum, remotePath) { + state.Put(s.step.ResultKey, "skip_upload:"+remotePath) + ui.Message("Remote cache verified, skipping download step") + return multistep.ActionContinue + } + + ui.Message("Remote cache couldn't be verified") + } + } + + return s.step.Run(state) +} + +func (s *stepDownload) Cleanup(multistep.StateBag) {} diff --git a/builder/vmware/iso/step_remote_upload.go b/builder/vmware/iso/step_remote_upload.go index 6ef27bce6..852369627 100644 --- a/builder/vmware/iso/step_remote_upload.go +++ b/builder/vmware/iso/step_remote_upload.go @@ -2,10 +2,12 @@ package iso import ( "fmt" + "log" + "strings" + vmwcommon "github.com/hashicorp/packer/builder/vmware/common" "github.com/hashicorp/packer/packer" "github.com/mitchellh/multistep" - "log" ) // stepRemoteUpload uploads some thing from the state bag to a remote driver @@ -33,17 +35,21 @@ func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction { checksum := config.ISOChecksum checksumType := config.ISOChecksumType - ui.Say(s.Message) - log.Printf("Remote uploading: %s", path) - newPath, err := remote.UploadISO(path, checksum, checksumType) - if err != nil { - err := fmt.Errorf("Error uploading file: %s", err) - state.Put("error", err) - ui.Error(err.Error()) - return multistep.ActionHalt + if !strings.HasPrefix(path, "skip_upload:") { + log.Printf("Remote uploading: %s", path) + newPath, err := remote.UploadISO(path, checksum, checksumType) + + if err != nil { + err := fmt.Errorf("Error uploading file: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + state.Put(s.Key, newPath) + } else { + state.Put(s.Key, strings.Split("skip_upload:", path)[0]) } - state.Put(s.Key, newPath) return multistep.ActionContinue } From 84ad413e23186f9ecfbb74d0e0a52a844c8a7628 Mon Sep 17 00:00:00 2001 From: bugbuilder Date: Sun, 23 Jul 2017 03:20:06 -0400 Subject: [PATCH 2/9] Set remote iso path --- builder/vmware/iso/step_remote_upload.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/vmware/iso/step_remote_upload.go b/builder/vmware/iso/step_remote_upload.go index 852369627..2cb5003f5 100644 --- a/builder/vmware/iso/step_remote_upload.go +++ b/builder/vmware/iso/step_remote_upload.go @@ -36,9 +36,9 @@ func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction { checksumType := config.ISOChecksumType if !strings.HasPrefix(path, "skip_upload:") { + ui.Say(s.Message) log.Printf("Remote uploading: %s", path) newPath, err := remote.UploadISO(path, checksum, checksumType) - if err != nil { err := fmt.Errorf("Error uploading file: %s", err) state.Put("error", err) @@ -47,7 +47,7 @@ func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction { } state.Put(s.Key, newPath) } else { - state.Put(s.Key, strings.Split("skip_upload:", path)[0]) + state.Put(s.Key, strings.Split(path, "skip_upload:")[1]) } return multistep.ActionContinue From 22aa89db274245621fda6b155f2622f57a2dd184 Mon Sep 17 00:00:00 2001 From: bugbuilder Date: Sun, 23 Jul 2017 14:11:48 -0400 Subject: [PATCH 3/9] file scheme has prioriry as remote targetPath --- builder/vmware/iso/step_download.go | 32 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/builder/vmware/iso/step_download.go b/builder/vmware/iso/step_download.go index 874a2a26e..7228fc8dd 100644 --- a/builder/vmware/iso/step_download.go +++ b/builder/vmware/iso/step_download.go @@ -29,29 +29,27 @@ func (s *stepDownload) Run(state multistep.StateBag) multistep.StepAction { for _, url := range s.step.Url { targetPath = s.step.TargetPath - if targetPath == "" { - if u, err := neturl.Parse(url); err == nil { + if u, err := neturl.Parse(url); err == nil { - if u.Scheme == "file" { + if u.Scheme == "file" { - if u.Path != "" { - targetPath = u.Path - } else if u.Opaque != "" { - targetPath = u.Opaque - } + if u.Path != "" { + targetPath = u.Path + } else if u.Opaque != "" { + targetPath = u.Opaque + } - if runtime.GOOS == "windows" && len(targetPath) > 0 && targetPath[0] == '/' { - targetPath = targetPath[1:] - } + if runtime.GOOS == "windows" && len(targetPath) > 0 && targetPath[0] == '/' { + targetPath = targetPath[1:] } } + } - if targetPath == "" { - hash := sha1.Sum([]byte(url)) - cacheKey := fmt.Sprintf("%s.%s", hex.EncodeToString(hash[:]), s.step.Extension) - targetPath = cache.Lock(cacheKey) - cache.Unlock(cacheKey) - } + if targetPath == "" { + hash := sha1.Sum([]byte(url)) + cacheKey := fmt.Sprintf("%s.%s", hex.EncodeToString(hash[:]), s.step.Extension) + targetPath = cache.Lock(cacheKey) + cache.Unlock(cacheKey) } remotePath := esx5.cachePath(targetPath) From d4e0847a74766e60acc61bfb4c2fa9214341eb5d Mon Sep 17 00:00:00 2001 From: bugbuilder Date: Sun, 23 Jul 2017 14:16:03 -0400 Subject: [PATCH 4/9] remove unnecessary initialization --- builder/vmware/iso/step_download.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/builder/vmware/iso/step_download.go b/builder/vmware/iso/step_download.go index 7228fc8dd..d9a26fc17 100644 --- a/builder/vmware/iso/step_download.go +++ b/builder/vmware/iso/step_download.go @@ -25,12 +25,10 @@ func (s *stepDownload) Run(state multistep.StateBag) multistep.StepAction { if esx5, ok := driver.(*ESX5Driver); ok { ui.Say("Verifying remote cache") - targetPath := "" for _, url := range s.step.Url { - targetPath = s.step.TargetPath + targetPath := s.step.TargetPath if u, err := neturl.Parse(url); err == nil { - if u.Scheme == "file" { if u.Path != "" { From b50e279d8abfec34350ccd86e55a99973a53610c Mon Sep 17 00:00:00 2001 From: bugbuilder Date: Mon, 24 Jul 2017 00:11:30 -0400 Subject: [PATCH 5/9] Making visible verify cache step --- builder/vmware/iso/builder.go | 34 +++++++++++-------- builder/vmware/iso/step_register.go | 2 +- builder/vmware/iso/step_remote_upload.go | 34 ++++++++++--------- ...{step_download.go => step_verify_cache.go} | 28 ++++++++------- 4 files changed, 54 insertions(+), 44 deletions(-) rename builder/vmware/iso/{step_download.go => step_verify_cache.go} (63%) diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 5dba8de4e..7d3d6074e 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -215,21 +215,28 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe state.Put("hook", hook) state.Put("ui", ui) + stepVerifyCache := &stepVerifyCache{ + download: &common.StepDownload{ + Checksum: b.config.ISOChecksum, + ChecksumType: b.config.ISOChecksumType, + Description: "ISO", + Extension: b.config.TargetExtension, + ResultKey: "iso_path", + TargetPath: b.config.TargetPath, + Url: b.config.ISOUrls, + }, + remoteUpload: &stepRemoteUpload{ + Key: "iso_path", + Message: "Uploading ISO to remoteUpload machine...", + }, + } + steps := []multistep.Step{ &vmwcommon.StepPrepareTools{ RemoteType: b.config.RemoteType, ToolsUploadFlavor: b.config.ToolsUploadFlavor, }, - &stepDownload{ - step: &common.StepDownload{ - Checksum: b.config.ISOChecksum, - ChecksumType: b.config.ISOChecksumType, - Description: "ISO", - Extension: b.config.TargetExtension, - ResultKey: "iso_path", - TargetPath: b.config.TargetPath, - Url: b.config.ISOUrls, - }}, + stepVerifyCache, &vmwcommon.StepOutputDir{ Force: b.config.PackerForce, }, @@ -239,12 +246,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe }, &stepRemoteUpload{ Key: "floppy_path", - Message: "Uploading Floppy to remote machine...", - }, - &stepRemoteUpload{ - Key: "iso_path", - Message: "Uploading ISO to remote machine...", + Message: "Uploading Floppy to remoteUpload machine...", }, + stepVerifyCache.remoteUpload, &stepCreateDisk{}, &stepCreateVMX{}, &vmwcommon.StepConfigureVMX{ diff --git a/builder/vmware/iso/step_register.go b/builder/vmware/iso/step_register.go index a90de5fa2..524e3006d 100644 --- a/builder/vmware/iso/step_register.go +++ b/builder/vmware/iso/step_register.go @@ -20,7 +20,7 @@ func (s *StepRegister) Run(state multistep.StateBag) multistep.StepAction { vmxPath := state.Get("vmx_path").(string) if remoteDriver, ok := driver.(RemoteDriver); ok { - ui.Say("Registering remote VM...") + ui.Say("Registering remoteUpload VM...") if err := remoteDriver.Register(vmxPath); err != nil { err := fmt.Errorf("Error registering VM: %s", err) state.Put("error", err) diff --git a/builder/vmware/iso/step_remote_upload.go b/builder/vmware/iso/step_remote_upload.go index 2cb5003f5..56e1d0e58 100644 --- a/builder/vmware/iso/step_remote_upload.go +++ b/builder/vmware/iso/step_remote_upload.go @@ -3,24 +3,30 @@ package iso import ( "fmt" "log" - "strings" vmwcommon "github.com/hashicorp/packer/builder/vmware/common" "github.com/hashicorp/packer/packer" "github.com/mitchellh/multistep" ) -// stepRemoteUpload uploads some thing from the state bag to a remote driver -// (if it can) and stores that new remote path into the state bag. +// stepRemoteUpload uploads some thing from the state bag to a remoteUpload driver +// (if it can) and stores that new remoteUpload path into the state bag. type stepRemoteUpload struct { Key string Message string + + // Set this to true for skip + Skip bool } func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction { driver := state.Get("driver").(vmwcommon.Driver) ui := state.Get("ui").(packer.Ui) + if s.Skip { + return multistep.ActionContinue + } + remote, ok := driver.(RemoteDriver) if !ok { return multistep.ActionContinue @@ -35,20 +41,16 @@ func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction { checksum := config.ISOChecksum checksumType := config.ISOChecksumType - if !strings.HasPrefix(path, "skip_upload:") { - ui.Say(s.Message) - log.Printf("Remote uploading: %s", path) - newPath, err := remote.UploadISO(path, checksum, checksumType) - if err != nil { - err := fmt.Errorf("Error uploading file: %s", err) - state.Put("error", err) - ui.Error(err.Error()) - return multistep.ActionHalt - } - state.Put(s.Key, newPath) - } else { - state.Put(s.Key, strings.Split(path, "skip_upload:")[1]) + ui.Say(s.Message) + log.Printf("Remote uploading: %s", path) + newPath, err := remote.UploadISO(path, checksum, checksumType) + if err != nil { + err := fmt.Errorf("Error uploading file: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt } + state.Put(s.Key, newPath) return multistep.ActionContinue } diff --git a/builder/vmware/iso/step_download.go b/builder/vmware/iso/step_verify_cache.go similarity index 63% rename from builder/vmware/iso/step_download.go rename to builder/vmware/iso/step_verify_cache.go index d9a26fc17..01e90bbbf 100644 --- a/builder/vmware/iso/step_download.go +++ b/builder/vmware/iso/step_verify_cache.go @@ -13,20 +13,21 @@ import ( "runtime" ) -type stepDownload struct { - step *common.StepDownload +type stepVerifyCache struct { + download *common.StepDownload + remoteUpload *stepRemoteUpload } -func (s *stepDownload) Run(state multistep.StateBag) multistep.StepAction { +func (s *stepVerifyCache) Run(state multistep.StateBag) multistep.StepAction { cache := state.Get("cache").(packer.Cache) driver := state.Get("driver").(vmwcommon.Driver) ui := state.Get("ui").(packer.Ui) if esx5, ok := driver.(*ESX5Driver); ok { - ui.Say("Verifying remote cache") + ui.Say("Verifying remoteUpload cache") - for _, url := range s.step.Url { - targetPath := s.step.TargetPath + for _, url := range s.download.Url { + targetPath := s.download.TargetPath if u, err := neturl.Parse(url); err == nil { if u.Scheme == "file" { @@ -45,16 +46,19 @@ func (s *stepDownload) Run(state multistep.StateBag) multistep.StepAction { if targetPath == "" { hash := sha1.Sum([]byte(url)) - cacheKey := fmt.Sprintf("%s.%s", hex.EncodeToString(hash[:]), s.step.Extension) + cacheKey := fmt.Sprintf("%s.%s", hex.EncodeToString(hash[:]), s.download.Extension) targetPath = cache.Lock(cacheKey) cache.Unlock(cacheKey) } remotePath := esx5.cachePath(targetPath) ui.Message(remotePath) - if esx5.verifyChecksum(s.step.ChecksumType, s.step.Checksum, remotePath) { - state.Put(s.step.ResultKey, "skip_upload:"+remotePath) - ui.Message("Remote cache verified, skipping download step") + + if esx5.verifyChecksum(s.download.ChecksumType, s.download.Checksum, remotePath) { + ui.Message("Remote cache verified, skipping download/upload step") + + s.remoteUpload.Skip = true + state.Put(s.download.ResultKey, remotePath) return multistep.ActionContinue } @@ -62,7 +66,7 @@ func (s *stepDownload) Run(state multistep.StateBag) multistep.StepAction { } } - return s.step.Run(state) + return s.download.Run(state) } -func (s *stepDownload) Cleanup(multistep.StateBag) {} +func (s *stepVerifyCache) Cleanup(multistep.StateBag) {} From f31f1542377710471b2aad5d245dad035c6bac93 Mon Sep 17 00:00:00 2001 From: bugbuilder Date: Mon, 24 Jul 2017 00:17:18 -0400 Subject: [PATCH 6/9] Cleaning refactoring name errors --- builder/vmware/iso/step_register.go | 2 +- builder/vmware/iso/step_remote_upload.go | 4 ++-- builder/vmware/iso/step_verify_cache.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/builder/vmware/iso/step_register.go b/builder/vmware/iso/step_register.go index 524e3006d..a90de5fa2 100644 --- a/builder/vmware/iso/step_register.go +++ b/builder/vmware/iso/step_register.go @@ -20,7 +20,7 @@ func (s *StepRegister) Run(state multistep.StateBag) multistep.StepAction { vmxPath := state.Get("vmx_path").(string) if remoteDriver, ok := driver.(RemoteDriver); ok { - ui.Say("Registering remoteUpload VM...") + ui.Say("Registering remote VM...") if err := remoteDriver.Register(vmxPath); err != nil { err := fmt.Errorf("Error registering VM: %s", err) state.Put("error", err) diff --git a/builder/vmware/iso/step_remote_upload.go b/builder/vmware/iso/step_remote_upload.go index 56e1d0e58..691ebcb84 100644 --- a/builder/vmware/iso/step_remote_upload.go +++ b/builder/vmware/iso/step_remote_upload.go @@ -9,8 +9,8 @@ import ( "github.com/mitchellh/multistep" ) -// stepRemoteUpload uploads some thing from the state bag to a remoteUpload driver -// (if it can) and stores that new remoteUpload path into the state bag. +// stepRemoteUpload uploads some thing from the state bag to a remote driver +// (if it can) and stores that new remote path into the state bag. type stepRemoteUpload struct { Key string Message string diff --git a/builder/vmware/iso/step_verify_cache.go b/builder/vmware/iso/step_verify_cache.go index 01e90bbbf..7aefa128c 100644 --- a/builder/vmware/iso/step_verify_cache.go +++ b/builder/vmware/iso/step_verify_cache.go @@ -24,7 +24,7 @@ func (s *stepVerifyCache) Run(state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) if esx5, ok := driver.(*ESX5Driver); ok { - ui.Say("Verifying remoteUpload cache") + ui.Say("Verifying remote cache") for _, url := range s.download.Url { targetPath := s.download.TargetPath From 15eb33859603b4b0d603310957d4b60943bed21a Mon Sep 17 00:00:00 2001 From: bugbuilder Date: Mon, 24 Jul 2017 00:30:55 -0400 Subject: [PATCH 7/9] Cleaning refactoring name errors x2 --- builder/vmware/iso/builder.go | 4 ++-- builder/vmware/iso/step_verify_cache.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 7d3d6074e..75c37f875 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -227,7 +227,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe }, remoteUpload: &stepRemoteUpload{ Key: "iso_path", - Message: "Uploading ISO to remoteUpload machine...", + Message: "Uploading ISO to remote machine...", }, } @@ -246,7 +246,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe }, &stepRemoteUpload{ Key: "floppy_path", - Message: "Uploading Floppy to remoteUpload machine...", + Message: "Uploading Floppy to remote machine...", }, stepVerifyCache.remoteUpload, &stepCreateDisk{}, diff --git a/builder/vmware/iso/step_verify_cache.go b/builder/vmware/iso/step_verify_cache.go index 7aefa128c..f6f7d8b0d 100644 --- a/builder/vmware/iso/step_verify_cache.go +++ b/builder/vmware/iso/step_verify_cache.go @@ -55,7 +55,7 @@ func (s *stepVerifyCache) Run(state multistep.StateBag) multistep.StepAction { ui.Message(remotePath) if esx5.verifyChecksum(s.download.ChecksumType, s.download.Checksum, remotePath) { - ui.Message("Remote cache verified, skipping download/upload step") + ui.Message("Remote cache verified, skipping download/upload steps") s.remoteUpload.Skip = true state.Put(s.download.ResultKey, remotePath) From be2afccb85b0d7ad020ef69bb6f6b5f10f1b5a6e Mon Sep 17 00:00:00 2001 From: bugbuilder Date: Fri, 10 Nov 2017 23:55:26 -0300 Subject: [PATCH 8/9] Revamped the process to verify remote cache. --- builder/vmware/iso/builder.go | 25 ++++---- builder/vmware/iso/step_remote_upload.go | 11 ++++ builder/vmware/iso/step_verify_cache.go | 72 ------------------------ 3 files changed, 21 insertions(+), 87 deletions(-) delete mode 100644 builder/vmware/iso/step_verify_cache.go diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 73a6a1c04..5fa15317f 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -225,8 +225,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe state.Put("hook", hook) state.Put("ui", ui) - stepVerifyCache := &stepVerifyCache{ - download: &common.StepDownload{ + steps := []multistep.Step{ + &vmwcommon.StepPrepareTools{ + RemoteType: b.config.RemoteType, + ToolsUploadFlavor: b.config.ToolsUploadFlavor, + }, + &common.StepDownload{ Checksum: b.config.ISOChecksum, ChecksumType: b.config.ISOChecksumType, Description: "ISO", @@ -235,18 +239,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe TargetPath: b.config.TargetPath, Url: b.config.ISOUrls, }, - remoteUpload: &stepRemoteUpload{ - Key: "iso_path", - Message: "Uploading ISO to remote machine...", - }, - } - - steps := []multistep.Step{ - &vmwcommon.StepPrepareTools{ - RemoteType: b.config.RemoteType, - ToolsUploadFlavor: b.config.ToolsUploadFlavor, - }, - stepVerifyCache, &vmwcommon.StepOutputDir{ Force: b.config.PackerForce, }, @@ -258,7 +250,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Key: "floppy_path", Message: "Uploading Floppy to remote machine...", }, - stepVerifyCache.remoteUpload, + &stepRemoteUpload{ + Key: "iso_path", + Message: "Uploading ISO to remote machine...", + }, &stepCreateDisk{}, &stepCreateVMX{}, &vmwcommon.StepConfigureVMX{ diff --git a/builder/vmware/iso/step_remote_upload.go b/builder/vmware/iso/step_remote_upload.go index 691ebcb84..6aa963055 100644 --- a/builder/vmware/iso/step_remote_upload.go +++ b/builder/vmware/iso/step_remote_upload.go @@ -41,6 +41,17 @@ func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction { checksum := config.ISOChecksum checksumType := config.ISOChecksumType + if esx5, ok := remote.(*ESX5Driver); ok { + remotePath := esx5.cachePath(path) + + if esx5.verifyChecksum(checksumType, checksum, remotePath) { + ui.Say("Remote cache was verified skipping remote upload...") + state.Put(s.Key, remotePath) + return multistep.ActionContinue + } + + } + ui.Say(s.Message) log.Printf("Remote uploading: %s", path) newPath, err := remote.UploadISO(path, checksum, checksumType) diff --git a/builder/vmware/iso/step_verify_cache.go b/builder/vmware/iso/step_verify_cache.go deleted file mode 100644 index f6f7d8b0d..000000000 --- a/builder/vmware/iso/step_verify_cache.go +++ /dev/null @@ -1,72 +0,0 @@ -package iso - -import ( - "crypto/sha1" - "encoding/hex" - "fmt" - neturl "net/url" - - vmwcommon "github.com/hashicorp/packer/builder/vmware/common" - "github.com/hashicorp/packer/common" - "github.com/hashicorp/packer/packer" - "github.com/mitchellh/multistep" - "runtime" -) - -type stepVerifyCache struct { - download *common.StepDownload - remoteUpload *stepRemoteUpload -} - -func (s *stepVerifyCache) Run(state multistep.StateBag) multistep.StepAction { - cache := state.Get("cache").(packer.Cache) - driver := state.Get("driver").(vmwcommon.Driver) - ui := state.Get("ui").(packer.Ui) - - if esx5, ok := driver.(*ESX5Driver); ok { - ui.Say("Verifying remote cache") - - for _, url := range s.download.Url { - targetPath := s.download.TargetPath - - if u, err := neturl.Parse(url); err == nil { - if u.Scheme == "file" { - - if u.Path != "" { - targetPath = u.Path - } else if u.Opaque != "" { - targetPath = u.Opaque - } - - if runtime.GOOS == "windows" && len(targetPath) > 0 && targetPath[0] == '/' { - targetPath = targetPath[1:] - } - } - } - - if targetPath == "" { - hash := sha1.Sum([]byte(url)) - cacheKey := fmt.Sprintf("%s.%s", hex.EncodeToString(hash[:]), s.download.Extension) - targetPath = cache.Lock(cacheKey) - cache.Unlock(cacheKey) - } - - remotePath := esx5.cachePath(targetPath) - ui.Message(remotePath) - - if esx5.verifyChecksum(s.download.ChecksumType, s.download.Checksum, remotePath) { - ui.Message("Remote cache verified, skipping download/upload steps") - - s.remoteUpload.Skip = true - state.Put(s.download.ResultKey, remotePath) - return multistep.ActionContinue - } - - ui.Message("Remote cache couldn't be verified") - } - } - - return s.download.Run(state) -} - -func (s *stepVerifyCache) Cleanup(multistep.StateBag) {} From f7b45312f115b588395b2d0da8a3e4eb2988b7a3 Mon Sep 17 00:00:00 2001 From: bugbuilder Date: Fri, 10 Nov 2017 23:58:24 -0300 Subject: [PATCH 9/9] Removing skip attribute --- builder/vmware/iso/step_remote_upload.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/builder/vmware/iso/step_remote_upload.go b/builder/vmware/iso/step_remote_upload.go index 6aa963055..a9f6ecc80 100644 --- a/builder/vmware/iso/step_remote_upload.go +++ b/builder/vmware/iso/step_remote_upload.go @@ -14,19 +14,12 @@ import ( type stepRemoteUpload struct { Key string Message string - - // Set this to true for skip - Skip bool } func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction { driver := state.Get("driver").(vmwcommon.Driver) ui := state.Get("ui").(packer.Ui) - if s.Skip { - return multistep.ActionContinue - } - remote, ok := driver.(RemoteDriver) if !ok { return multistep.ActionContinue