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)
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) {

View File

@ -38,7 +38,7 @@ level maintenance.
## Maintainer
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.
# 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).
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 {
MachineName string
IPAddress string
SSHUser string
SSHPort int
CaCertPath string
PrivateKeyPath string
DriverKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
*drivers.BaseDriver
DriverSpecificField string
}
```
@ -142,7 +133,7 @@ func GetCreateFlags() []cli.Flag {
EnvVar: "DRIVERNAME_TOKEN",
Name: "drivername-token",
Usage: "Provider access token",
},
cli.StringFlag{
EnvVar: "DRIVERNAME_IMAGE",

View File

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

View File

@ -5,7 +5,6 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
azure "github.com/MSOpenTech/azure-sdk-for-go"
@ -20,8 +19,7 @@ import (
)
type Driver struct {
IPAddress string
MachineName string
*drivers.BaseDriver
SubscriptionID string
SubscriptionCert string
PublishSettingsFilePath string
@ -29,15 +27,7 @@ type Driver struct {
Size string
UserPassword string
Image string
SSHUser string
SSHPort int
DockerPort int
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
}
func init() {
@ -107,38 +97,15 @@ func GetCreateFlags() []cli.Flag {
}
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
}
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) {
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 = "ubuntu"
@ -426,20 +393,16 @@ func (d *Driver) addDockerEndpoint(vmConfig *vmClient.Role) error {
}
func (d *Driver) generateCertForAzure() error {
if err := ssh.GenerateSSHKey(d.sshKeyPath()); err != nil {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
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()
}
func (d *Driver) sshKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) azureCertPath() string {
return filepath.Join(d.storePath, "azure_cert.pem")
return d.ResolveStorePath("azure_cert.pem")
}
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 (
"fmt"
"io/ioutil"
"path/filepath"
"time"
"code.google.com/p/goauth2/oauth"
@ -16,27 +15,17 @@ import (
)
type Driver struct {
*drivers.BaseDriver
AccessToken string
DropletID int
DropletName string
Image string
MachineName string
IPAddress string
Region string
SSHKeyID int
SSHUser string
SSHPort int
Size string
IPv6 bool
Backups bool
PrivateNetworking bool
CaCertPath string
PrivateKeyPath string
DriverKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
}
func init() {
@ -92,45 +81,14 @@ func GetCreateFlags() []cli.Flag {
}
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{MachineName: machineName, 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
inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
return &Driver{BaseDriver: inner}, nil
}
func (d *Driver) GetSSHHostname() (string, error) {
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 {
return "digitalocean"
}
@ -229,7 +187,7 @@ func (d *Driver) Create() 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
}
@ -329,10 +287,6 @@ func (d *Driver) getClient() *godo.Client {
return godo.NewClient(t.Client())
}
func (d *Driver) sshKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) publicSSHKeyPath() string {
return d.sshKeyPath() + ".pub"
return d.GetSSHKeyPath() + ".pub"
}

View File

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

View File

@ -6,6 +6,7 @@ import (
)
type FakeDriver struct {
*drivers.BaseDriver
MockState state.State
}
@ -13,14 +14,6 @@ func (d *FakeDriver) DriverName() string {
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 {
return nil
}

View File

@ -15,18 +15,8 @@ import (
)
type Driver struct {
MachineName string
IPAddress string
SSHKey string
SSHUser string
SSHPort int
CaCertPath string
PrivateKeyPath string
DriverKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
*drivers.BaseDriver
SSHKey string
}
const (
@ -68,46 +58,18 @@ func GetCreateFlags() []cli.Flag {
}
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) DriverName() string {
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) {
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 {
return d.SSHUser
}
@ -136,11 +98,11 @@ func (d *Driver) PreCreateCheck() error {
func (d *Driver) Create() error {
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)
}
if err := os.Chmod(d.sshKeyPath(), 0600); err != nil {
if err := os.Chmod(d.GetSSHKeyPath(), 0600); err != nil {
return err
}
@ -208,10 +170,6 @@ func (d *Driver) Kill() error {
return nil
}
func (d *Driver) sshKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
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.
func newComputeUtil(driver *Driver) (*ComputeUtil, error) {
service, err := newGCEService(driver.storePath, driver.AuthTokenPath)
service, err := newGCEService(driver.ResolveStorePath("."), driver.AuthTokenPath)
if err != nil {
return nil, err
}

View File

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

View File

@ -18,22 +18,13 @@ import (
)
type Driver struct {
IPAddress string
SSHUser string
SSHPort int
storePath string
*drivers.BaseDriver
boot2DockerURL string
boot2DockerLoc string
vSwitch string
MachineName string
diskImage string
diskSize int
memSize int
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
}
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) {
return &Driver{MachineName: machineName, 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
inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
return &Driver{BaseDriver: inner}, nil
}
func (d *Driver) GetSSHHostname() (string, error) {
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 = "docker"
@ -186,7 +154,7 @@ func (d *Driver) Create() error {
if d.boot2DockerURL != "" {
isoURL = d.boot2DockerURL
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
}
} 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 {
return err
}
}
} 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
}
}
@ -250,7 +218,7 @@ func (d *Driver) Create() error {
command := []string{
"New-VM",
"-Name", d.MachineName,
"-Path", fmt.Sprintf("'%s'", d.storePath),
"-Path", fmt.Sprintf("'%s'", d.ResolveStorePath(".")),
"-MemoryStartupBytes", fmt.Sprintf("%dMB", d.memSize)}
_, err = execute(command)
if err != nil {
@ -260,7 +228,7 @@ func (d *Driver) Create() error {
command = []string{
"Set-VMDvdDrive",
"-VMName", d.MachineName,
"-Path", fmt.Sprintf("'%s'", filepath.Join(d.storePath, "boot2docker.iso"))}
"-Path", fmt.Sprintf("'%s'", d.ResolveStorePath("boot2docker.iso"))}
_, err = execute(command)
if err != nil {
return err
@ -444,8 +412,8 @@ func (d *Driver) generateDiskImage() error {
// Create a small fixed vhd, put the tar in,
// convert to dynamic, then resize
d.diskImage = filepath.Join(d.storePath, "disk.vhd")
fixed := filepath.Join(d.storePath, "fixed.vhd")
d.diskImage = d.ResolveStorePath("disk.vhd")
fixed := d.ResolveStorePath("fixed.vhd")
log.Infof("Creating VHD")
command := []string{
"New-VHD",

View File

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

View File

@ -3,7 +3,6 @@ package openstack
import (
"fmt"
"io/ioutil"
"path/filepath"
"strings"
"time"
@ -16,6 +15,7 @@ import (
)
type Driver struct {
*drivers.BaseDriver
AuthUrl string
Insecure bool
DomainID string
@ -27,7 +27,6 @@ type Driver struct {
Region string
AvailabilityZone string
EndpointType string
MachineName string
MachineId string
FlavorName string
FlavorId string
@ -39,15 +38,6 @@ type Driver struct {
SecurityGroups []string
FloatingIpPool string
FloatingIpPoolId string
SSHUser string
SSHPort int
IPAddress string
CaCertPath string
PrivateKeyPath string
storePath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
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) {
return &Driver{
MachineName: machineName,
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
inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
return &Driver{BaseDriver: inner, client: client}, nil
}
func (d *Driver) GetSSHHostname() (string, error) {
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 {
return "openstack"
}

View File

@ -4,7 +4,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"time"
@ -20,20 +19,11 @@ const (
)
type Driver struct {
storePath string
IPAddress string
deviceConfig *deviceConfig
Id int
Client *Client
SSHUser string
SSHPort int
MachineName string
CaCertPath string
PrivateKeyPath string
SSHKeyID int
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
*drivers.BaseDriver
deviceConfig *deviceConfig
Id int
Client *Client
SSHKeyID int
}
type deviceConfig struct {
@ -59,45 +49,14 @@ func init() {
}
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{MachineName: machineName, 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
inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
return &Driver{BaseDriver: inner}, nil
}
func (d *Driver) GetSSHHostname() (string, error) {
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 {
// Set hourly billing to true by default since codegangsta cli doesn't take default bool values
if os.Getenv("SOFTLAYER_HOURLY_BILLING") == "" {

View File

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

View File

@ -9,8 +9,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
"runtime"
"strings"
@ -33,23 +31,13 @@ const (
// Driver for VMware Fusion
type Driver struct {
MachineName string
IPAddress string
*drivers.BaseDriver
Memory int
DiskSize int
CPU int
ISO string
Boot2DockerURL string
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
CPUS int
SSHUser string
SSHPort int
storePath string
}
func init() {
@ -90,37 +78,14 @@ func GetCreateFlags() []cli.Flag {
}
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{MachineName: machineName, 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
inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
return &Driver{BaseDriver: inner}, nil
}
func (d *Driver) GetSSHHostname() (string, error) {
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 = "docker"
@ -138,7 +103,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.CPU = flags.Int("vmwarefusion-cpu-count")
d.DiskSize = flags.Int("vmwarefusion-disk-size")
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.SwarmHost = flags.String("swarm-host")
d.SwarmDiscovery = flags.String("swarm-discovery")
@ -207,7 +172,7 @@ func (d *Driver) Create() error {
}
log.Infof("Creating VM...")
if err := os.MkdirAll(d.storePath, 0755); err != nil {
if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil {
return err
}
@ -224,7 +189,7 @@ func (d *Driver) Create() error {
vmxt.Execute(vmxfile, d)
// 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 !os.IsNotExist(err) {
return err
@ -271,7 +236,7 @@ func (d *Driver) Create() error {
vmrun("-gu", B2DUser, "-gp", B2DPass, "directoryExistsInGuest", d.vmxPath(), "/var/lib/boot2docker")
// 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.
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 {
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 {
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) {
@ -459,7 +424,7 @@ func (d *Driver) generateKeyBundle() error {
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 {
return err
}

View File

@ -7,7 +7,6 @@ package vmwarevcloudair
import (
"fmt"
"io/ioutil"
"path/filepath"
"strings"
"github.com/vmware/govcloudair"
@ -21,30 +20,21 @@ import (
)
type Driver struct {
IPAddress string
UserName string
UserPassword string
ComputeID string
VDCID string
OrgVDCNet string
EdgeGateway string
PublicIP string
Catalog string
CatalogItem string
MachineName string
SSHUser string
SSHPort int
DockerPort int
Provision bool
CPUCount int
MemorySize int
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
VAppID string
storePath string
*drivers.BaseDriver
UserName string
UserPassword string
ComputeID string
VDCID string
OrgVDCNet string
EdgeGateway string
PublicIP string
Catalog string
CatalogItem string
DockerPort int
Provision bool
CPUCount int
MemorySize int
VAppID string
}
func init() {
@ -141,46 +131,14 @@ func GetCreateFlags() []cli.Flag {
}
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
driver := &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}
return driver, 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
inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
return &Driver{BaseDriver: inner}, nil
}
func (d *Driver) GetSSHHostname() (string, error) {
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
func (d *Driver) DriverName() string {
return "vmwarevcloudair"

View File

@ -33,10 +33,7 @@ const (
)
type Driver struct {
IPAddress string
MachineName string
SSHUser string
SSHPort int
*drivers.BaseDriver
CPU int
Memory int
DiskSize int
@ -49,13 +46,7 @@ type Driver struct {
Datacenter string
Pool string
HostIP string
storePath string
ISO string
CaCertPath string
PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
}
func init() {
@ -136,37 +127,14 @@ func GetCreateFlags() []cli.Flag {
}
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{MachineName: machineName, 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
inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
return &Driver{BaseDriver: inner}, nil
}
func (d *Driver) GetSSHHostname() (string, error) {
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 = "docker"
@ -306,7 +274,7 @@ func (d *Driver) Create() error {
}
// 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
}
@ -454,7 +422,7 @@ func (d *Driver) generateKeyBundle() error {
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 {
return err
}