Refactoring drivers to embed drivers.DefaultDriver

Signed-off-by: Dave Henderson <dhenderson@gmail.com>
This commit is contained in:
Dave Henderson 2015-05-27 14:12:36 -04:00
parent 306aed635d
commit 3d002187fe
19 changed files with 196 additions and 612 deletions

View File

@ -29,7 +29,21 @@ func TestCmdInspectFormat(t *testing.T) {
assert.Equal(t, "\"none\"", actual) assert.Equal(t, "\"none\"", actual)
actual, _ = runInspectCommand(t, []string{"--format", "{{prettyjson .Driver}}", "test-a"}) actual, _ = runInspectCommand(t, []string{"--format", "{{prettyjson .Driver}}", "test-a"})
assert.Equal(t, "{\n \"IPAddress\": \"\",\n \"URL\": \"unix:///var/run/docker.sock\"\n}", actual) type ExpectedDriver struct {
CaCertPath string
IPAddress string
MachineName string
PrivateKeyPath string
SSHPort int
SSHUser string
SwarmDiscovery string
SwarmHost string
SwarmMaster bool
URL string
}
expected, err := json.MarshalIndent(&ExpectedDriver{MachineName: "test-a", URL: "unix:///var/run/docker.sock"}, "", " ")
assert.NoError(t, err)
assert.Equal(t, string(expected), actual)
} }
func runInspectCommand(t *testing.T, args []string) (string, *libmachine.Host) { func runInspectCommand(t *testing.T, args []string) (string, *libmachine.Host) {

View File

@ -38,7 +38,7 @@ level maintenance.
## Maintainer ## Maintainer
To be supported as an official driver, it will need to be maintained. There To be supported as an official driver, it will need to be maintained. There
can be multiple driver maintainers and they will be identified in the can be multiple driver maintainers and they will be identified in the
maintainers file. maintainers file.
# Provider Operations # Provider Operations
@ -102,21 +102,12 @@ operations such as `Create`, `Remove`, `Start`, `Stop` etc.
For details see the [Driver Interface](https://github.com/docker/machine/blob/master/drivers/drivers.go#L24). For details see the [Driver Interface](https://github.com/docker/machine/blob/master/drivers/drivers.go#L24).
To provide this functionality, most drivers use a struct similar to the following: To provide this functionality, you should embed the `drivers.BaseDriver` struct, similar to the following:
``` ```
type Driver struct { type Driver struct {
MachineName string *drivers.BaseDriver
IPAddress string DriverSpecificField string
SSHUser string
SSHPort int
CaCertPath string
PrivateKeyPath string
DriverKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
} }
``` ```
@ -142,7 +133,7 @@ func GetCreateFlags() []cli.Flag {
EnvVar: "DRIVERNAME_TOKEN", EnvVar: "DRIVERNAME_TOKEN",
Name: "drivername-token", Name: "drivername-token",
Usage: "Provider access token", Usage: "Provider access token",
}, },
cli.StringFlag{ cli.StringFlag{
EnvVar: "DRIVERNAME_IMAGE", EnvVar: "DRIVERNAME_IMAGE",

View File

@ -7,7 +7,6 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"net/url" "net/url"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -36,6 +35,7 @@ var (
) )
type Driver struct { type Driver struct {
*drivers.BaseDriver
Id string Id string
AccessKey string AccessKey string
SecretKey string SecretKey string
@ -43,14 +43,10 @@ type Driver struct {
Region string Region string
AMI string AMI string
SSHKeyID int SSHKeyID int
SSHUser string
SSHPort int
KeyName string KeyName string
InstanceId string InstanceId string
InstanceType string InstanceType string
IPAddress string
PrivateIPAddress string PrivateIPAddress string
MachineName string
SecurityGroupId string SecurityGroupId string
SecurityGroupName string SecurityGroupName string
ReservationId string ReservationId string
@ -59,12 +55,6 @@ type Driver struct {
VpcId string VpcId string
SubnetId string SubnetId string
Zone string Zone string
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
keyPath string keyPath string
RequestSpotInstance bool RequestSpotInstance bool
SpotPrice string SpotPrice string
@ -179,23 +169,13 @@ func GetCreateFlags() []cli.Flag {
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
id := generateId() id := generateId()
inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
return &Driver{ return &Driver{
Id: id, Id: id,
MachineName: machineName, BaseDriver: inner,
storePath: storePath,
CaCertPath: caCert,
PrivateKeyPath: privateKey,
}, nil }, nil
} }
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
region, err := validateAwsRegion(flags.String("amazonec2-region")) region, err := validateAwsRegion(flags.String("amazonec2-region"))
if err != nil { if err != nil {
@ -260,10 +240,6 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
return nil return nil
} }
func (d *Driver) GetMachineName() string {
return d.MachineName
}
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return driverName return driverName
} }
@ -464,19 +440,12 @@ func (d *Driver) GetState() (state.State, error) {
return state.None, nil return state.None, nil
} }
// GetSSHHostname -
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
// TODO: use @nathanleclaire retry func here (ehazlett) // TODO: use @nathanleclaire retry func here (ehazlett)
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string { func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" { if d.SSHUser == "" {
d.SSHUser = "ubuntu" d.SSHUser = "ubuntu"
@ -537,10 +506,6 @@ func (d *Driver) getClient() *amz.EC2 {
return amz.NewEC2(auth, d.Region) return amz.NewEC2(auth, d.Region)
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) getInstance() (*amz.EC2Instance, error) { func (d *Driver) getInstance() (*amz.EC2Instance, error) {
instance, err := d.getClient().GetInstance(d.InstanceId) instance, err := d.getClient().GetInstance(d.InstanceId)
if err != nil { if err != nil {

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"strings" "strings"
azure "github.com/MSOpenTech/azure-sdk-for-go" azure "github.com/MSOpenTech/azure-sdk-for-go"
@ -20,8 +19,7 @@ import (
) )
type Driver struct { type Driver struct {
IPAddress string *drivers.BaseDriver
MachineName string
SubscriptionID string SubscriptionID string
SubscriptionCert string SubscriptionCert string
PublishSettingsFilePath string PublishSettingsFilePath string
@ -29,15 +27,7 @@ type Driver struct {
Size string Size string
UserPassword string UserPassword string
Image string Image string
SSHUser string
SSHPort int
DockerPort int DockerPort int
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
} }
func init() { func init() {
@ -107,38 +97,15 @@ func GetCreateFlags() []cli.Flag {
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
d := &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey} inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
d := &Driver{BaseDriver: inner}
return d, nil return d, nil
} }
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
}
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string { func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" { if d.SSHUser == "" {
d.SSHUser = "ubuntu" d.SSHUser = "ubuntu"
@ -426,20 +393,16 @@ func (d *Driver) addDockerEndpoint(vmConfig *vmClient.Role) error {
} }
func (d *Driver) generateCertForAzure() error { func (d *Driver) generateCertForAzure() error {
if err := ssh.GenerateSSHKey(d.sshKeyPath()); err != nil { if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err return err
} }
cmd := exec.Command("openssl", "req", "-x509", "-key", d.sshKeyPath(), "-nodes", "-days", "365", "-newkey", "rsa:2048", "-out", d.azureCertPath(), "-subj", "/C=AU/ST=Some-State/O=InternetWidgitsPtyLtd/CN=\\*") cmd := exec.Command("openssl", "req", "-x509", "-key", d.GetSSHKeyPath(), "-nodes", "-days", "365", "-newkey", "rsa:2048", "-out", d.azureCertPath(), "-subj", "/C=AU/ST=Some-State/O=InternetWidgitsPtyLtd/CN=\\*")
return cmd.Run() return cmd.Run()
} }
func (d *Driver) sshKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) azureCertPath() string { func (d *Driver) azureCertPath() string {
return filepath.Join(d.storePath, "azure_cert.pem") return d.ResolveStorePath("azure_cert.pem")
} }
func (d *Driver) getHostname() string { func (d *Driver) getHostname() string {

76
drivers/base.go Normal file
View File

@ -0,0 +1,76 @@
package drivers
import "path/filepath"
// BaseDriver - Embed this struct into drivers to provide the common set
// of fields and functions.
type BaseDriver struct {
storePath string
IPAddress string
SSHUser string
SSHPort int
MachineName string
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
}
// NewBaseDriver - Get an instance of a BaseDriver
func NewBaseDriver(machineName string, storePath string, caCert string, privateKey string) *BaseDriver {
return &BaseDriver{
MachineName: machineName,
storePath: storePath,
CaCertPath: caCert,
PrivateKeyPath: privateKey,
}
}
// GetSSHKeyPath -
func (d *BaseDriver) GetSSHKeyPath() string {
return d.ResolveStorePath("id_rsa")
}
// ResolveStorePath -
func (d *BaseDriver) ResolveStorePath(path string) string {
return filepath.Join(d.storePath, path)
}
// AuthorizePort -
func (d *BaseDriver) AuthorizePort(ports []*Port) error {
return nil
}
// DeauthorizePort -
func (d *BaseDriver) DeauthorizePort(ports []*Port) error {
return nil
}
// DriverName - This must be implemented in every driver
func (d *BaseDriver) DriverName() string {
return "unknown"
}
// GetMachineName -
func (d *BaseDriver) GetMachineName() string {
return d.MachineName
}
// GetSSHPort -
func (d *BaseDriver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
// GetSSHUsername -
func (d *BaseDriver) GetSSHUsername() string {
if d.SSHUser == "" {
d.SSHUser = "root"
}
return d.SSHUser
}

View File

@ -3,7 +3,6 @@ package digitalocean
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"path/filepath"
"time" "time"
"code.google.com/p/goauth2/oauth" "code.google.com/p/goauth2/oauth"
@ -16,27 +15,17 @@ import (
) )
type Driver struct { type Driver struct {
*drivers.BaseDriver
AccessToken string AccessToken string
DropletID int DropletID int
DropletName string DropletName string
Image string Image string
MachineName string
IPAddress string
Region string Region string
SSHKeyID int SSHKeyID int
SSHUser string
SSHPort int
Size string Size string
IPv6 bool IPv6 bool
Backups bool Backups bool
PrivateNetworking bool PrivateNetworking bool
CaCertPath string
PrivateKeyPath string
DriverKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
} }
func init() { func init() {
@ -92,45 +81,14 @@ func GetCreateFlags() []cli.Flag {
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
} return &Driver{BaseDriver: inner}, nil
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
} }
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" {
d.SSHUser = "root"
}
return d.SSHUser
}
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "digitalocean" return "digitalocean"
} }
@ -229,7 +187,7 @@ func (d *Driver) Create() error {
} }
func (d *Driver) createSSHKey() (*godo.Key, error) { func (d *Driver) createSSHKey() (*godo.Key, error) {
if err := ssh.GenerateSSHKey(d.sshKeyPath()); err != nil { if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return nil, err return nil, err
} }
@ -329,10 +287,6 @@ func (d *Driver) getClient() *godo.Client {
return godo.NewClient(t.Client()) return godo.NewClient(t.Client())
} }
func (d *Driver) sshKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) publicSSHKeyPath() string { func (d *Driver) publicSSHKeyPath() string {
return d.sshKeyPath() + ".pub" return d.GetSSHKeyPath() + ".pub"
} }

View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"path/filepath"
"strings" "strings"
"text/template" "text/template"
"time" "time"
@ -18,6 +17,7 @@ import (
) )
type Driver struct { type Driver struct {
*drivers.BaseDriver
URL string URL string
ApiKey string ApiKey string
ApiSecretKey string ApiSecretKey string
@ -26,18 +26,9 @@ type Driver struct {
Image string Image string
SecurityGroup string SecurityGroup string
AvailabilityZone string AvailabilityZone string
MachineName string
KeyPair string KeyPair string
IPAddress string
PublicKey string PublicKey string
Id string Id string
CaCertPath string
PrivateKeyPath string
DriverKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
} }
func init() { func init() {
@ -100,33 +91,14 @@ func GetCreateFlags() []cli.Flag {
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
} return &Driver{BaseDriver: inner}, nil
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
} }
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
return 22, nil
}
func (d *Driver) GetSSHUsername() string { func (d *Driver) GetSSHUsername() string {
return "ubuntu" return "ubuntu"
} }

