file upload trough specific host

By default a host is selected randomly. Used account may have read-only but no upload permissions there.
This commit is contained in:
Michael Kuzmin 2018-11-13 20:22:19 +03:00
parent 4f952613d7
commit e1cdd04f4f
2 changed files with 8 additions and 3 deletions

View File

@ -81,9 +81,14 @@ func (ds *Datastore) ResolvePath(path string) string {
return ds.ds.Path(path) 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 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 { func (ds *Datastore) Delete(path string) error {

View File

@ -40,7 +40,7 @@ func (s *StepAddFloppy) Run(_ context.Context, state multistep.StateBag) multist
} }
uploadPath := fmt.Sprintf("%v/packer-tmp-created-floppy.flp", vmDir) 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) state.Put("error", err)
return multistep.ActionHalt return multistep.ActionHalt
} }