Skip to content

Commit 72f0550

Browse files
committed
vmwarevsphere: update with new driver interface
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
1 parent 9e27af6 commit 72f0550

File tree

2 files changed

+38
-64
lines changed

2 files changed

+38
-64
lines changed

commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
_ "github.com/docker/machine/drivers/virtualbox"
2828
_ "github.com/docker/machine/drivers/vmwarefusion"
2929
_ "github.com/docker/machine/drivers/vmwarevcloudair"
30-
//_ "github.com/docker/machine/drivers/vmwarevsphere"
30+
_ "github.com/docker/machine/drivers/vmwarevsphere"
3131
"github.com/docker/machine/state"
3232
"github.com/docker/machine/utils"
3333
)

drivers/vmwarevsphere/vsphere.go

Lines changed: 37 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"io/ioutil"
1212
"net/http"
1313
"os"
14-
"os/exec"
1514
"path"
1615
"path/filepath"
1716
"strings"
@@ -22,10 +21,10 @@ import (
2221
"github.com/codegangsta/cli"
2322
"github.com/docker/machine/drivers"
2423
"github.com/docker/machine/drivers/vmwarevsphere/errors"
24+
"github.com/docker/machine/provider"
2525
"github.com/docker/machine/ssh"
2626
"github.com/docker/machine/state"
2727
"github.com/docker/machine/utils"
28-
// cssh "golang.org/x/crypto/ssh"
2928
)
3029

3130
const (
@@ -40,6 +39,7 @@ const (
4039

4140
type Driver struct {
4241
MachineName string
42+
SSHUser string
4343
SSHPort int
4444
CPU int
4545
Memory int
@@ -160,11 +160,44 @@ func NewDriver(machineName string, storePath string, caCert string, privateKey s
160160
return &Driver{MachineName: machineName, StorePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil
161161
}
162162

163+
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
164+
return nil
165+
}
166+
167+
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
168+
return nil
169+
}
170+
171+
func (d *Driver) GetMachineName() string {
172+
return d.MachineName
173+
}
174+
175+
func (d *Driver) GetSSHHostname() (string, error) {
176+
return d.GetIP()
177+
}
178+
179+
func (d *Driver) GetSSHKeyPath() string {
180+
return filepath.Join(d.storePath, "id_rsa")
181+
}
182+
183+
func (d *Driver) GetSSHPort() (int, error) {
184+
return d.SSHPort, nil
185+
}
186+
187+
func (d *Driver) GetSSHUsername() string {
188+
return d.SSHUser
189+
}
190+
191+
func (d *Driver) GetProviderType() provider.ProviderType {
192+
return provider.Local
193+
}
194+
163195
func (d *Driver) DriverName() string {
164196
return "vmwarevsphere"
165197
}
166198

167199
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
200+
d.SSHUser = "docker"
168201
d.SSHPort = 22
169202
d.CPU = flags.Int("vmwarevsphere-cpu-count")
170203
d.Memory = flags.Int("vmwarevsphere-memory-size")
@@ -243,7 +276,6 @@ func (d *Driver) Create() error {
243276

244277
var (
245278
isoURL string
246-
err error
247279
)
248280

249281
b2dutils := utils.NewB2dUtils("", "")
@@ -305,7 +337,7 @@ func (d *Driver) Create() error {
305337
}
306338

307339
log.Infof("Generating SSH Keypair...")
308-
if err := ssh.GenerateSSHKey(d.sshKeyPath()); err != nil {
340+
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
309341
return err
310342
}
311343

@@ -357,20 +389,6 @@ func (d *Driver) Create() error {
357389
return err
358390
}
359391

360-
log.Debugf("Setting hostname: %s", d.MachineName)
361-
cmd, err := d.GetSSHCommand(fmt.Sprintf(
362-
"echo \"127.0.0.1 %s\" | sudo tee -a /etc/hosts && sudo hostname %s && echo \"%s\" | sudo tee /etc/hostname",
363-
d.MachineName,
364-
d.MachineName,
365-
d.MachineName,
366-
))
367-
if err != nil {
368-
return err
369-
}
370-
if err := cmd.Run(); err != nil {
371-
return err
372-
}
373-
374392
return nil
375393
}
376394

@@ -469,56 +487,12 @@ func (d *Driver) Kill() error {
469487
return nil
470488
}
471489

472-
func (d *Driver) StartDocker() error {
473-
log.Debug("Starting Docker...")
474-
475-
cmd, err := d.GetSSHCommand("sudo /etc/init.d/docker start")
476-
if err != nil {
477-
return err
478-
}
479-
if err := cmd.Run(); err != nil {
480-
return err
481-
}
482-
483-
return nil
484-
}
485-
486-
func (d *Driver) StopDocker() error {
487-
log.Debug("Stopping Docker...")
488-
489-
cmd, err := d.GetSSHCommand("sudo /etc/init.d/docker stop")
490-
if err != nil {
491-
return err
492-
}
493-
if err := cmd.Run(); err != nil {
494-
return err
495-
}
496-
497-
return nil
498-
}
499-
500-
func (d *Driver) GetDockerConfigDir() string {
501-
return dockerConfigDir
502-
}
503-
504490
func (d *Driver) Upgrade() error {
505491
return fmt.Errorf("upgrade is not supported for vsphere driver at this moment")
506492
}
507493

508-
func (d *Driver) GetSSHCommand(args ...string) (*exec.Cmd, error) {
509-
ip, err := d.GetIP()
510-
if err != nil {
511-
return nil, err
512-
}
513-
return ssh.GetSSHCommand(ip, d.SSHPort, "docker", d.sshKeyPath(), args...), nil
514-
}
515-
516-
func (d *Driver) sshKeyPath() string {
517-
return path.Join(d.storePath, "id_rsa")
518-
}
519-
520494
func (d *Driver) publicSSHKeyPath() string {
521-
return d.sshKeyPath() + ".pub"
495+
return d.GetSSHKeyPath() + ".pub"
522496
}
523497

524498
func (d *Driver) checkVsphereConfig() error {

0 commit comments

Comments
 (0)