View File

@ -6,6 +6,7 @@ import (
) )
type FakeDriver struct { type FakeDriver struct {
*drivers.BaseDriver
MockState state.State MockState state.State
} }
@ -13,14 +14,6 @@ func (d *FakeDriver) DriverName() string {
return "fakedriver" return "fakedriver"
} }
func (d *FakeDriver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *FakeDriver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *FakeDriver) SetConfigFromFlags(flags drivers.DriverOptions) error { func (d *FakeDriver) SetConfigFromFlags(flags drivers.DriverOptions) error {
return nil return nil
} }

View File

@ -15,18 +15,8 @@ import (
) )
type Driver struct { type Driver struct {
MachineName string *drivers.BaseDriver
IPAddress string SSHKey string
SSHKey string
SSHUser string
SSHPort int
CaCertPath string
PrivateKeyPath string
DriverKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
} }
const ( const (
@ -68,46 +58,18 @@ func GetCreateFlags() []cli.Flag {
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{ inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
MachineName: machineName, return &Driver{BaseDriver: inner}, nil
storePath: storePath,
CaCertPath: caCert,
PrivateKeyPath: privateKey,
}, nil
} }
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "generic" return "generic"
} }
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
}
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string { func (d *Driver) GetSSHUsername() string {
return d.SSHUser return d.SSHUser
} }
@ -136,11 +98,11 @@ func (d *Driver) PreCreateCheck() error {
func (d *Driver) Create() error { func (d *Driver) Create() error {
log.Infof("Importing SSH key...") log.Infof("Importing SSH key...")
if err := utils.CopyFile(d.SSHKey, d.sshKeyPath()); err != nil { if err := utils.CopyFile(d.SSHKey, d.GetSSHKeyPath()); err != nil {
return fmt.Errorf("unable to copy ssh key: %s", err) return fmt.Errorf("unable to copy ssh key: %s", err)
} }
if err := os.Chmod(d.sshKeyPath(), 0600); err != nil { if err := os.Chmod(d.GetSSHKeyPath(), 0600); err != nil {
return err return err
} }
@ -208,10 +170,6 @@ func (d *Driver) Kill() error {
return nil return nil
} }
func (d *Driver) sshKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) publicSSHKeyPath() string { func (d *Driver) publicSSHKeyPath() string {
return d.sshKeyPath() + ".pub" return d.GetSSHKeyPath() + ".pub"
} }

View File

@ -40,7 +40,7 @@ const (
// NewComputeUtil creates and initializes a ComputeUtil. // NewComputeUtil creates and initializes a ComputeUtil.
func newComputeUtil(driver *Driver) (*ComputeUtil, error) { func newComputeUtil(driver *Driver) (*ComputeUtil, error) {
service, err := newGCEService(driver.storePath, driver.AuthTokenPath) service, err := newGCEService(driver.ResolveStorePath("."), driver.AuthTokenPath)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -2,7 +2,6 @@ package google
import ( import (
"fmt" "fmt"
"path/filepath"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/docker/machine/drivers" "github.com/docker/machine/drivers"
@ -13,23 +12,14 @@ import (
// Driver is a struct compatible with the docker.hosts.drivers.Driver interface. // Driver is a struct compatible with the docker.hosts.drivers.Driver interface.
type Driver struct { type Driver struct {
IPAddress string *drivers.BaseDriver
MachineName string Zone string
SSHUser string MachineType string
SSHPort int DiskType string
Zone string Scopes string
MachineType string DiskSize int
DiskType string AuthTokenPath string
Scopes string Project string
DiskSize int
AuthTokenPath string
storePath string
Project string
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
} }
func init() { func init() {
@ -94,42 +84,14 @@ func GetCreateFlags() []cli.Flag {
// NewDriver creates a Driver with the specified storePath. // NewDriver creates a Driver with the specified storePath.
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{ inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
MachineName: machineName, return &Driver{BaseDriver: inner}, nil
storePath: storePath,
CaCertPath: caCert,
PrivateKeyPath: privateKey,
}, nil
}
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
} }
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string { func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" { if d.SSHUser == "" {
d.SSHUser = "docker-user" d.SSHUser = "docker-user"

View File

@ -18,22 +18,13 @@ import (
) )
type Driver struct { type Driver struct {
IPAddress string *drivers.BaseDriver
SSHUser string
SSHPort int
storePath string
boot2DockerURL string boot2DockerURL string
boot2DockerLoc string boot2DockerLoc string
vSwitch string vSwitch string
MachineName string
diskImage string diskImage string
diskSize int diskSize int
memSize int memSize int
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
} }
func init() { func init() {
@ -87,37 +78,14 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
} return &Driver{BaseDriver: inner}, nil
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
} }
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string { func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" { if d.SSHUser == "" {
d.SSHUser = "docker" d.SSHUser = "docker"
@ -186,7 +154,7 @@ func (d *Driver) Create() error {
if d.boot2DockerURL != "" { if d.boot2DockerURL != "" {
isoURL = d.boot2DockerURL isoURL = d.boot2DockerURL
log.Infof("Downloading boot2docker.iso from %s...", isoURL) log.Infof("Downloading boot2docker.iso from %s...", isoURL)
if err := b2dutils.DownloadISO(d.storePath, "boot2docker.iso", isoURL); err != nil { if err := b2dutils.DownloadISO(d.ResolveStorePath("."), "boot2docker.iso", isoURL); err != nil {
return err return err
} }
} else { } else {
@ -217,14 +185,14 @@ func (d *Driver) Create() error {
} }
} }
isoDest := filepath.Join(d.storePath, "boot2docker.iso") isoDest := d.ResolveStorePath("boot2docker.iso")
if err := utils.CopyFile(commonIsoPath, isoDest); err != nil { if err := utils.CopyFile(commonIsoPath, isoDest); err != nil {
return err return err
} }
} }
} else { } else {
if err := utils.CopyFile(d.boot2DockerLoc, filepath.Join(d.storePath, "boot2docker.iso")); err != nil { if err := utils.CopyFile(d.boot2DockerLoc, d.ResolveStorePath("boot2docker.iso")); err != nil {
return err return err
} }
} }
@ -250,7 +218,7 @@ func (d *Driver) Create() error {
command := []string{ command := []string{
"New-VM", "New-VM",
"-Name", d.MachineName, "-Name", d.MachineName,
"-Path", fmt.Sprintf("'%s'", d.storePath), "-Path", fmt.Sprintf("'%s'", d.ResolveStorePath(".")),
"-MemoryStartupBytes", fmt.Sprintf("%dMB", d.memSize)} "-MemoryStartupBytes", fmt.Sprintf("%dMB", d.memSize)}
_, err = execute(command) _, err = execute(command)
if err != nil { if err != nil {
@ -260,7 +228,7 @@ func (d *Driver) Create() error {
command = []string{ command = []string{
"Set-VMDvdDrive", "Set-VMDvdDrive",
"-VMName", d.MachineName, "-VMName", d.MachineName,
"-Path", fmt.Sprintf("'%s'", filepath.Join(d.storePath, "boot2docker.iso"))} "-Path", fmt.Sprintf("'%s'", d.ResolveStorePath("boot2docker.iso"))}
_, err = execute(command) _, err = execute(command)
if err != nil { if err != nil {
return err return err
@ -444,8 +412,8 @@ func (d *Driver) generateDiskImage() error {
// Create a small fixed vhd, put the tar in, // Create a small fixed vhd, put the tar in,
// convert to dynamic, then resize // convert to dynamic, then resize
d.diskImage = filepath.Join(d.storePath, "disk.vhd") d.diskImage = d.ResolveStorePath("disk.vhd")
fixed := filepath.Join(d.storePath, "fixed.vhd") fixed := d.ResolveStorePath("fixed.vhd")
log.Infof("Creating VHD") log.Infof("Creating VHD")
command := []string{ command := []string{
"New-VHD", "New-VHD",

View File

@ -13,8 +13,8 @@ import (
// connect to existing Docker hosts by specifying the URL of the host as // connect to existing Docker hosts by specifying the URL of the host as
// an option. // an option.
type Driver struct { type Driver struct {
IPAddress string *drivers.BaseDriver
URL string URL string
} }
func init() { func init() {
@ -35,21 +35,14 @@ func GetCreateFlags() []cli.Flag {
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{}, nil inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
} return &Driver{inner, ""}, nil
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
} }
func (d *Driver) Create() error { func (d *Driver) Create() error {
return nil return nil
} }
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "none" return "none"
} }

View File

@ -3,7 +3,6 @@ package openstack
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"path/filepath"
"strings" "strings"
"time" "time"
@ -16,6 +15,7 @@ import (
) )
type Driver struct { type Driver struct {
*drivers.BaseDriver
AuthUrl string AuthUrl string
Insecure bool Insecure bool
DomainID string DomainID string
@ -27,7 +27,6 @@ type Driver struct {
Region string Region string
AvailabilityZone string AvailabilityZone string
EndpointType string EndpointType string
MachineName string
MachineId string MachineId string
FlavorName string FlavorName string
FlavorId string FlavorId string
@ -39,15 +38,6 @@ type Driver struct {
SecurityGroups []string SecurityGroups []string
FloatingIpPool string FloatingIpPool string
FloatingIpPoolId string FloatingIpPoolId string
SSHUser string
SSHPort int
IPAddress string
CaCertPath string
PrivateKeyPath string
storePath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
client Client client Client
} }
@ -189,51 +179,14 @@ func NewDriver(machineName string, storePath string, caCert string, privateKey s
} }
func NewDerivedDriver(machineName string, storePath string, client Client, caCert string, privateKey string) (*Driver, error) { func NewDerivedDriver(machineName string, storePath string, client Client, caCert string, privateKey string) (*Driver, error) {
return &Driver{ inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
MachineName: machineName, return &Driver{BaseDriver: inner, client: client}, nil
storePath: storePath,
client: client,
CaCertPath: caCert,
PrivateKeyPath: privateKey,
}, nil
}
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
} }
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" {
d.SSHUser = "root"
}
return d.SSHUser
}
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "openstack" return "openstack"
} }

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
"regexp" "regexp"
"time" "time"
@ -20,20 +19,11 @@ const (
) )
type Driver struct { type Driver struct {
storePath string *drivers.BaseDriver
IPAddress string deviceConfig *deviceConfig
deviceConfig *deviceConfig Id int
Id int Client *Client
Client *Client SSHKeyID int
SSHUser string
SSHPort int
MachineName string
CaCertPath string
PrivateKeyPath string
SSHKeyID int
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
} }
type deviceConfig struct { type deviceConfig struct {
@ -59,45 +49,14 @@ func init() {
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
} return &Driver{BaseDriver: inner}, nil
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
} }
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" {
d.SSHUser = "root"
}
return d.SSHUser
}
func GetCreateFlags() []cli.Flag { func GetCreateFlags() []cli.Flag {
// Set hourly billing to true by default since codegangsta cli doesn't take default bool values // Set hourly billing to true by default since codegangsta cli doesn't take default bool values
if os.Getenv("SOFTLAYER_HOURLY_BILLING") == "" { if os.Getenv("SOFTLAYER_HOURLY_BILLING") == "" {

View File

@ -36,20 +36,11 @@ var (
) )
type Driver struct { type Driver struct {
IPAddress string *drivers.BaseDriver
CPU int CPU int
MachineName string
SSHUser string
SSHPort int
Memory int Memory int
DiskSize int DiskSize int
Boot2DockerURL string Boot2DockerURL string
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
Boot2DockerImportVM string Boot2DockerImportVM string
HostOnlyCIDR string HostOnlyCIDR string
} }
@ -104,33 +95,14 @@ func GetCreateFlags() []cli.Flag {
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
} return &Driver{BaseDriver: inner}, nil
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
} }
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return "localhost", nil return "localhost", nil
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string { func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" { if d.SSHUser == "" {
d.SSHUser = "docker" d.SSHUser = "docker"
@ -237,7 +209,7 @@ func (d *Driver) Create() error {
} }
if err := vbm("createvm", if err := vbm("createvm",
"--basefolder", d.storePath, "--basefolder", d.ResolveStorePath("."),
"--name", d.MachineName, "--name", d.MachineName,
"--register"); err != nil { "--register"); err != nil {
return err return err
@ -304,7 +276,7 @@ func (d *Driver) Create() error {
"--port", "0", "--port", "0",
"--device", "0", "--device", "0",
"--type", "dvddrive", "--type", "dvddrive",
"--medium", filepath.Join(d.storePath, "boot2docker.iso")); err != nil { "--medium", d.ResolveStorePath("boot2docker.iso")); err != nil {
return err return err
} }
@ -553,7 +525,7 @@ func (d *Driver) publicSSHKeyPath() string {
} }
func (d *Driver) diskPath() string { func (d *Driver) diskPath() string {
return filepath.Join(d.storePath, "disk.vmdk") return d.ResolveStorePath("disk.vmdk")
} }
// Make a boot2docker VM disk image. // Make a boot2docker VM disk image.

View File

@ -9,8 +9,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath"
"regexp" "regexp"
"runtime" "runtime"
"strings" "strings"
@ -33,23 +31,13 @@ const (
// Driver for VMware Fusion // Driver for VMware Fusion
type Driver struct { type Driver struct {
MachineName string *drivers.BaseDriver
IPAddress string
Memory int Memory int
DiskSize int DiskSize int
CPU int CPU int
ISO string ISO string
Boot2DockerURL string Boot2DockerURL string
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
CPUS int CPUS int
SSHUser string
SSHPort int
storePath string
} }
func init() { func init() {
@ -90,37 +78,14 @@ func GetCreateFlags() []cli.Flag {
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
} return &Driver{BaseDriver: inner}, nil
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
} }
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string { func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" { if d.SSHUser == "" {
d.SSHUser = "docker" d.SSHUser = "docker"
@ -138,7 +103,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.CPU = flags.Int("vmwarefusion-cpu-count") d.CPU = flags.Int("vmwarefusion-cpu-count")
d.DiskSize = flags.Int("vmwarefusion-disk-size") d.DiskSize = flags.Int("vmwarefusion-disk-size")
d.Boot2DockerURL = flags.String("vmwarefusion-boot2docker-url") d.Boot2DockerURL = flags.String("vmwarefusion-boot2docker-url")
d.ISO = path.Join(d.storePath, isoFilename) d.ISO = d.ResolveStorePath(isoFilename)
d.SwarmMaster = flags.Bool("swarm-master") d.SwarmMaster = flags.Bool("swarm-master")
d.SwarmHost = flags.String("swarm-host") d.SwarmHost = flags.String("swarm-host")
d.SwarmDiscovery = flags.String("swarm-discovery") d.SwarmDiscovery = flags.String("swarm-discovery")
@ -207,7 +172,7 @@ func (d *Driver) Create() error {
} }
log.Infof("Creating VM...") log.Infof("Creating VM...")
if err := os.MkdirAll(d.storePath, 0755); err != nil { if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil {
return err return err
} }
@ -224,7 +189,7 @@ func (d *Driver) Create() error {
vmxt.Execute(vmxfile, d) vmxt.Execute(vmxfile, d)
// Generate vmdk file // Generate vmdk file
diskImg := filepath.Join(d.storePath, fmt.Sprintf("%s.vmdk", d.MachineName)) diskImg := d.ResolveStorePath(fmt.Sprintf("%s.vmdk", d.MachineName))
if _, err := os.Stat(diskImg); err != nil { if _, err := os.Stat(diskImg); err != nil {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
return err return err
@ -271,7 +236,7 @@ func (d *Driver) Create() error {
vmrun("-gu", B2DUser, "-gp", B2DPass, "directoryExistsInGuest", d.vmxPath(), "/var/lib/boot2docker") vmrun("-gu", B2DUser, "-gp", B2DPass, "directoryExistsInGuest", d.vmxPath(), "/var/lib/boot2docker")
// Copy SSH keys bundle // Copy SSH keys bundle
vmrun("-gu", B2DUser, "-gp", B2DPass, "CopyFileFromHostToGuest", d.vmxPath(), path.Join(d.storePath, "userdata.tar"), "/home/docker/userdata.tar") vmrun("-gu", B2DUser, "-gp", B2DPass, "CopyFileFromHostToGuest", d.vmxPath(), d.ResolveStorePath("userdata.tar"), "/home/docker/userdata.tar")
// Expand tar file. // Expand tar file.
vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", "sudo /bin/mv /home/docker/userdata.tar /var/lib/boot2docker/userdata.tar && sudo tar xf /var/lib/boot2docker/userdata.tar -C /home/docker/ > /var/log/userdata.log 2>&1 && sudo chown -R docker:staff /home/docker") vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", "sudo /bin/mv /home/docker/userdata.tar /var/lib/boot2docker/userdata.tar && sudo tar xf /var/lib/boot2docker/userdata.tar -C /home/docker/ > /var/log/userdata.log 2>&1 && sudo chown -R docker:staff /home/docker")
@ -360,11 +325,11 @@ func (d *Driver) Upgrade() error {
} }
func (d *Driver) vmxPath() string { func (d *Driver) vmxPath() string {
return path.Join(d.storePath, fmt.Sprintf("%s.vmx", d.MachineName)) return d.ResolveStorePath(fmt.Sprintf("%s.vmx", d.MachineName))
} }
func (d *Driver) vmdkPath() string { func (d *Driver) vmdkPath() string {
return path.Join(d.storePath, fmt.Sprintf("%s.vmdk", d.MachineName)) return d.ResolveStorePath(fmt.Sprintf("%s.vmdk", d.MachineName))
} }
func (d *Driver) getIPfromDHCPLease() (string, error) { func (d *Driver) getIPfromDHCPLease() (string, error) {
@ -459,7 +424,7 @@ func (d *Driver) generateKeyBundle() error {
magicString := "boot2docker, this is vmware speaking" magicString := "boot2docker, this is vmware speaking"
tf, err := os.Create(path.Join(d.storePath, "userdata.tar")) tf, err := os.Create(d.ResolveStorePath("userdata.tar"))
if err != nil { if err != nil {
return err return err
} }

View File

@ -7,7 +7,6 @@ package vmwarevcloudair
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"path/filepath"
"strings" "strings"
"github.com/vmware/govcloudair" "github.com/vmware/govcloudair"
@ -21,30 +20,21 @@ import (
) )
type Driver struct { type Driver struct {
IPAddress string *drivers.BaseDriver
UserName string UserName string
UserPassword string UserPassword string
ComputeID string ComputeID string
VDCID string VDCID string
OrgVDCNet string OrgVDCNet string
EdgeGateway string EdgeGateway string
PublicIP string PublicIP string
Catalog string Catalog string
CatalogItem string CatalogItem string
MachineName string DockerPort int
SSHUser string Provision bool
SSHPort int CPUCount int
DockerPort int MemorySize int
Provision bool VAppID string
CPUCount int
MemorySize int
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
VAppID string
storePath string
} }
func init() { func init() {
@ -141,46 +131,14 @@ func GetCreateFlags() []cli.Flag {
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
driver := &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey} inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
return driver, nil return &Driver{BaseDriver: inner}, nil
}
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
} }
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" {
d.SSHUser = "root"
}
return d.SSHUser
}
// Driver interface implementation // Driver interface implementation
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "vmwarevcloudair" return "vmwarevcloudair"

View File

@ -33,10 +33,7 @@ const (
) )
type Driver struct { type Driver struct {
IPAddress string *drivers.BaseDriver
MachineName string
SSHUser string
SSHPort int
CPU int CPU int
Memory int Memory int
DiskSize int DiskSize int
@ -49,13 +46,7 @@ type Driver struct {
Datacenter string Datacenter string
Pool string Pool string
HostIP string HostIP string
storePath string
ISO string ISO string
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
} }
func init() { func init() {
@ -136,37 +127,14 @@ func GetCreateFlags() []cli.Flag {
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
} return &Driver{BaseDriver: inner}, nil
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
} }
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string { func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" { if d.SSHUser == "" {
d.SSHUser = "docker" d.SSHUser = "docker"
@ -306,7 +274,7 @@ func (d *Driver) Create() error {
} }
// Copy SSH keys bundle // Copy SSH keys bundle
if err := vcConn.GuestUpload(B2DUser, B2DPass, path.Join(d.storePath, "userdata.tar"), "/home/docker/userdata.tar"); err != nil { if err := vcConn.GuestUpload(B2DUser, B2DPass, d.ResolveStorePath("userdata.tar"), "/home/docker/userdata.tar"); err != nil {
return err return err
} }
@ -454,7 +422,7 @@ func (d *Driver) generateKeyBundle() error {
magicString := "boot2docker, this is vmware speaking" magicString := "boot2docker, this is vmware speaking"
tf, err := os.Create(path.Join(d.storePath, "userdata.tar")) tf, err := os.Create(d.ResolveStorePath("userdata.tar"))
if err != nil { if err != nil {
return err return err
} }