forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step_remote_upload.go
51 lines (42 loc) · 1.21 KB
/
step_remote_upload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package iso
import (
"fmt"
"github.com/mitchellh/multistep"
vmwcommon "github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/packer"
"log"
)
// 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
}
func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(vmwcommon.Driver)
ui := state.Get("ui").(packer.Ui)
remote, ok := driver.(RemoteDriver)
if !ok {
return multistep.ActionContinue
}
path, ok := state.Get(s.Key).(string)
if !ok {
return multistep.ActionContinue
}
config := state.Get("config").(*Config)
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
}
state.Put(s.Key, newPath)
return multistep.ActionContinue
}
func (s *stepRemoteUpload) Cleanup(state multistep.StateBag) {
}