packer-cn/builder/googlecompute/tunnel_driver_windows.go

42 lines
889 B
Go
Raw Normal View History

// +build windows
package googlecompute
import (
2020-04-22 17:09:19 -04:00
"context"
"log"
"os/exec"
)
func NewTunnelDriver() TunnelDriver {
return &TunnelDriverWindows{}
}
2020-04-22 17:05:38 -04:00
type TunnelDriverWindows struct {
cmd *exec.Cmd
}
2020-07-07 18:37:45 -04:00
func (t *TunnelDriverWindows) StartTunnel(cancelCtx context.Context, tempScriptFileName string, timeout int) error {
2020-04-29 15:13:22 -04:00
args := []string{"/C", "call", tempScriptFileName}
cmd := exec.CommandContext(cancelCtx, "cmd", args...)
2020-07-07 18:37:45 -04:00
err := RunTunnelCommand(cmd, timeout)
if err != nil {
return err
}
// Store successful command on step so we can access it to cancel it
// later.
t.cmd = cmd
return nil
}
func (t *TunnelDriverWindows) StopTunnel() {
if t.cmd != nil && t.cmd.Process != nil {
err := t.cmd.Process.Kill()
if err != nil {
log.Printf("Issue stopping IAP tunnel: %s", err)
}
} else {
log.Printf("Couldn't find IAP tunnel process to kill. Continuing.")
}
}