Migrate (swarmConfig) => (swarmOptions)

and (SwarmConfig) => (SwarmOptions)

Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>

Migrate (authConfig) => (authOptions)
        (AuthConfig) => (AuthOptions)

Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>

Migrate (hostConfig) => (hostOptions)
        (HostConfig) => (HostOptions)

Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
Nathan LeClaire 2015-03-20 22:03:10 -07:00
parent 04f5679e4f
commit 3b2c8f9845
12 changed files with 182 additions and 181 deletions

View File

@ -47,8 +47,8 @@ type machineConfig struct {
caCertPath string caCertPath string
caKeyPath string caKeyPath string
serverKeyPath string serverKeyPath string
AuthConfig auth.AuthOptions AuthOptions auth.AuthOptions
SwarmConfig swarm.SwarmOptions SwarmOptions swarm.SwarmOptions
} }
type hostListItem struct { type hostListItem struct {
@ -57,7 +57,7 @@ type hostListItem struct {
DriverName string DriverName string
State state.State State state.State
URL string URL string
SwarmConfig swarm.SwarmOptions SwarmOptions swarm.SwarmOptions
} }
func sortHostListItemsByName(items []hostListItem) { func sortHostListItemsByName(items []hostListItem) {
@ -398,8 +398,8 @@ func cmdCreate(c *cli.Context) {
log.Fatal(err) log.Fatal(err)
} }
hostConfig := &libmachine.HostOptions{ hostOptions := &libmachine.HostOptions{
AuthConfig: &auth.AuthOptions{ AuthOptions: &auth.AuthOptions{
CaCertPath: certInfo.CaCertPath, CaCertPath: certInfo.CaCertPath,
PrivateKeyPath: certInfo.CaKeyPath, PrivateKeyPath: certInfo.CaKeyPath,
ClientCertPath: certInfo.ClientCertPath, ClientCertPath: certInfo.ClientCertPath,
@ -407,8 +407,8 @@ func cmdCreate(c *cli.Context) {
ServerCertPath: filepath.Join(utils.GetMachineDir(), name, "server.pem"), ServerCertPath: filepath.Join(utils.GetMachineDir(), name, "server.pem"),
ServerKeyPath: filepath.Join(utils.GetMachineDir(), name, "server-key.pem"), ServerKeyPath: filepath.Join(utils.GetMachineDir(), name, "server-key.pem"),
}, },
EngineConfig: &engine.EngineOptions{}, EngineOptions: &engine.EngineOptions{},
SwarmConfig: &swarm.SwarmOptions{ SwarmOptions: &swarm.SwarmOptions{
IsSwarm: c.Bool("swarm"), IsSwarm: c.Bool("swarm"),
Master: c.Bool("swarm-master"), Master: c.Bool("swarm-master"),
Discovery: c.String("swarm-discovery"), Discovery: c.String("swarm-discovery"),
@ -417,7 +417,7 @@ func cmdCreate(c *cli.Context) {
}, },
} }
host, err := mcn.Create(name, driver, hostConfig, c) host, err := mcn.Create(name, driver, hostOptions, c)
if err != nil { if err != nil {
log.Errorf("Error creating machine: %s", err) log.Errorf("Error creating machine: %s", err)
log.Warn("You will want to check the provider to make sure the machine and associated resources were properly removed.") log.Warn("You will want to check the provider to make sure the machine and associated resources were properly removed.")
@ -456,10 +456,10 @@ func cmdConfig(c *cli.Context) {
} }
if c.Bool("swarm") { if c.Bool("swarm") {
if !cfg.SwarmConfig.Master { if !cfg.SwarmOptions.Master {
log.Fatalf("%s is not a swarm master", cfg.machineName) log.Fatalf("%s is not a swarm master", cfg.machineName)
} }
u, err := url.Parse(cfg.SwarmConfig.Host) u, err := url.Parse(cfg.SwarmOptions.Host)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -563,14 +563,14 @@ func cmdLs(c *cli.Context) {
swarmInfo := make(map[string]string) swarmInfo := make(map[string]string)
for _, host := range hostList { for _, host := range hostList {
swarmConfig := host.HostConfig.SwarmConfig swarmOptions := host.HostOptions.SwarmOptions
if !quiet { if !quiet {
if swarmConfig.Master { if swarmOptions.Master {
swarmMasters[swarmConfig.Discovery] = host.Name swarmMasters[swarmOptions.Discovery] = host.Name
} }
if swarmConfig.Discovery != "" { if swarmOptions.Discovery != "" {
swarmInfo[host.Name] = swarmConfig.Discovery swarmInfo[host.Name] = swarmOptions.Discovery
} }
go getHostState(*host, defaultStore, hostListItems) go getHostState(*host, defaultStore, hostListItems)
@ -597,9 +597,9 @@ func cmdLs(c *cli.Context) {
swarmInfo := "" swarmInfo := ""
if item.SwarmConfig.Discovery != "" { if item.SwarmOptions.Discovery != "" {
swarmInfo = swarmMasters[item.SwarmConfig.Discovery] swarmInfo = swarmMasters[item.SwarmOptions.Discovery]
if item.SwarmConfig.Master { if item.SwarmOptions.Master {
swarmInfo = fmt.Sprintf("%s (master)", swarmInfo) swarmInfo = fmt.Sprintf("%s (master)", swarmInfo)
} }
} }
@ -675,10 +675,10 @@ func cmdEnv(c *cli.Context) {
dockerHost := cfg.machineUrl dockerHost := cfg.machineUrl
if c.Bool("swarm") { if c.Bool("swarm") {
if !cfg.SwarmConfig.Master { if !cfg.SwarmOptions.Master {
log.Fatalf("%s is not a swarm master", cfg.machineName) log.Fatalf("%s is not a swarm master", cfg.machineName)
} }
u, err := url.Parse(cfg.SwarmConfig.Host) u, err := url.Parse(cfg.SwarmOptions.Host)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -1038,7 +1038,7 @@ func getHostState(host libmachine.Host, store libmachine.Store, hostListItems ch
DriverName: host.Driver.DriverName(), DriverName: host.Driver.DriverName(),
State: currentState, State: currentState,
URL: url, URL: url,
SwarmConfig: *host.HostConfig.SwarmConfig, SwarmOptions: *host.HostOptions.SwarmOptions,
} }
} }
@ -1103,8 +1103,8 @@ func getMachineConfig(c *cli.Context) (*machineConfig, error) {
caKeyPath: caKey, caKeyPath: caKey,
caCertPath: caCert, caCertPath: caCert,
serverKeyPath: serverKey, serverKeyPath: serverKey,
AuthConfig: *machine.HostConfig.AuthConfig, AuthOptions: *machine.HostOptions.AuthOptions,
SwarmConfig: *machine.HostConfig.SwarmConfig, SwarmOptions: *machine.HostOptions.SwarmOptions,
}, nil }, nil
} }

View File

@ -87,16 +87,16 @@ func getDefaultTestHost() (*libmachine.Host, error) {
Discovery: "", Discovery: "",
Address: "", Address: "",
} }
authConfig := &auth.AuthOptions{ authOptions := &auth.AuthOptions{
CaCertPath: hostTestCaCert, CaCertPath: hostTestCaCert,
PrivateKeyPath: hostTestPrivateKey, PrivateKeyPath: hostTestPrivateKey,
} }
hostConfig := &libmachine.HostOptions{ hostOptions := &libmachine.HostOptions{
EngineConfig: engineOptions, EngineOptions: engineOptions,
SwarmConfig: swarmOptions, SwarmOptions: swarmOptions,
AuthConfig: authConfig, AuthOptions: authOptions,
} }
host, err := libmachine.NewHost(hostTestName, hostTestDriverName, hostConfig) host, err := libmachine.NewHost(hostTestName, hostTestDriverName, hostOptions)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -142,8 +142,8 @@ func TestGetHostState(t *testing.T) {
MockState: state.Running, MockState: state.Running,
}, },
StorePath: store.GetPath(), StorePath: store.GetPath(),
HostConfig: &libmachine.HostOptions{ HostOptions: &libmachine.HostOptions{
SwarmConfig: &swarm.SwarmOptions{ SwarmOptions: &swarm.SwarmOptions{
Master: false, Master: false,
Address: "", Address: "",
Discovery: "", Discovery: "",
@ -157,8 +157,8 @@ func TestGetHostState(t *testing.T) {
MockState: state.Stopped, MockState: state.Stopped,
}, },
StorePath: store.GetPath(), StorePath: store.GetPath(),
HostConfig: &libmachine.HostOptions{ HostOptions: &libmachine.HostOptions{
SwarmConfig: &swarm.SwarmOptions{ SwarmOptions: &swarm.SwarmOptions{
Master: false, Master: false,
Address: "", Address: "",
Discovery: "", Discovery: "",
@ -172,8 +172,8 @@ func TestGetHostState(t *testing.T) {
MockState: state.Running, MockState: state.Running,
}, },
StorePath: store.GetPath(), StorePath: store.GetPath(),
HostConfig: &libmachine.HostOptions{ HostOptions: &libmachine.HostOptions{
SwarmConfig: &swarm.SwarmOptions{ SwarmOptions: &swarm.SwarmOptions{
Master: false, Master: false,
Address: "", Address: "",
Discovery: "", Discovery: "",
@ -335,14 +335,14 @@ func TestCmdConfig(t *testing.T) {
flags := getTestDriverFlags() flags := getTestDriverFlags()
hostOptions := &libmachine.HostOptions{ hostOptions := &libmachine.HostOptions{
EngineConfig: &engine.EngineOptions{}, EngineOptions: &engine.EngineOptions{},
SwarmConfig: &swarm.SwarmOptions{ SwarmOptions: &swarm.SwarmOptions{
Master: false, Master: false,
Discovery: "", Discovery: "",
Address: "", Address: "",
Host: "", Host: "",
}, },
AuthConfig: &auth.AuthOptions{}, AuthOptions: &auth.AuthOptions{},
} }
host, err := mcn.Create("test-a", "none", hostOptions, flags) host, err := mcn.Create("test-a", "none", hostOptions, flags)
@ -432,14 +432,14 @@ func TestCmdEnvBash(t *testing.T) {
} }
hostOptions := &libmachine.HostOptions{ hostOptions := &libmachine.HostOptions{
EngineConfig: &engine.EngineOptions{}, EngineOptions: &engine.EngineOptions{},
SwarmConfig: &swarm.SwarmOptions{ SwarmOptions: &swarm.SwarmOptions{
Master: false, Master: false,
Discovery: "", Discovery: "",
Address: "", Address: "",
Host: "", Host: "",
}, },
AuthConfig: &auth.AuthOptions{}, AuthOptions: &auth.AuthOptions{},
} }
host, err := mcn.Create("test-a", "none", hostOptions, flags) host, err := mcn.Create("test-a", "none", hostOptions, flags)
@ -527,14 +527,14 @@ func TestCmdEnvFish(t *testing.T) {
} }
hostOptions := &libmachine.HostOptions{ hostOptions := &libmachine.HostOptions{
EngineConfig: &engine.EngineOptions{}, EngineOptions: &engine.EngineOptions{},
SwarmConfig: &swarm.SwarmOptions{ SwarmOptions: &swarm.SwarmOptions{
Master: false, Master: false,
Discovery: "", Discovery: "",
Address: "", Address: "",
Host: "", Host: "",
}, },
AuthConfig: &auth.AuthOptions{}, AuthOptions: &auth.AuthOptions{},
} }
host, err := mcn.Create("test-a", "none", hostOptions, flags) host, err := mcn.Create("test-a", "none", hostOptions, flags)

View File

@ -30,7 +30,7 @@ type Host struct {
DriverName string DriverName string
Driver drivers.Driver Driver drivers.Driver
StorePath string StorePath string
HostConfig *HostOptions HostOptions *HostOptions
// deprecated options; these are left to assist in config migrations // deprecated options; these are left to assist in config migrations
SwarmHost string SwarmHost string
@ -48,14 +48,14 @@ type HostOptions struct {
Driver string Driver string
Memory int Memory int
Disk int Disk int
EngineConfig *engine.EngineOptions EngineOptions *engine.EngineOptions
SwarmConfig *swarm.SwarmOptions SwarmOptions *swarm.SwarmOptions
AuthConfig *auth.AuthOptions AuthOptions *auth.AuthOptions
} }
type HostMetadata struct { type HostMetadata struct {
DriverName string DriverName string
HostConfig HostOptions HostOptions HostOptions
StorePath string StorePath string
CaCertPath string CaCertPath string
PrivateKeyPath string PrivateKeyPath string
@ -64,10 +64,10 @@ type HostMetadata struct {
ClientCertPath string ClientCertPath string
} }
func NewHost(name, driverName string, hostConfig *HostOptions) (*Host, error) { func NewHost(name, driverName string, hostOptions *HostOptions) (*Host, error) {
authConfig := hostConfig.AuthConfig authOptions := hostOptions.AuthOptions
storePath := filepath.Join(utils.GetMachineDir(), name) storePath := filepath.Join(utils.GetMachineDir(), name)
driver, err := drivers.NewDriver(driverName, name, storePath, authConfig.CaCertPath, authConfig.PrivateKeyPath) driver, err := drivers.NewDriver(driverName, name, storePath, authOptions.CaCertPath, authOptions.PrivateKeyPath)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -76,7 +76,7 @@ func NewHost(name, driverName string, hostConfig *HostOptions) (*Host, error) {
DriverName: driverName, DriverName: driverName,
Driver: driver, Driver: driver,
StorePath: storePath, StorePath: storePath,
HostConfig: hostConfig, HostOptions: hostOptions,
}, nil }, nil
} }
@ -121,7 +121,7 @@ func (h *Host) Create(name string) error {
return err return err
} }
if err := provisioner.Provision(*h.HostConfig.SwarmConfig, *h.HostConfig.AuthConfig); err != nil { if err := provisioner.Provision(*h.HostOptions.SwarmOptions, *h.HostOptions.AuthOptions); err != nil {
return err return err
} }
} }
@ -271,9 +271,9 @@ func (h *Host) LoadConfig() error {
meta := ValidateHostMetadata(&hostMetadata) meta := ValidateHostMetadata(&hostMetadata)
authConfig := meta.HostConfig.AuthConfig authOptions := meta.HostOptions.AuthOptions
driver, err := drivers.NewDriver(hostMetadata.DriverName, h.Name, h.StorePath, authConfig.CaCertPath, authConfig.PrivateKeyPath) driver, err := drivers.NewDriver(hostMetadata.DriverName, h.Name, h.StorePath, authOptions.CaCertPath, authOptions.PrivateKeyPath)
if err != nil { if err != nil {
return err return err
} }
@ -294,7 +294,7 @@ func (h *Host) ConfigureAuth() error {
return err return err
} }
if err := provision.ConfigureAuth(provisioner, *h.HostConfig.AuthConfig); err != nil { if err := provision.ConfigureAuth(provisioner, *h.HostOptions.AuthOptions); err != nil {
return err return err
} }

View File

@ -59,14 +59,14 @@ func getTestDriverFlags() *DriverOptionsMock {
func getDefaultTestHost() (*Host, error) { func getDefaultTestHost() (*Host, error) {
hostOptions := &HostOptions{ hostOptions := &HostOptions{
EngineConfig: &engine.EngineOptions{}, EngineOptions: &engine.EngineOptions{},
SwarmConfig: &swarm.SwarmOptions{ SwarmOptions: &swarm.SwarmOptions{
Master: false, Master: false,
Host: "", Host: "",
Discovery: "", Discovery: "",
Address: "", Address: "",
}, },
AuthConfig: &auth.AuthOptions{ AuthOptions: &auth.AuthOptions{
CaCertPath: hostTestCaCert, CaCertPath: hostTestCaCert,
PrivateKeyPath: hostTestPrivateKey, PrivateKeyPath: hostTestPrivateKey,
}, },
@ -96,7 +96,7 @@ func TestLoadHostExists(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
authConfig := host.HostConfig.AuthConfig authOptions := host.HostOptions.AuthOptions
if host.Name != hostTestName { if host.Name != hostTestName {
t.Fatalf("expected name %s; received %s", hostTestName, host.Name) t.Fatalf("expected name %s; received %s", hostTestName, host.Name)
} }
@ -105,12 +105,12 @@ func TestLoadHostExists(t *testing.T) {
t.Fatalf("expected driver %s; received %s", hostTestDriverName, host.DriverName) t.Fatalf("expected driver %s; received %s", hostTestDriverName, host.DriverName)
} }
if authConfig.CaCertPath != hostTestCaCert { if authOptions.CaCertPath != hostTestCaCert {
t.Fatalf("expected ca cert path %s; received %s", hostTestCaCert, authConfig.CaCertPath) t.Fatalf("expected ca cert path %s; received %s", hostTestCaCert, authOptions.CaCertPath)
} }
if authConfig.PrivateKeyPath != hostTestPrivateKey { if authOptions.PrivateKeyPath != hostTestPrivateKey {
t.Fatalf("expected key path %s; received %s", hostTestPrivateKey, authConfig.PrivateKeyPath) t.Fatalf("expected key path %s; received %s", hostTestPrivateKey, authOptions.PrivateKeyPath)
} }
} }
@ -148,7 +148,7 @@ func TestValidateHostnameInvalid(t *testing.T) {
} }
} }
func TestHostConfig(t *testing.T) { func TestHostOptions(t *testing.T) {
store, err := getTestStore() store, err := getTestStore()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -19,7 +19,7 @@ func New(store Store) (*Machine, error) {
}, nil }, nil
} }
func (m *Machine) Create(name string, driverName string, hostConfig *HostOptions, driverConfig drivers.DriverOptions) (*Host, error) { func (m *Machine) Create(name string, driverName string, hostOptions *HostOptions, driverConfig drivers.DriverOptions) (*Host, error) {
exists, err := m.store.Exists(name) exists, err := m.store.Exists(name)
if err != nil { if err != nil {
return nil, err return nil, err
@ -30,7 +30,7 @@ func (m *Machine) Create(name string, driverName string, hostConfig *HostOptions
hostPath := filepath.Join(utils.GetMachineDir(), name) hostPath := filepath.Join(utils.GetMachineDir(), name)
host, err := NewHost(name, driverName, hostConfig) host, err := NewHost(name, driverName, hostOptions)
if err != nil { if err != nil {
return host, err return host, err
} }

View File

@ -27,7 +27,7 @@ func NewBoot2DockerProvisioner(d drivers.Driver) Provisioner {
type Boot2DockerProvisioner struct { type Boot2DockerProvisioner struct {
OsReleaseInfo *OsRelease OsReleaseInfo *OsRelease
Driver drivers.Driver Driver drivers.Driver
SwarmConfig swarm.SwarmOptions SwarmOptions swarm.SwarmOptions
} }
func (provisioner *Boot2DockerProvisioner) Service(name string, action pkgaction.ServiceAction) error { func (provisioner *Boot2DockerProvisioner) Service(name string, action pkgaction.ServiceAction) error {
@ -82,23 +82,23 @@ func (provisioner *Boot2DockerProvisioner) SetHostname(hostname string) error {
return cmd.Run() return cmd.Run()
} }
func (provisioner *Boot2DockerProvisioner) GetDockerConfigDir() string { func (provisioner *Boot2DockerProvisioner) GetDockerOptionsDir() string {
return "/var/lib/boot2docker" return "/var/lib/boot2docker"
} }
func (provisioner *Boot2DockerProvisioner) GenerateDockerConfig(dockerPort int, authConfig auth.AuthOptions) (*DockerConfig, error) { func (provisioner *Boot2DockerProvisioner) GenerateDockerOptions(dockerPort int, authOptions auth.AuthOptions) (*DockerOptions, error) {
defaultDaemonOpts := getDefaultDaemonOpts(provisioner.Driver.DriverName(), authConfig) defaultDaemonOpts := getDefaultDaemonOpts(provisioner.Driver.DriverName(), authOptions)
daemonOpts := fmt.Sprintf("-H tcp://0.0.0.0:%d", dockerPort) daemonOpts := fmt.Sprintf("-H tcp://0.0.0.0:%d", dockerPort)
daemonOptsCfg := path.Join(provisioner.GetDockerConfigDir(), "profile") daemonOptsDir := path.Join(provisioner.GetDockerOptionsDir(), "profile")
opts := fmt.Sprintf("%s %s", defaultDaemonOpts, daemonOpts) opts := fmt.Sprintf("%s %s", defaultDaemonOpts, daemonOpts)
daemonCfg := fmt.Sprintf(`EXTRA_ARGS='%s' daemonCfg := fmt.Sprintf(`EXTRA_ARGS='%s'
CACERT=%s CACERT=%s
SERVERCERT=%s SERVERCERT=%s
SERVERKEY=%s SERVERKEY=%s
DOCKER_TLS=no`, opts, authConfig.CaCertRemotePath, authConfig.ServerCertRemotePath, authConfig.ServerKeyRemotePath) DOCKER_TLS=no`, opts, authOptions.CaCertRemotePath, authOptions.ServerCertRemotePath, authOptions.ServerKeyRemotePath)
return &DockerConfig{ return &DockerOptions{
EngineConfig: daemonCfg, EngineOptions: daemonCfg,
EngineConfigPath: daemonOptsCfg, EngineOptionsPath: daemonOptsDir,
}, nil }, nil
} }
@ -110,7 +110,7 @@ func (provisioner *Boot2DockerProvisioner) SetOsReleaseInfo(info *OsRelease) {
provisioner.OsReleaseInfo = info provisioner.OsReleaseInfo = info
} }
func (provisioner *Boot2DockerProvisioner) Provision(swarmConfig swarm.SwarmOptions, authConfig auth.AuthOptions) error { func (provisioner *Boot2DockerProvisioner) Provision(swarmOptions swarm.SwarmOptions, authOptions auth.AuthOptions) error {
if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil { if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil {
return err return err
} }
@ -119,11 +119,11 @@ func (provisioner *Boot2DockerProvisioner) Provision(swarmConfig swarm.SwarmOpti
return err return err
} }
if err := ConfigureAuth(provisioner, authConfig); err != nil { if err := ConfigureAuth(provisioner, authOptions); err != nil {
return err return err
} }
if err := configureSwarm(provisioner, swarmConfig); err != nil { if err := configureSwarm(provisioner, swarmOptions); err != nil {
return err return err
} }

View File

@ -16,10 +16,10 @@ var provisioners = make(map[string]*RegisteredProvisioner)
// Distribution specific actions // Distribution specific actions
type Provisioner interface { type Provisioner interface {
// Create the files for the daemon to consume configuration settings (return struct of content and path) // Create the files for the daemon to consume configuration settings (return struct of content and path)
GenerateDockerConfig(dockerPort int, authConfig auth.AuthOptions) (*DockerConfig, error) GenerateDockerOptions(dockerPort int, authOptions auth.AuthOptions) (*DockerOptions, error)
// Get the directory where the settings files for docker are to be found // Get the directory where the settings files for docker are to be found
GetDockerConfigDir() string GetDockerOptionsDir() string
// Run a package action e.g. install // Run a package action e.g. install
Package(name string, action pkgaction.PackageAction) error Package(name string, action pkgaction.PackageAction) error
@ -39,7 +39,7 @@ type Provisioner interface {
// 3. Configure the daemon to accept connections over TLS. // 3. Configure the daemon to accept connections over TLS.
// 4. Copy the needed certificates to the server and local config dir. // 4. Copy the needed certificates to the server and local config dir.
// 5. Configure / activate swarm if applicable. // 5. Configure / activate swarm if applicable.
Provision(swarmConfig swarm.SwarmOptions, authConfig auth.AuthOptions) error Provision(swarmOptions swarm.SwarmOptions, authOptions auth.AuthOptions) error
// Perform action on a named service e.g. stop // Perform action on a named service e.g. stop
Service(name string, action pkgaction.ServiceAction) error Service(name string, action pkgaction.ServiceAction) error

View File

@ -30,7 +30,7 @@ type UbuntuProvisioner struct {
packages []string packages []string
OsReleaseInfo *OsRelease OsReleaseInfo *OsRelease
Driver drivers.Driver Driver drivers.Driver
SwarmConfig swarm.SwarmOptions SwarmOptions swarm.SwarmOptions
} }
func (provisioner *UbuntuProvisioner) Service(name string, action pkgaction.ServiceAction) error { func (provisioner *UbuntuProvisioner) Service(name string, action pkgaction.ServiceAction) error {
@ -72,7 +72,7 @@ func (provisioner *UbuntuProvisioner) Package(name string, action pkgaction.Pack
return nil return nil
} }
func (provisioner *UbuntuProvisioner) Provision(swarmConfig swarm.SwarmOptions, authConfig auth.AuthOptions) error { func (provisioner *UbuntuProvisioner) Provision(swarmOptions swarm.SwarmOptions, authOptions auth.AuthOptions) error {
if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil { if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil {
return err return err
} }
@ -87,11 +87,11 @@ func (provisioner *UbuntuProvisioner) Provision(swarmConfig swarm.SwarmOptions,
return err return err
} }
if err := ConfigureAuth(provisioner, authConfig); err != nil { if err := ConfigureAuth(provisioner, authOptions); err != nil {
return err return err
} }
if err := configureSwarm(provisioner, swarmConfig); err != nil { if err := configureSwarm(provisioner, swarmOptions); err != nil {
return err return err
} }
@ -129,7 +129,7 @@ func (provisioner *UbuntuProvisioner) SetHostname(hostname string) error {
return cmd.Run() return cmd.Run()
} }
func (provisioner *UbuntuProvisioner) GetDockerConfigDir() string { func (provisioner *UbuntuProvisioner) GetDockerOptionsDir() string {
return "/etc/docker" return "/etc/docker"
} }
@ -145,15 +145,15 @@ func (provisioner *UbuntuProvisioner) SetOsReleaseInfo(info *OsRelease) {
provisioner.OsReleaseInfo = info provisioner.OsReleaseInfo = info
} }
func (provisioner *UbuntuProvisioner) GenerateDockerConfig(dockerPort int, authConfig auth.AuthOptions) (*DockerConfig, error) { func (provisioner *UbuntuProvisioner) GenerateDockerOptions(dockerPort int, authOptions auth.AuthOptions) (*DockerOptions, error) {
defaultDaemonOpts := getDefaultDaemonOpts(provisioner.Driver.DriverName(), authConfig) defaultDaemonOpts := getDefaultDaemonOpts(provisioner.Driver.DriverName(), authOptions)
daemonOpts := fmt.Sprintf("--host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:%d", dockerPort) daemonOpts := fmt.Sprintf("--host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:%d", dockerPort)
daemonOptsCfg := "/etc/default/docker" daemonOptsDir := "/etc/default/docker"
opts := fmt.Sprintf("%s %s", defaultDaemonOpts, daemonOpts) opts := fmt.Sprintf("%s %s", defaultDaemonOpts, daemonOpts)
daemonCfg := fmt.Sprintf("export DOCKER_OPTS=\\\"%s\\\"", opts) daemonCfg := fmt.Sprintf("export DOCKER_OPTS=\\\"%s\\\"", opts)
return &DockerConfig{ return &DockerOptions{
EngineConfig: daemonCfg, EngineOptions: daemonCfg,
EngineConfigPath: daemonOptsCfg, EngineOptionsPath: daemonOptsDir,
}, nil }, nil
} }

View File

@ -17,9 +17,9 @@ import (
"github.com/docker/machine/utils" "github.com/docker/machine/utils"
) )
type DockerConfig struct { type DockerOptions struct {
EngineConfig string EngineOptions string
EngineConfigPath string EngineOptionsPath string
} }
func installDockerGeneric(p Provisioner) error { func installDockerGeneric(p Provisioner) error {
@ -42,7 +42,7 @@ func installDockerGeneric(p Provisioner) error {
return nil return nil
} }
func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error { func ConfigureAuth(p Provisioner, authOptions auth.AuthOptions) error {
var ( var (
err error err error
) )
@ -59,33 +59,33 @@ func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error {
// copy certs to client dir for docker client // copy certs to client dir for docker client
machineDir := filepath.Join(utils.GetMachineDir(), machineName) machineDir := filepath.Join(utils.GetMachineDir(), machineName)
if err := utils.CopyFile(authConfig.CaCertPath, filepath.Join(machineDir, "ca.pem")); err != nil { if err := utils.CopyFile(authOptions.CaCertPath, filepath.Join(machineDir, "ca.pem")); err != nil {
log.Fatalf("Error copying ca.pem to machine dir: %s", err) log.Fatalf("Error copying ca.pem to machine dir: %s", err)
} }
if err := utils.CopyFile(authConfig.ClientCertPath, filepath.Join(machineDir, "cert.pem")); err != nil { if err := utils.CopyFile(authOptions.ClientCertPath, filepath.Join(machineDir, "cert.pem")); err != nil {
log.Fatalf("Error copying cert.pem to machine dir: %s", err) log.Fatalf("Error copying cert.pem to machine dir: %s", err)
} }
if err := utils.CopyFile(authConfig.ClientKeyPath, filepath.Join(machineDir, "key.pem")); err != nil { if err := utils.CopyFile(authOptions.ClientKeyPath, filepath.Join(machineDir, "key.pem")); err != nil {
log.Fatalf("Error copying key.pem to machine dir: %s", err) log.Fatalf("Error copying key.pem to machine dir: %s", err)
} }
log.Debugf("generating server cert: %s ca-key=%s private-key=%s org=%s", log.Debugf("generating server cert: %s ca-key=%s private-key=%s org=%s",
authConfig.ServerCertPath, authOptions.ServerCertPath,
authConfig.CaCertPath, authOptions.CaCertPath,
authConfig.PrivateKeyPath, authOptions.PrivateKeyPath,
org, org,
) )
// TODO: Switch to passing just authConfig to this func // TODO: Switch to passing just authOptions to this func
// instead of all these individual fields // instead of all these individual fields
err = utils.GenerateCert( err = utils.GenerateCert(
[]string{ip}, []string{ip},
authConfig.ServerCertPath, authOptions.ServerCertPath,
authConfig.ServerKeyPath, authOptions.ServerKeyPath,
authConfig.CaCertPath, authOptions.CaCertPath,
authConfig.PrivateKeyPath, authOptions.PrivateKeyPath,
org, org,
bits, bits,
) )
@ -97,7 +97,7 @@ func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error {
return err return err
} }
dockerDir := p.GetDockerConfigDir() dockerDir := p.GetDockerOptionsDir()
cmd, err := p.SSHCommand(fmt.Sprintf("sudo mkdir -p %s", dockerDir)) cmd, err := p.SSHCommand(fmt.Sprintf("sudo mkdir -p %s", dockerDir))
if err != nil { if err != nil {
@ -108,7 +108,7 @@ func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error {
} }
// upload certs and configure TLS auth // upload certs and configure TLS auth
caCert, err := ioutil.ReadFile(authConfig.CaCertPath) caCert, err := ioutil.ReadFile(authOptions.CaCertPath)
if err != nil { if err != nil {
return err return err
} }
@ -116,21 +116,21 @@ func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error {
// due to windows clients, we cannot use filepath.Join as the paths // due to windows clients, we cannot use filepath.Join as the paths
// will be mucked on the linux hosts // will be mucked on the linux hosts
machineCaCertPath := path.Join(dockerDir, "ca.pem") machineCaCertPath := path.Join(dockerDir, "ca.pem")
authConfig.CaCertRemotePath = machineCaCertPath authOptions.CaCertRemotePath = machineCaCertPath
serverCert, err := ioutil.ReadFile(authConfig.ServerCertPath) serverCert, err := ioutil.ReadFile(authOptions.ServerCertPath)
if err != nil { if err != nil {
return err return err
} }
machineServerCertPath := path.Join(dockerDir, "server.pem") machineServerCertPath := path.Join(dockerDir, "server.pem")
authConfig.ServerCertRemotePath = machineServerCertPath authOptions.ServerCertRemotePath = machineServerCertPath
serverKey, err := ioutil.ReadFile(authConfig.ServerKeyPath) serverKey, err := ioutil.ReadFile(authOptions.ServerKeyPath)
if err != nil { if err != nil {
return err return err
} }
machineServerKeyPath := path.Join(dockerDir, "server-key.pem") machineServerKeyPath := path.Join(dockerDir, "server-key.pem")
authConfig.ServerKeyRemotePath = machineServerKeyPath authOptions.ServerKeyRemotePath = machineServerKeyPath
cmd, err = p.SSHCommand(fmt.Sprintf("echo \"%s\" | sudo tee %s", string(caCert), machineCaCertPath)) cmd, err = p.SSHCommand(fmt.Sprintf("echo \"%s\" | sudo tee %s", string(caCert), machineCaCertPath))
if err != nil { if err != nil {
@ -174,12 +174,12 @@ func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error {
dockerPort = dPort dockerPort = dPort
} }
dkrcfg, err := p.GenerateDockerConfig(dockerPort, authConfig) dkrcfg, err := p.GenerateDockerOptions(dockerPort, authOptions)
if err != nil { if err != nil {
return err return err
} }
cmd, err = p.SSHCommand(fmt.Sprintf("echo \"%s\" | sudo tee -a %s", dkrcfg.EngineConfig, dkrcfg.EngineConfigPath)) cmd, err = p.SSHCommand(fmt.Sprintf("echo \"%s\" | sudo tee -a %s", dkrcfg.EngineOptions, dkrcfg.EngineOptionsPath))
if err != nil { if err != nil {
return err return err
} }
@ -194,21 +194,21 @@ func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error {
return nil return nil
} }
func getDefaultDaemonOpts(driverName string, authConfig auth.AuthOptions) string { func getDefaultDaemonOpts(driverName string, authOptions auth.AuthOptions) string {
return fmt.Sprintf(`--tlsverify --tlscacert=%s --tlskey=%s --tlscert=%s %s`, return fmt.Sprintf(`--tlsverify --tlscacert=%s --tlskey=%s --tlscert=%s %s`,
authConfig.CaCertRemotePath, authOptions.CaCertRemotePath,
authConfig.ServerKeyRemotePath, authOptions.ServerKeyRemotePath,
authConfig.ServerCertRemotePath, authOptions.ServerCertRemotePath,
fmt.Sprintf("--label=provider=%s", driverName), fmt.Sprintf("--label=provider=%s", driverName),
) )
} }
func configureSwarm(p Provisioner, swarmConfig swarm.SwarmOptions) error { func configureSwarm(p Provisioner, swarmOptions swarm.SwarmOptions) error {
if !swarmConfig.IsSwarm { if !swarmOptions.IsSwarm {
return nil return nil
} }
basePath := p.GetDockerConfigDir() basePath := p.GetDockerOptionsDir()
ip, err := p.GetDriver().GetIP() ip, err := p.GetDriver().GetIP()
if err != nil { if err != nil {
return err return err
@ -218,10 +218,10 @@ func configureSwarm(p Provisioner, swarmConfig swarm.SwarmOptions) error {
tlsCert := path.Join(basePath, "server.pem") tlsCert := path.Join(basePath, "server.pem")
tlsKey := path.Join(basePath, "server-key.pem") tlsKey := path.Join(basePath, "server-key.pem")
masterArgs := fmt.Sprintf("--tlsverify --tlscacert=%s --tlscert=%s --tlskey=%s -H %s %s", masterArgs := fmt.Sprintf("--tlsverify --tlscacert=%s --tlscert=%s --tlskey=%s -H %s %s",
tlsCaCert, tlsCert, tlsKey, swarmConfig.Host, swarmConfig.Discovery) tlsCaCert, tlsCert, tlsKey, swarmOptions.Host, swarmOptions.Discovery)
nodeArgs := fmt.Sprintf("--addr %s:2376 %s", ip, swarmConfig.Discovery) nodeArgs := fmt.Sprintf("--addr %s:2376 %s", ip, swarmOptions.Discovery)
u, err := url.Parse(swarmConfig.Host) u, err := url.Parse(swarmOptions.Host)
if err != nil { if err != nil {
return err return err
} }
@ -242,10 +242,10 @@ func configureSwarm(p Provisioner, swarmConfig swarm.SwarmOptions) error {
return err return err
} }
dockerDir := p.GetDockerConfigDir() dockerDir := p.GetDockerOptionsDir()
// if master start master agent // if master start master agent
if swarmConfig.Master { if swarmOptions.Master {
log.Debug("launching swarm master") log.Debug("launching swarm master")
log.Debugf("master args: %s", masterArgs) log.Debugf("master args: %s", masterArgs)
cmd, err = p.SSHCommand(fmt.Sprintf("sudo docker run -d -p %s:%s --restart=always --name swarm-agent-master -v %s:%s %s manage %s", cmd, err = p.SSHCommand(fmt.Sprintf("sudo docker run -d -p %s:%s --restart=always --name swarm-agent-master -v %s:%s %s manage %s",

View File

@ -10,41 +10,41 @@ import (
"github.com/docker/machine/libmachine/auth" "github.com/docker/machine/libmachine/auth"
) )
func TestGenerateDockerConfigBoot2Docker(t *testing.T) { func TestGenerateDockerOptionsBoot2Docker(t *testing.T) {
p := &Boot2DockerProvisioner{ p := &Boot2DockerProvisioner{
Driver: &fakedriver.FakeDriver{}, Driver: &fakedriver.FakeDriver{},
} }
dockerPort := 1234 dockerPort := 1234
authConfig := auth.AuthOptions{ authOptions := auth.AuthOptions{
CaCertRemotePath: "/test/ca-cert", CaCertRemotePath: "/test/ca-cert",
ServerKeyRemotePath: "/test/server-key", ServerKeyRemotePath: "/test/server-key",
ServerCertRemotePath: "/test/server-cert", ServerCertRemotePath: "/test/server-cert",
} }
engineConfigPath := "/var/lib/boot2docker/profile" engineConfigPath := "/var/lib/boot2docker/profile"
dockerCfg, err := p.GenerateDockerConfig(dockerPort, authConfig) dockerCfg, err := p.GenerateDockerOptions(dockerPort, authOptions)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if dockerCfg.EngineConfigPath != engineConfigPath { if dockerCfg.EngineOptionsPath != engineConfigPath {
t.Fatalf("expected engine path %s; received %s", engineConfigPath, dockerCfg.EngineConfigPath) t.Fatalf("expected engine path %s; received %s", engineConfigPath, dockerCfg.EngineOptionsPath)
} }
if strings.Index(dockerCfg.EngineConfig, fmt.Sprintf("-H tcp://0.0.0.0:%d", dockerPort)) == -1 { if strings.Index(dockerCfg.EngineOptions, fmt.Sprintf("-H tcp://0.0.0.0:%d", dockerPort)) == -1 {
t.Fatalf("-H docker port invalid; expected %d", dockerPort) t.Fatalf("-H docker port invalid; expected %d", dockerPort)
} }
if strings.Index(dockerCfg.EngineConfig, fmt.Sprintf("CACERT=%s", authConfig.CaCertRemotePath)) == -1 { if strings.Index(dockerCfg.EngineOptions, fmt.Sprintf("CACERT=%s", authOptions.CaCertRemotePath)) == -1 {
t.Fatalf("CACERT option invalid; expected %s", authConfig.CaCertRemotePath) t.Fatalf("CACERT option invalid; expected %s", authOptions.CaCertRemotePath)
} }
if strings.Index(dockerCfg.EngineConfig, fmt.Sprintf("SERVERKEY=%s", authConfig.ServerKeyRemotePath)) == -1 { if strings.Index(dockerCfg.EngineOptions, fmt.Sprintf("SERVERKEY=%s", authOptions.ServerKeyRemotePath)) == -1 {
t.Fatalf("SERVERKEY option invalid; expected %s", authConfig.ServerKeyRemotePath) t.Fatalf("SERVERKEY option invalid; expected %s", authOptions.ServerKeyRemotePath)
} }
if strings.Index(dockerCfg.EngineConfig, fmt.Sprintf("SERVERCERT=%s", authConfig.ServerCertRemotePath)) == -1 { if strings.Index(dockerCfg.EngineOptions, fmt.Sprintf("SERVERCERT=%s", authOptions.ServerCertRemotePath)) == -1 {
t.Fatalf("SERVERCERT option invalid; expected %s", authConfig.ServerCertRemotePath) t.Fatalf("SERVERCERT option invalid; expected %s", authOptions.ServerCertRemotePath)
} }
} }
@ -54,18 +54,18 @@ func TestMachinePortBoot2Docker(t *testing.T) {
} }
dockerPort := 2376 dockerPort := 2376
bindUrl := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort) bindUrl := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort)
authConfig := auth.AuthOptions{ authOptions := auth.AuthOptions{
CaCertRemotePath: "/test/ca-cert", CaCertRemotePath: "/test/ca-cert",
ServerKeyRemotePath: "/test/server-key", ServerKeyRemotePath: "/test/server-key",
ServerCertRemotePath: "/test/server-cert", ServerCertRemotePath: "/test/server-cert",
} }
cfg, err := p.GenerateDockerConfig(dockerPort, authConfig) cfg, err := p.GenerateDockerOptions(dockerPort, authOptions)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
re := regexp.MustCompile("-H tcp://.*:(.+)") re := regexp.MustCompile("-H tcp://.*:(.+)")
m := re.FindStringSubmatch(cfg.EngineConfig) m := re.FindStringSubmatch(cfg.EngineOptions)
if len(m) == 0 { if len(m) == 0 {
t.Errorf("could not find port %d in engine config", dockerPort) t.Errorf("could not find port %d in engine config", dockerPort)
} }
@ -86,19 +86,19 @@ func TestMachineCustomPortBoot2Docker(t *testing.T) {
} }
dockerPort := 3376 dockerPort := 3376
bindUrl := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort) bindUrl := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort)
authConfig := auth.AuthOptions{ authOptions := auth.AuthOptions{
CaCertRemotePath: "/test/ca-cert", CaCertRemotePath: "/test/ca-cert",
ServerKeyRemotePath: "/test/server-key", ServerKeyRemotePath: "/test/server-key",
ServerCertRemotePath: "/test/server-cert", ServerCertRemotePath: "/test/server-cert",
} }
cfg, err := p.GenerateDockerConfig(dockerPort, authConfig) cfg, err := p.GenerateDockerOptions(dockerPort, authOptions)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
re := regexp.MustCompile("-H tcp://.*:(.+)") re := regexp.MustCompile("-H tcp://.*:(.+)")
m := re.FindStringSubmatch(cfg.EngineConfig) m := re.FindStringSubmatch(cfg.EngineOptions)
if len(m) == 0 { if len(m) == 0 {
t.Errorf("could not find port %d in engine config", dockerPort) t.Errorf("could not find port %d in engine config", dockerPort)
} }

View File

@ -14,15 +14,15 @@ import (
func ValidateHost(host *Host) *Host { func ValidateHost(host *Host) *Host {
certInfo := getCertInfoFromHost(host) certInfo := getCertInfoFromHost(host)
if host.HostConfig == nil { if host.HostOptions == nil {
host.HostConfig = &HostOptions{} host.HostOptions = &HostOptions{}
} }
if host.HostConfig.EngineConfig == nil { if host.HostOptions.EngineOptions == nil {
host.HostConfig.EngineConfig = &engine.EngineOptions{} host.HostOptions.EngineOptions = &engine.EngineOptions{}
} }
if host.HostConfig.SwarmConfig == nil { if host.HostOptions.SwarmOptions == nil {
host.HostConfig.SwarmConfig = &swarm.SwarmOptions{ host.HostOptions.SwarmOptions = &swarm.SwarmOptions{
Address: "", Address: "",
Discovery: host.SwarmDiscovery, Discovery: host.SwarmDiscovery,
Host: host.SwarmHost, Host: host.SwarmHost,
@ -30,7 +30,7 @@ func ValidateHost(host *Host) *Host {
} }
} }
host.HostConfig.AuthConfig = &auth.AuthOptions{ host.HostOptions.AuthOptions = &auth.AuthOptions{
StorePath: host.StorePath, StorePath: host.StorePath,
CaCertPath: certInfo.CaCertPath, CaCertPath: certInfo.CaCertPath,
CaCertRemotePath: "", CaCertRemotePath: "",
@ -49,12 +49,12 @@ func ValidateHost(host *Host) *Host {
// validates host metadata and modifies if needed // validates host metadata and modifies if needed
// this is used for configuration updates // this is used for configuration updates
func ValidateHostMetadata(m *HostMetadata) *HostMetadata { func ValidateHostMetadata(m *HostMetadata) *HostMetadata {
if m.HostConfig.EngineConfig == nil { if m.HostOptions.EngineOptions == nil {
m.HostConfig.EngineConfig = &engine.EngineOptions{} m.HostOptions.EngineOptions = &engine.EngineOptions{}
} }
if m.HostConfig.AuthConfig == nil { if m.HostOptions.AuthOptions == nil {
m.HostConfig.AuthConfig = &auth.AuthOptions{ m.HostOptions.AuthOptions = &auth.AuthOptions{
StorePath: m.StorePath, StorePath: m.StorePath,
CaCertPath: m.CaCertPath, CaCertPath: m.CaCertPath,
CaCertRemotePath: "", CaCertRemotePath: "",

View File

@ -14,7 +14,8 @@ fi
MACHINE_BIN_NAME=docker-machine_$PLATFORM-$ARCH MACHINE_BIN_NAME=docker-machine_$PLATFORM-$ARCH
BATS_LOG=${MACHINE_ROOT}/bats.log BATS_LOG=${MACHINE_ROOT}/bats.log
truncate -s0 ${BATS_LOG} touch ${BATS_LOG}
rm ${BATS_LOG}
teardown() { teardown() {
echo "$BATS_TEST_NAME echo "$BATS_TEST_NAME