diff --git a/commands.go b/commands.go index 26b7ecbc65..4909f7e5b5 100644 --- a/commands.go +++ b/commands.go @@ -47,17 +47,17 @@ type machineConfig struct { caCertPath string caKeyPath string serverKeyPath string - AuthConfig auth.AuthOptions - SwarmConfig swarm.SwarmOptions + AuthOptions auth.AuthOptions + SwarmOptions swarm.SwarmOptions } type hostListItem struct { - Name string - Active bool - DriverName string - State state.State - URL string - SwarmConfig swarm.SwarmOptions + Name string + Active bool + DriverName string + State state.State + URL string + SwarmOptions swarm.SwarmOptions } func sortHostListItemsByName(items []hostListItem) { @@ -398,8 +398,8 @@ func cmdCreate(c *cli.Context) { log.Fatal(err) } - hostConfig := &libmachine.HostOptions{ - AuthConfig: &auth.AuthOptions{ + hostOptions := &libmachine.HostOptions{ + AuthOptions: &auth.AuthOptions{ CaCertPath: certInfo.CaCertPath, PrivateKeyPath: certInfo.CaKeyPath, ClientCertPath: certInfo.ClientCertPath, @@ -407,8 +407,8 @@ func cmdCreate(c *cli.Context) { ServerCertPath: filepath.Join(utils.GetMachineDir(), name, "server.pem"), ServerKeyPath: filepath.Join(utils.GetMachineDir(), name, "server-key.pem"), }, - EngineConfig: &engine.EngineOptions{}, - SwarmConfig: &swarm.SwarmOptions{ + EngineOptions: &engine.EngineOptions{}, + SwarmOptions: &swarm.SwarmOptions{ IsSwarm: c.Bool("swarm"), Master: c.Bool("swarm-master"), 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 { 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.") @@ -456,10 +456,10 @@ func cmdConfig(c *cli.Context) { } if c.Bool("swarm") { - if !cfg.SwarmConfig.Master { + if !cfg.SwarmOptions.Master { 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 { log.Fatal(err) } @@ -563,14 +563,14 @@ func cmdLs(c *cli.Context) { swarmInfo := make(map[string]string) for _, host := range hostList { - swarmConfig := host.HostConfig.SwarmConfig + swarmOptions := host.HostOptions.SwarmOptions if !quiet { - if swarmConfig.Master { - swarmMasters[swarmConfig.Discovery] = host.Name + if swarmOptions.Master { + swarmMasters[swarmOptions.Discovery] = host.Name } - if swarmConfig.Discovery != "" { - swarmInfo[host.Name] = swarmConfig.Discovery + if swarmOptions.Discovery != "" { + swarmInfo[host.Name] = swarmOptions.Discovery } go getHostState(*host, defaultStore, hostListItems) @@ -597,9 +597,9 @@ func cmdLs(c *cli.Context) { swarmInfo := "" - if item.SwarmConfig.Discovery != "" { - swarmInfo = swarmMasters[item.SwarmConfig.Discovery] - if item.SwarmConfig.Master { + if item.SwarmOptions.Discovery != "" { + swarmInfo = swarmMasters[item.SwarmOptions.Discovery] + if item.SwarmOptions.Master { swarmInfo = fmt.Sprintf("%s (master)", swarmInfo) } } @@ -675,10 +675,10 @@ func cmdEnv(c *cli.Context) { dockerHost := cfg.machineUrl if c.Bool("swarm") { - if !cfg.SwarmConfig.Master { + if !cfg.SwarmOptions.Master { 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 { log.Fatal(err) } @@ -1033,12 +1033,12 @@ func getHostState(host libmachine.Host, store libmachine.Store, hostListItems ch } hostListItems <- hostListItem{ - Name: host.Name, - Active: isActive, - DriverName: host.Driver.DriverName(), - State: currentState, - URL: url, - SwarmConfig: *host.HostConfig.SwarmConfig, + Name: host.Name, + Active: isActive, + DriverName: host.Driver.DriverName(), + State: currentState, + URL: url, + SwarmOptions: *host.HostOptions.SwarmOptions, } } @@ -1103,8 +1103,8 @@ func getMachineConfig(c *cli.Context) (*machineConfig, error) { caKeyPath: caKey, caCertPath: caCert, serverKeyPath: serverKey, - AuthConfig: *machine.HostConfig.AuthConfig, - SwarmConfig: *machine.HostConfig.SwarmConfig, + AuthOptions: *machine.HostOptions.AuthOptions, + SwarmOptions: *machine.HostOptions.SwarmOptions, }, nil } diff --git a/commands_test.go b/commands_test.go index f365a9c5fc..7de8771cc9 100644 --- a/commands_test.go +++ b/commands_test.go @@ -87,16 +87,16 @@ func getDefaultTestHost() (*libmachine.Host, error) { Discovery: "", Address: "", } - authConfig := &auth.AuthOptions{ + authOptions := &auth.AuthOptions{ CaCertPath: hostTestCaCert, PrivateKeyPath: hostTestPrivateKey, } - hostConfig := &libmachine.HostOptions{ - EngineConfig: engineOptions, - SwarmConfig: swarmOptions, - AuthConfig: authConfig, + hostOptions := &libmachine.HostOptions{ + EngineOptions: engineOptions, + SwarmOptions: swarmOptions, + AuthOptions: authOptions, } - host, err := libmachine.NewHost(hostTestName, hostTestDriverName, hostConfig) + host, err := libmachine.NewHost(hostTestName, hostTestDriverName, hostOptions) if err != nil { return nil, err } @@ -142,8 +142,8 @@ func TestGetHostState(t *testing.T) { MockState: state.Running, }, StorePath: store.GetPath(), - HostConfig: &libmachine.HostOptions{ - SwarmConfig: &swarm.SwarmOptions{ + HostOptions: &libmachine.HostOptions{ + SwarmOptions: &swarm.SwarmOptions{ Master: false, Address: "", Discovery: "", @@ -157,8 +157,8 @@ func TestGetHostState(t *testing.T) { MockState: state.Stopped, }, StorePath: store.GetPath(), - HostConfig: &libmachine.HostOptions{ - SwarmConfig: &swarm.SwarmOptions{ + HostOptions: &libmachine.HostOptions{ + SwarmOptions: &swarm.SwarmOptions{ Master: false, Address: "", Discovery: "", @@ -172,8 +172,8 @@ func TestGetHostState(t *testing.T) { MockState: state.Running, }, StorePath: store.GetPath(), - HostConfig: &libmachine.HostOptions{ - SwarmConfig: &swarm.SwarmOptions{ + HostOptions: &libmachine.HostOptions{ + SwarmOptions: &swarm.SwarmOptions{ Master: false, Address: "", Discovery: "", @@ -335,14 +335,14 @@ func TestCmdConfig(t *testing.T) { flags := getTestDriverFlags() hostOptions := &libmachine.HostOptions{ - EngineConfig: &engine.EngineOptions{}, - SwarmConfig: &swarm.SwarmOptions{ + EngineOptions: &engine.EngineOptions{}, + SwarmOptions: &swarm.SwarmOptions{ Master: false, Discovery: "", Address: "", Host: "", }, - AuthConfig: &auth.AuthOptions{}, + AuthOptions: &auth.AuthOptions{}, } host, err := mcn.Create("test-a", "none", hostOptions, flags) @@ -432,14 +432,14 @@ func TestCmdEnvBash(t *testing.T) { } hostOptions := &libmachine.HostOptions{ - EngineConfig: &engine.EngineOptions{}, - SwarmConfig: &swarm.SwarmOptions{ + EngineOptions: &engine.EngineOptions{}, + SwarmOptions: &swarm.SwarmOptions{ Master: false, Discovery: "", Address: "", Host: "", }, - AuthConfig: &auth.AuthOptions{}, + AuthOptions: &auth.AuthOptions{}, } host, err := mcn.Create("test-a", "none", hostOptions, flags) @@ -527,14 +527,14 @@ func TestCmdEnvFish(t *testing.T) { } hostOptions := &libmachine.HostOptions{ - EngineConfig: &engine.EngineOptions{}, - SwarmConfig: &swarm.SwarmOptions{ + EngineOptions: &engine.EngineOptions{}, + SwarmOptions: &swarm.SwarmOptions{ Master: false, Discovery: "", Address: "", Host: "", }, - AuthConfig: &auth.AuthOptions{}, + AuthOptions: &auth.AuthOptions{}, } host, err := mcn.Create("test-a", "none", hostOptions, flags) diff --git a/libmachine/host.go b/libmachine/host.go index c7d5ca2ec8..952a57a989 100644 --- a/libmachine/host.go +++ b/libmachine/host.go @@ -26,11 +26,11 @@ var ( ) type Host struct { - Name string `json:"-"` - DriverName string - Driver drivers.Driver - StorePath string - HostConfig *HostOptions + Name string `json:"-"` + DriverName string + Driver drivers.Driver + StorePath string + HostOptions *HostOptions // deprecated options; these are left to assist in config migrations SwarmHost string @@ -45,17 +45,17 @@ type Host struct { } type HostOptions struct { - Driver string - Memory int - Disk int - EngineConfig *engine.EngineOptions - SwarmConfig *swarm.SwarmOptions - AuthConfig *auth.AuthOptions + Driver string + Memory int + Disk int + EngineOptions *engine.EngineOptions + SwarmOptions *swarm.SwarmOptions + AuthOptions *auth.AuthOptions } type HostMetadata struct { DriverName string - HostConfig HostOptions + HostOptions HostOptions StorePath string CaCertPath string PrivateKeyPath string @@ -64,19 +64,19 @@ type HostMetadata struct { ClientCertPath string } -func NewHost(name, driverName string, hostConfig *HostOptions) (*Host, error) { - authConfig := hostConfig.AuthConfig +func NewHost(name, driverName string, hostOptions *HostOptions) (*Host, error) { + authOptions := hostOptions.AuthOptions 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 { return nil, err } return &Host{ - Name: name, - DriverName: driverName, - Driver: driver, - StorePath: storePath, - HostConfig: hostConfig, + Name: name, + DriverName: driverName, + Driver: driver, + StorePath: storePath, + HostOptions: hostOptions, }, nil } @@ -121,7 +121,7 @@ func (h *Host) Create(name string) error { 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 } } @@ -271,9 +271,9 @@ func (h *Host) LoadConfig() error { 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 { return err } @@ -294,7 +294,7 @@ func (h *Host) ConfigureAuth() error { return err } - if err := provision.ConfigureAuth(provisioner, *h.HostConfig.AuthConfig); err != nil { + if err := provision.ConfigureAuth(provisioner, *h.HostOptions.AuthOptions); err != nil { return err } diff --git a/libmachine/host_test.go b/libmachine/host_test.go index 2af66cb462..32b08c16d5 100644 --- a/libmachine/host_test.go +++ b/libmachine/host_test.go @@ -59,14 +59,14 @@ func getTestDriverFlags() *DriverOptionsMock { func getDefaultTestHost() (*Host, error) { hostOptions := &HostOptions{ - EngineConfig: &engine.EngineOptions{}, - SwarmConfig: &swarm.SwarmOptions{ + EngineOptions: &engine.EngineOptions{}, + SwarmOptions: &swarm.SwarmOptions{ Master: false, Host: "", Discovery: "", Address: "", }, - AuthConfig: &auth.AuthOptions{ + AuthOptions: &auth.AuthOptions{ CaCertPath: hostTestCaCert, PrivateKeyPath: hostTestPrivateKey, }, @@ -96,7 +96,7 @@ func TestLoadHostExists(t *testing.T) { if err != nil { t.Fatal(err) } - authConfig := host.HostConfig.AuthConfig + authOptions := host.HostOptions.AuthOptions if host.Name != hostTestName { 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) } - if authConfig.CaCertPath != hostTestCaCert { - t.Fatalf("expected ca cert path %s; received %s", hostTestCaCert, authConfig.CaCertPath) + if authOptions.CaCertPath != hostTestCaCert { + t.Fatalf("expected ca cert path %s; received %s", hostTestCaCert, authOptions.CaCertPath) } - if authConfig.PrivateKeyPath != hostTestPrivateKey { - t.Fatalf("expected key path %s; received %s", hostTestPrivateKey, authConfig.PrivateKeyPath) + if authOptions.PrivateKeyPath != hostTestPrivateKey { + 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() if err != nil { t.Fatal(err) diff --git a/libmachine/machine.go b/libmachine/machine.go index e076985022..0a43394bc3 100644 --- a/libmachine/machine.go +++ b/libmachine/machine.go @@ -19,7 +19,7 @@ func New(store Store) (*Machine, error) { }, 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) if err != nil { return nil, err @@ -30,7 +30,7 @@ func (m *Machine) Create(name string, driverName string, hostConfig *HostOptions hostPath := filepath.Join(utils.GetMachineDir(), name) - host, err := NewHost(name, driverName, hostConfig) + host, err := NewHost(name, driverName, hostOptions) if err != nil { return host, err } diff --git a/libmachine/provision/boot2docker.go b/libmachine/provision/boot2docker.go index bd874c529f..2935775976 100644 --- a/libmachine/provision/boot2docker.go +++ b/libmachine/provision/boot2docker.go @@ -27,7 +27,7 @@ func NewBoot2DockerProvisioner(d drivers.Driver) Provisioner { type Boot2DockerProvisioner struct { OsReleaseInfo *OsRelease Driver drivers.Driver - SwarmConfig swarm.SwarmOptions + SwarmOptions swarm.SwarmOptions } func (provisioner *Boot2DockerProvisioner) Service(name string, action pkgaction.ServiceAction) error { @@ -82,23 +82,23 @@ func (provisioner *Boot2DockerProvisioner) SetHostname(hostname string) error { return cmd.Run() } -func (provisioner *Boot2DockerProvisioner) GetDockerConfigDir() string { +func (provisioner *Boot2DockerProvisioner) GetDockerOptionsDir() string { return "/var/lib/boot2docker" } -func (provisioner *Boot2DockerProvisioner) GenerateDockerConfig(dockerPort int, authConfig auth.AuthOptions) (*DockerConfig, error) { - defaultDaemonOpts := getDefaultDaemonOpts(provisioner.Driver.DriverName(), authConfig) +func (provisioner *Boot2DockerProvisioner) GenerateDockerOptions(dockerPort int, authOptions auth.AuthOptions) (*DockerOptions, error) { + defaultDaemonOpts := getDefaultDaemonOpts(provisioner.Driver.DriverName(), authOptions) 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) daemonCfg := fmt.Sprintf(`EXTRA_ARGS='%s' CACERT=%s SERVERCERT=%s SERVERKEY=%s -DOCKER_TLS=no`, opts, authConfig.CaCertRemotePath, authConfig.ServerCertRemotePath, authConfig.ServerKeyRemotePath) - return &DockerConfig{ - EngineConfig: daemonCfg, - EngineConfigPath: daemonOptsCfg, +DOCKER_TLS=no`, opts, authOptions.CaCertRemotePath, authOptions.ServerCertRemotePath, authOptions.ServerKeyRemotePath) + return &DockerOptions{ + EngineOptions: daemonCfg, + EngineOptionsPath: daemonOptsDir, }, nil } @@ -110,7 +110,7 @@ func (provisioner *Boot2DockerProvisioner) SetOsReleaseInfo(info *OsRelease) { 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 { return err } @@ -119,11 +119,11 @@ func (provisioner *Boot2DockerProvisioner) Provision(swarmConfig swarm.SwarmOpti return err } - if err := ConfigureAuth(provisioner, authConfig); err != nil { + if err := ConfigureAuth(provisioner, authOptions); err != nil { return err } - if err := configureSwarm(provisioner, swarmConfig); err != nil { + if err := configureSwarm(provisioner, swarmOptions); err != nil { return err } diff --git a/libmachine/provision/provisioner.go b/libmachine/provision/provisioner.go index bb745d8e5d..9965ed829b 100644 --- a/libmachine/provision/provisioner.go +++ b/libmachine/provision/provisioner.go @@ -16,10 +16,10 @@ var provisioners = make(map[string]*RegisteredProvisioner) // Distribution specific actions type Provisioner interface { // 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 - GetDockerConfigDir() string + GetDockerOptionsDir() string // Run a package action e.g. install Package(name string, action pkgaction.PackageAction) error @@ -39,7 +39,7 @@ type Provisioner interface { // 3. Configure the daemon to accept connections over TLS. // 4. Copy the needed certificates to the server and local config dir. // 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 Service(name string, action pkgaction.ServiceAction) error diff --git a/libmachine/provision/ubuntu.go b/libmachine/provision/ubuntu.go index 71101326fc..2b446a6592 100644 --- a/libmachine/provision/ubuntu.go +++ b/libmachine/provision/ubuntu.go @@ -30,7 +30,7 @@ type UbuntuProvisioner struct { packages []string OsReleaseInfo *OsRelease Driver drivers.Driver - SwarmConfig swarm.SwarmOptions + SwarmOptions swarm.SwarmOptions } 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 } -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 { return err } @@ -87,11 +87,11 @@ func (provisioner *UbuntuProvisioner) Provision(swarmConfig swarm.SwarmOptions, return err } - if err := ConfigureAuth(provisioner, authConfig); err != nil { + if err := ConfigureAuth(provisioner, authOptions); err != nil { return err } - if err := configureSwarm(provisioner, swarmConfig); err != nil { + if err := configureSwarm(provisioner, swarmOptions); err != nil { return err } @@ -129,7 +129,7 @@ func (provisioner *UbuntuProvisioner) SetHostname(hostname string) error { return cmd.Run() } -func (provisioner *UbuntuProvisioner) GetDockerConfigDir() string { +func (provisioner *UbuntuProvisioner) GetDockerOptionsDir() string { return "/etc/docker" } @@ -145,15 +145,15 @@ func (provisioner *UbuntuProvisioner) SetOsReleaseInfo(info *OsRelease) { provisioner.OsReleaseInfo = info } -func (provisioner *UbuntuProvisioner) GenerateDockerConfig(dockerPort int, authConfig auth.AuthOptions) (*DockerConfig, error) { - defaultDaemonOpts := getDefaultDaemonOpts(provisioner.Driver.DriverName(), authConfig) +func (provisioner *UbuntuProvisioner) GenerateDockerOptions(dockerPort int, authOptions auth.AuthOptions) (*DockerOptions, error) { + defaultDaemonOpts := getDefaultDaemonOpts(provisioner.Driver.DriverName(), authOptions) 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) daemonCfg := fmt.Sprintf("export DOCKER_OPTS=\\\"%s\\\"", opts) - return &DockerConfig{ - EngineConfig: daemonCfg, - EngineConfigPath: daemonOptsCfg, + return &DockerOptions{ + EngineOptions: daemonCfg, + EngineOptionsPath: daemonOptsDir, }, nil } diff --git a/libmachine/provision/utils.go b/libmachine/provision/utils.go index 2eed1e4633..236baa31b7 100644 --- a/libmachine/provision/utils.go +++ b/libmachine/provision/utils.go @@ -17,9 +17,9 @@ import ( "github.com/docker/machine/utils" ) -type DockerConfig struct { - EngineConfig string - EngineConfigPath string +type DockerOptions struct { + EngineOptions string + EngineOptionsPath string } func installDockerGeneric(p Provisioner) error { @@ -42,7 +42,7 @@ func installDockerGeneric(p Provisioner) error { return nil } -func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error { +func ConfigureAuth(p Provisioner, authOptions auth.AuthOptions) error { var ( err error ) @@ -59,33 +59,33 @@ func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error { // copy certs to client dir for docker client 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) } - 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) } - 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.Debugf("generating server cert: %s ca-key=%s private-key=%s org=%s", - authConfig.ServerCertPath, - authConfig.CaCertPath, - authConfig.PrivateKeyPath, + authOptions.ServerCertPath, + authOptions.CaCertPath, + authOptions.PrivateKeyPath, 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 err = utils.GenerateCert( []string{ip}, - authConfig.ServerCertPath, - authConfig.ServerKeyPath, - authConfig.CaCertPath, - authConfig.PrivateKeyPath, + authOptions.ServerCertPath, + authOptions.ServerKeyPath, + authOptions.CaCertPath, + authOptions.PrivateKeyPath, org, bits, ) @@ -97,7 +97,7 @@ func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error { return err } - dockerDir := p.GetDockerConfigDir() + dockerDir := p.GetDockerOptionsDir() cmd, err := p.SSHCommand(fmt.Sprintf("sudo mkdir -p %s", dockerDir)) if err != nil { @@ -108,7 +108,7 @@ func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error { } // upload certs and configure TLS auth - caCert, err := ioutil.ReadFile(authConfig.CaCertPath) + caCert, err := ioutil.ReadFile(authOptions.CaCertPath) if err != nil { 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 // will be mucked on the linux hosts 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 { return err } 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 { return err } 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)) if err != nil { @@ -174,12 +174,12 @@ func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error { dockerPort = dPort } - dkrcfg, err := p.GenerateDockerConfig(dockerPort, authConfig) + dkrcfg, err := p.GenerateDockerOptions(dockerPort, authOptions) if err != nil { 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 { return err } @@ -194,21 +194,21 @@ func ConfigureAuth(p Provisioner, authConfig auth.AuthOptions) error { 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`, - authConfig.CaCertRemotePath, - authConfig.ServerKeyRemotePath, - authConfig.ServerCertRemotePath, + authOptions.CaCertRemotePath, + authOptions.ServerKeyRemotePath, + authOptions.ServerCertRemotePath, fmt.Sprintf("--label=provider=%s", driverName), ) } -func configureSwarm(p Provisioner, swarmConfig swarm.SwarmOptions) error { - if !swarmConfig.IsSwarm { +func configureSwarm(p Provisioner, swarmOptions swarm.SwarmOptions) error { + if !swarmOptions.IsSwarm { return nil } - basePath := p.GetDockerConfigDir() + basePath := p.GetDockerOptionsDir() ip, err := p.GetDriver().GetIP() if err != nil { return err @@ -218,10 +218,10 @@ func configureSwarm(p Provisioner, swarmConfig swarm.SwarmOptions) error { tlsCert := path.Join(basePath, "server.pem") tlsKey := path.Join(basePath, "server-key.pem") masterArgs := fmt.Sprintf("--tlsverify --tlscacert=%s --tlscert=%s --tlskey=%s -H %s %s", - tlsCaCert, tlsCert, tlsKey, swarmConfig.Host, swarmConfig.Discovery) - nodeArgs := fmt.Sprintf("--addr %s:2376 %s", ip, swarmConfig.Discovery) + tlsCaCert, tlsCert, tlsKey, swarmOptions.Host, swarmOptions.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 { return err } @@ -242,10 +242,10 @@ func configureSwarm(p Provisioner, swarmConfig swarm.SwarmOptions) error { return err } - dockerDir := p.GetDockerConfigDir() + dockerDir := p.GetDockerOptionsDir() // if master start master agent - if swarmConfig.Master { + if swarmOptions.Master { log.Debug("launching swarm master") 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", diff --git a/libmachine/provision/utils_test.go b/libmachine/provision/utils_test.go index 039fc1f7af..30bf5d889d 100644 --- a/libmachine/provision/utils_test.go +++ b/libmachine/provision/utils_test.go @@ -10,41 +10,41 @@ import ( "github.com/docker/machine/libmachine/auth" ) -func TestGenerateDockerConfigBoot2Docker(t *testing.T) { +func TestGenerateDockerOptionsBoot2Docker(t *testing.T) { p := &Boot2DockerProvisioner{ Driver: &fakedriver.FakeDriver{}, } dockerPort := 1234 - authConfig := auth.AuthOptions{ + authOptions := auth.AuthOptions{ CaCertRemotePath: "/test/ca-cert", ServerKeyRemotePath: "/test/server-key", ServerCertRemotePath: "/test/server-cert", } engineConfigPath := "/var/lib/boot2docker/profile" - dockerCfg, err := p.GenerateDockerConfig(dockerPort, authConfig) + dockerCfg, err := p.GenerateDockerOptions(dockerPort, authOptions) if err != nil { t.Fatal(err) } - if dockerCfg.EngineConfigPath != engineConfigPath { - t.Fatalf("expected engine path %s; received %s", engineConfigPath, dockerCfg.EngineConfigPath) + if dockerCfg.EngineOptionsPath != 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) } - if strings.Index(dockerCfg.EngineConfig, fmt.Sprintf("CACERT=%s", authConfig.CaCertRemotePath)) == -1 { - t.Fatalf("CACERT option invalid; expected %s", authConfig.CaCertRemotePath) + if strings.Index(dockerCfg.EngineOptions, fmt.Sprintf("CACERT=%s", authOptions.CaCertRemotePath)) == -1 { + t.Fatalf("CACERT option invalid; expected %s", authOptions.CaCertRemotePath) } - if strings.Index(dockerCfg.EngineConfig, fmt.Sprintf("SERVERKEY=%s", authConfig.ServerKeyRemotePath)) == -1 { - t.Fatalf("SERVERKEY option invalid; expected %s", authConfig.ServerKeyRemotePath) + if strings.Index(dockerCfg.EngineOptions, fmt.Sprintf("SERVERKEY=%s", authOptions.ServerKeyRemotePath)) == -1 { + t.Fatalf("SERVERKEY option invalid; expected %s", authOptions.ServerKeyRemotePath) } - if strings.Index(dockerCfg.EngineConfig, fmt.Sprintf("SERVERCERT=%s", authConfig.ServerCertRemotePath)) == -1 { - t.Fatalf("SERVERCERT option invalid; expected %s", authConfig.ServerCertRemotePath) + if strings.Index(dockerCfg.EngineOptions, fmt.Sprintf("SERVERCERT=%s", authOptions.ServerCertRemotePath)) == -1 { + t.Fatalf("SERVERCERT option invalid; expected %s", authOptions.ServerCertRemotePath) } } @@ -54,18 +54,18 @@ func TestMachinePortBoot2Docker(t *testing.T) { } dockerPort := 2376 bindUrl := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort) - authConfig := auth.AuthOptions{ + authOptions := auth.AuthOptions{ CaCertRemotePath: "/test/ca-cert", ServerKeyRemotePath: "/test/server-key", ServerCertRemotePath: "/test/server-cert", } - cfg, err := p.GenerateDockerConfig(dockerPort, authConfig) + cfg, err := p.GenerateDockerOptions(dockerPort, authOptions) if err != nil { t.Fatal(err) } re := regexp.MustCompile("-H tcp://.*:(.+)") - m := re.FindStringSubmatch(cfg.EngineConfig) + m := re.FindStringSubmatch(cfg.EngineOptions) if len(m) == 0 { t.Errorf("could not find port %d in engine config", dockerPort) } @@ -86,19 +86,19 @@ func TestMachineCustomPortBoot2Docker(t *testing.T) { } dockerPort := 3376 bindUrl := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort) - authConfig := auth.AuthOptions{ + authOptions := auth.AuthOptions{ CaCertRemotePath: "/test/ca-cert", ServerKeyRemotePath: "/test/server-key", ServerCertRemotePath: "/test/server-cert", } - cfg, err := p.GenerateDockerConfig(dockerPort, authConfig) + cfg, err := p.GenerateDockerOptions(dockerPort, authOptions) if err != nil { t.Fatal(err) } re := regexp.MustCompile("-H tcp://.*:(.+)") - m := re.FindStringSubmatch(cfg.EngineConfig) + m := re.FindStringSubmatch(cfg.EngineOptions) if len(m) == 0 { t.Errorf("could not find port %d in engine config", dockerPort) } diff --git a/libmachine/validate.go b/libmachine/validate.go index 5a73fbb2bc..a0b30c709a 100644 --- a/libmachine/validate.go +++ b/libmachine/validate.go @@ -14,15 +14,15 @@ import ( func ValidateHost(host *Host) *Host { certInfo := getCertInfoFromHost(host) - if host.HostConfig == nil { - host.HostConfig = &HostOptions{} + if host.HostOptions == nil { + host.HostOptions = &HostOptions{} } - if host.HostConfig.EngineConfig == nil { - host.HostConfig.EngineConfig = &engine.EngineOptions{} + if host.HostOptions.EngineOptions == nil { + host.HostOptions.EngineOptions = &engine.EngineOptions{} } - if host.HostConfig.SwarmConfig == nil { - host.HostConfig.SwarmConfig = &swarm.SwarmOptions{ + if host.HostOptions.SwarmOptions == nil { + host.HostOptions.SwarmOptions = &swarm.SwarmOptions{ Address: "", Discovery: host.SwarmDiscovery, 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, CaCertPath: certInfo.CaCertPath, CaCertRemotePath: "", @@ -49,12 +49,12 @@ func ValidateHost(host *Host) *Host { // validates host metadata and modifies if needed // this is used for configuration updates func ValidateHostMetadata(m *HostMetadata) *HostMetadata { - if m.HostConfig.EngineConfig == nil { - m.HostConfig.EngineConfig = &engine.EngineOptions{} + if m.HostOptions.EngineOptions == nil { + m.HostOptions.EngineOptions = &engine.EngineOptions{} } - if m.HostConfig.AuthConfig == nil { - m.HostConfig.AuthConfig = &auth.AuthOptions{ + if m.HostOptions.AuthOptions == nil { + m.HostOptions.AuthOptions = &auth.AuthOptions{ StorePath: m.StorePath, CaCertPath: m.CaCertPath, CaCertRemotePath: "", diff --git a/test/integration/helpers.bash b/test/integration/helpers.bash index efc7d2d63d..2a459c89a7 100644 --- a/test/integration/helpers.bash +++ b/test/integration/helpers.bash @@ -14,7 +14,8 @@ fi MACHINE_BIN_NAME=docker-machine_$PLATFORM-$ARCH BATS_LOG=${MACHINE_ROOT}/bats.log -truncate -s0 ${BATS_LOG} +touch ${BATS_LOG} +rm ${BATS_LOG} teardown() { echo "$BATS_TEST_NAME