Making visible verify cache step
This commit is contained in:
parent
d4e0847a74
commit
b50e279d8a
|
@ -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{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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) {}
|
Loading…
Reference in New Issue