66 "net"
77 "os"
88 "path"
9- "path/filepath"
109 "strconv"
1110 "time"
1211
@@ -15,13 +14,15 @@ import (
1514 "github.com/docker/machine/libmachine/log"
1615 "github.com/docker/machine/libmachine/mcnflag"
1716 "github.com/docker/machine/libmachine/mcnutils"
17+ "github.com/docker/machine/libmachine/ssh"
1818 "github.com/docker/machine/libmachine/state"
1919)
2020
2121type Driver struct {
2222 * drivers.BaseDriver
23- EnginePort int
24- SSHKey string
23+ EnginePort int
24+ SSHKey string
25+ SSHConfigFile string
2526}
2627
2728const (
@@ -99,13 +100,6 @@ func (d *Driver) GetSSHUsername() string {
99100 return d .SSHUser
100101}
101102
102- func (d * Driver ) GetSSHConfigFile () string {
103- if d .SSHConfigFile == "" {
104- d .SSHConfigFile = "/dev/null"
105- }
106- return d .SSHConfigFile
107- }
108-
109103func (d * Driver ) GetSSHKeyPath () string {
110104 return d .SSHKeyPath
111105}
@@ -121,16 +115,6 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
121115 return errors .New ("generic driver requires the --generic-ip-address option" )
122116 }
123117
124- if flags .Bool ("generic-use-user-ssh-config" ) {
125- if d .SSHConfigFile != "" {
126- return errors .New ("--generic-ssh-config-file not allowed with --generic-use-user-ssh-config" )
127- }
128-
129- d .SSHConfigFile = filepath .Join (os .Getenv ("HOME" ), ".ssh" , "config" )
130- } else {
131- d .SSHConfigFile = flags .String ("generic-ssh-config-file" )
132- }
133-
134118 return nil
135119}
136120
@@ -185,8 +169,15 @@ func (d *Driver) GetURL() (string, error) {
185169 return fmt .Sprintf ("tcp://%s" , net .JoinHostPort (ip , strconv .Itoa (d .EnginePort ))), nil
186170}
187171
172+ func (d * Driver ) runSSHCommand (command string ) (string , error ) {
173+ options := & ssh.Options {
174+ ConfigFile : d .SSHConfigFile ,
175+ }
176+ return drivers .RunSSHCommandFromDriverWithOptions (d , command , options )
177+ }
178+
188179func (d * Driver ) GetState () (state.State , error ) {
189- _ , err := drivers . RunSSHCommandFromDriver ( d , "/bin/true" )
180+ _ , err := d . runSSHCommand ( "/bin/true" )
190181 if err != nil {
191182 return state .Stopped , nil
192183 }
@@ -203,7 +194,7 @@ func (d *Driver) Stop() error {
203194}
204195
205196func (d * Driver ) Restart () error {
206- _ , err := drivers . RunSSHCommandFromDriver ( d , "sudo shutdown -r now" )
197+ _ , err := d . runSSHCommand ( "sudo shutdown -r now" )
207198 return err
208199}
209200
0 commit comments