Skip to content

Commit 6fe1c31

Browse files
author
Brett Higgins
committed
Revert driver API changes; build on generic opts
See docker-archive-public#3209 Signed-off-by: Brett Higgins <brhiggins@arbor.net>
1 parent 2011255 commit 6fe1c31

21 files changed

Lines changed: 74 additions & 134 deletions

File tree

cmd/machine.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ func main() {
158158
Usage: "BugSnag API token for crash reporting",
159159
Value: "",
160160
},
161+
cli.StringFlag{
162+
EnvVar: "MACHINE_SSH_CONFIG_FILE",
163+
Name: "ssh-config-file",
164+
Usage: "Use the specified SSH config file",
165+
Value: "",
166+
},
167+
cli.BoolFlag{
168+
EnvVar: "MACHINE_USE_USER_SSH_CONFIG",
169+
Name: "use-user-ssh-config",
170+
Usage: "Use the user's SSH config file (~/.ssh/config)",
171+
},
161172
}
162173

163174
if err := app.Run(os.Args); err != nil {

commands/commands.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"os"
7+
"path/filepath"
78
"strings"
89

910
"github.com/codegangsta/cli"
@@ -148,6 +149,7 @@ func runCommand(command func(commandLine CommandLine, api libmachine.API) error)
148149
libmachineOpts := &mcnopt.Options{
149150
BaseDir: context.GlobalString("storage-path"),
150151
GithubAPIToken: context.GlobalString("github-api-token"),
152+
SSHConfigFile: context.GlobalString("ssh-config-file"),
151153
}
152154

153155
if context.GlobalBool("native-ssh") {
@@ -156,6 +158,14 @@ func runCommand(command func(commandLine CommandLine, api libmachine.API) error)
156158
libmachineOpts.SSHClientType = ssh.External
157159
}
158160

161+
if context.GlobalBool("use-user-ssh-config") {
162+
if libmachineOpts.SSHConfigFile != "" {
163+
log.Error("--ssh-config-file not allowed with --use-user-ssh-config")
164+
osExit(1)
165+
}
166+
libmachineOpts.SSHConfigFile = filepath.Join(os.Getenv("HOME"), ".ssh", "config")
167+
}
168+
159169
mcnopt.SetOpts(libmachineOpts)
160170

161171
api.Filestore.Path = libmachineOpts.BaseDir

drivers/amazonec2/amazonec2.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -713,13 +713,6 @@ func (d *Driver) GetSSHUsername() string {
713713
return d.SSHUser
714714
}
715715

716-
func (d *Driver) GetSSHConfigFile() string {
717-
if d.SSHConfigFile == "" {
718-
d.SSHConfigFile = "/dev/null"
719-
}
720-
return d.SSHConfigFile
721-
}
722-
723716
func (d *Driver) Start() error {
724717
_, err := d.getClient().StartInstances(&ec2.StartInstancesInput{
725718
InstanceIds: []*string{&d.InstanceId},

drivers/errdriver/error.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ func (d *Driver) GetSSHUsername() string {
7171
return ""
7272
}
7373

74-
func (d *Driver) GetSSHConfigFile() string {
75-
return "/dev/null"
76-
}
77-
7874
func (d *Driver) GetState() (state.State, error) {
7975
return state.Error, NotLoadable{d.Name}
8076
}

drivers/exoscale/exoscale.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ func (d *Driver) GetSSHUsername() string {
128128
return d.SSHUser
129129
}
130130

131-
func (d *Driver) GetSSHConfigFile() string {
132-
if d.SSHConfigFile == "" {
133-
d.SSHConfigFile = "/dev/null"
134-
}
135-
return d.SSHConfigFile
136-
}
137-
138131
// DriverName returns the name of the driver
139132
func (d *Driver) DriverName() string {
140133
return "exoscale"

drivers/fakedriver/fakedriver.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ func (d *Driver) GetSSHUsername() string {
7272
return ""
7373
}
7474

75-
func (d *Driver) GetSSHConfigFile() string {
76-
return "/dev/null"
77-
}
78-
7975
func (d *Driver) GetState() (state.State, error) {
8076
return d.MockState, nil
8177
}

drivers/generic/generic.go

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
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

2121
type Driver struct {
2222
*drivers.BaseDriver
23-
EnginePort int
24-
SSHKey string
23+
EnginePort int
24+
SSHKey string
25+
SSHConfigFile string
2526
}
2627

2728
const (
@@ -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-
109103
func (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+
188179
func (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

205196
func (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

drivers/google/google.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,6 @@ func (d *Driver) GetSSHUsername() string {
155155
return d.SSHUser
156156
}
157157

158-
func (d *Driver) GetSSHConfigFile() string {
159-
if d.SSHConfigFile == "" {
160-
d.SSHConfigFile = "/dev/null"
161-
}
162-
return d.SSHConfigFile
163-
}
164-
165158
// DriverName returns the name of the driver
166159
func (d *Driver) DriverName() string {
167160
return "google"

drivers/none/driver.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ func (d *Driver) GetSSHUsername() string {
6767
return ""
6868
}
6969

70-
func (d *Driver) GetSSHConfigFile() string {
71-
return "/dev/null"
72-
}
73-
7470
func (d *Driver) GetURL() (string, error) {
7571
return d.URL, nil
7672
}

drivers/virtualbox/virtualbox.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,6 @@ func (d *Driver) GetSSHUsername() string {
188188
return d.SSHUser
189189
}
190190

191-
func (d *Driver) GetSSHConfigFile() string {
192-
if d.SSHConfigFile == "" {
193-
d.SSHConfigFile = "/dev/null"
194-
}
195-
return d.SSHConfigFile
196-
}
197-
198191
// DriverName returns the name of the driver
199192
func (d *Driver) DriverName() string {
200193
return "virtualbox"

0 commit comments

Comments
 (0)