From e1cdd04f4f19a82b89bc6fe881261dc2c3197921 Mon Sep 17 00:00:00 2001 From: Michael Kuzmin Date: Tue, 13 Nov 2018 20:22:19 +0300 Subject: [PATCH] file upload trough specific host By default a host is selected randomly. Used account may have read-only but no upload permissions there. --- driver/datastore.go | 9 +++++++-- iso/step_add_floppy.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/driver/datastore.go b/driver/datastore.go index 36f976fcd..7f4b3b1dc 100644 --- a/driver/datastore.go +++ b/driver/datastore.go @@ -81,9 +81,14 @@ func (ds *Datastore) ResolvePath(path string) string { return ds.ds.Path(path) } -func (ds *Datastore) UploadFile(src, dst string) error { +func (ds *Datastore) UploadFile(src, dst string, host string) error { p := soap.DefaultUpload - return ds.ds.UploadFile(ds.driver.ctx, src, dst, &p) + h, err := ds.driver.FindHost(host) + if err != nil { + return err + } + ctx := ds.ds.HostContext(ds.driver.ctx, h.host) + return ds.ds.UploadFile(ctx, src, dst, &p) } func (ds *Datastore) Delete(path string) error { diff --git a/iso/step_add_floppy.go b/iso/step_add_floppy.go index 5c67631a9..fd9f9ac27 100644 --- a/iso/step_add_floppy.go +++ b/iso/step_add_floppy.go @@ -40,7 +40,7 @@ func (s *StepAddFloppy) Run(_ context.Context, state multistep.StateBag) multist } uploadPath := fmt.Sprintf("%v/packer-tmp-created-floppy.flp", vmDir) - if err := ds.UploadFile(floppyPath.(string), uploadPath); err != nil { + if err := ds.UploadFile(floppyPath.(string), uploadPath, s.Host); err != nil { state.Put("error", err) return multistep.ActionHalt }