/
step_provision.go
68 lines (53 loc) · 1.53 KB
/
step_provision.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package vultr
import (
"context"
"errors"
"io"
"os"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"golang.org/x/crypto/ssh"
)
type stepProvision struct{}
func (s *stepProvision) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
comm := state.Get("communicator").(packer.Communicator)
hook := state.Get("hook").(packer.Hook)
ui.Say("Provisioning...")
hook.Run(ctx, packer.HookProvision, ui, comm, nil)
return multistep.ActionContinue
}
func (s *stepProvision) Cleanup(state multistep.StateBag) {}
type sshCommunicator struct {
output *uiWriter
client *ssh.Client
}
func (c *sshCommunicator) Start(cmd *packer.RemoteCmd) error {
c.output.ui.Message("Running command: " + cmd.Command)
session, err := c.client.NewSession()
if err != nil {
return errors.New("failed to start new SSH session: " + err.Error())
}
session.Stdout = c.output
session.Stderr = c.output
return session.Run(cmd.Command)
}
func (c *sshCommunicator) Upload(string, io.Reader, *os.FileInfo) error {
panic("not implemented")
}
func (c *sshCommunicator) UploadDir(dst, src string, exclude []string) error {
panic("not implemented")
}
func (c *sshCommunicator) Download(string, io.Writer) error {
panic("not implemented")
}
func (c *sshCommunicator) DownloadDir(src, dst string, exclude []string) error {
panic("not implemented")
}
type uiWriter struct {
ui packer.Ui
}
func (w uiWriter) Write(b []byte) (int, error) {
w.ui.Message(string(b))
return len(b), nil
}