mirror of https://github.com/docker/docs.git
libmachine: add engine and swarm options
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
56b229a767
commit
31b63a1204
30
commands.go
30
commands.go
|
|
@ -391,7 +391,17 @@ func cmdCreate(c *cli.Context) {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
host, err := mcn.Create(name, driver, c)
|
hostOptions := &libmachine.HostOptions{
|
||||||
|
EngineOptions: &libmachine.EngineOptions{},
|
||||||
|
SwarmOptions: &libmachine.SwarmOptions{
|
||||||
|
Master: c.GlobalBool("swarm-master"),
|
||||||
|
Discovery: c.GlobalString("swarm-discovery"),
|
||||||
|
Address: c.GlobalString("swarm-addr"),
|
||||||
|
Host: c.GlobalString("swarm-host"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
host, err := mcn.Create(name, driver, hostOptions)
|
||||||
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.")
|
||||||
|
|
@ -537,12 +547,12 @@ func cmdLs(c *cli.Context) {
|
||||||
|
|
||||||
for _, host := range hostList {
|
for _, host := range hostList {
|
||||||
if !quiet {
|
if !quiet {
|
||||||
if host.SwarmMaster {
|
if host.SwarmOptions.Master {
|
||||||
swarmMasters[host.SwarmDiscovery] = host.Name
|
swarmMasters[host.SwarmOptions.Discovery] = host.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
if host.SwarmDiscovery != "" {
|
if host.SwarmOptions.Discovery != "" {
|
||||||
swarmInfo[host.Name] = host.SwarmDiscovery
|
swarmInfo[host.Name] = host.SwarmOptions.Discovery
|
||||||
}
|
}
|
||||||
|
|
||||||
go getHostState(*host, defaultStore, hostListItems)
|
go getHostState(*host, defaultStore, hostListItems)
|
||||||
|
|
@ -1006,8 +1016,8 @@ 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,
|
||||||
SwarmMaster: host.SwarmMaster,
|
SwarmMaster: host.SwarmOptions.Master,
|
||||||
SwarmDiscovery: host.SwarmDiscovery,
|
SwarmDiscovery: host.SwarmOptions.Discovery,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1071,8 +1081,8 @@ func getMachineConfig(c *cli.Context) (*machineConfig, error) {
|
||||||
serverCertPath: serverCert,
|
serverCertPath: serverCert,
|
||||||
serverKeyPath: serverKey,
|
serverKeyPath: serverKey,
|
||||||
machineUrl: machineUrl,
|
machineUrl: machineUrl,
|
||||||
swarmMaster: machine.SwarmMaster,
|
swarmMaster: machine.SwarmOptions.Master,
|
||||||
swarmHost: machine.SwarmHost,
|
swarmHost: machine.SwarmOptions.Host,
|
||||||
swarmDiscovery: machine.SwarmDiscovery,
|
swarmDiscovery: machine.SwarmOptions.Discovery,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,9 @@ type Host struct {
|
||||||
ServerCertPath string
|
ServerCertPath string
|
||||||
ServerKeyPath string
|
ServerKeyPath string
|
||||||
ClientCertPath string
|
ClientCertPath string
|
||||||
SwarmMaster bool
|
|
||||||
SwarmHost string
|
|
||||||
SwarmDiscovery string
|
|
||||||
StorePath string
|
StorePath string
|
||||||
|
EngineOptions *EngineOptions
|
||||||
|
SwarmOptions *SwarmOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
type DockerConfig struct {
|
type DockerConfig struct {
|
||||||
|
|
@ -71,7 +70,7 @@ func waitForDocker(addr string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHost(name, driverName, StorePath, caCert, privateKey string, swarmMaster bool, swarmHost string, swarmDiscovery string) (*Host, error) {
|
func NewHost(name, driverName, StorePath, caCert, privateKey string, engineOptions *EngineOptions, swarmOptions *SwarmOptions) (*Host, error) {
|
||||||
driver, err := drivers.NewDriver(driverName, name, StorePath, caCert, privateKey)
|
driver, err := drivers.NewDriver(driverName, name, StorePath, caCert, privateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -82,9 +81,8 @@ func NewHost(name, driverName, StorePath, caCert, privateKey string, swarmMaster
|
||||||
Driver: driver,
|
Driver: driver,
|
||||||
CaCertPath: caCert,
|
CaCertPath: caCert,
|
||||||
PrivateKeyPath: privateKey,
|
PrivateKeyPath: privateKey,
|
||||||
SwarmMaster: swarmMaster,
|
EngineOptions: engineOptions,
|
||||||
SwarmHost: swarmHost,
|
SwarmOptions: swarmOptions,
|
||||||
SwarmDiscovery: swarmDiscovery,
|
|
||||||
StorePath: StorePath,
|
StorePath: StorePath,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/machine/drivers"
|
|
||||||
"github.com/docker/machine/utils"
|
"github.com/docker/machine/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -20,7 +19,11 @@ func New(store Store) (*Machine, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) Create(name string, driverName string, flags drivers.DriverOptions) (*Host, error) {
|
func (m *Machine) Create(name string, driverName string, options *HostOptions) (*Host, error) {
|
||||||
|
driverOptions := options.DriverOptions
|
||||||
|
engineOptions := options.EngineOptions
|
||||||
|
swarmOptions := options.SwarmOptions
|
||||||
|
|
||||||
exists, err := m.store.Exists(name)
|
exists, err := m.store.Exists(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -41,12 +44,12 @@ func (m *Machine) Create(name string, driverName string, flags drivers.DriverOpt
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
host, err := NewHost(name, driverName, hostPath, caCert, privateKey, flags.Bool("swarm-master"), flags.String("swarm-host"), flags.String("swarm-discovery"))
|
host, err := NewHost(name, driverName, hostPath, caCert, privateKey, engineOptions, swarmOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return host, err
|
return host, err
|
||||||
}
|
}
|
||||||
if flags != nil {
|
if driverOptions != nil {
|
||||||
if err := host.Driver.SetConfigFromFlags(flags); err != nil {
|
if err := host.Driver.SetConfigFromFlags(driverOptions); err != nil {
|
||||||
return host, err
|
return host, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -71,13 +74,13 @@ func (m *Machine) Create(name string, driverName string, flags drivers.DriverOpt
|
||||||
return host, err
|
return host, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.Bool("swarm") {
|
if swarmOptions.Host != "" {
|
||||||
log.Info("Configuring Swarm...")
|
log.Info("Configuring Swarm...")
|
||||||
|
|
||||||
discovery := flags.String("swarm-discovery")
|
discovery := swarmOptions.Discovery
|
||||||
master := flags.Bool("swarm-master")
|
master := swarmOptions.Master
|
||||||
swarmHost := flags.String("swarm-host")
|
swarmHost := swarmOptions.Host
|
||||||
addr := flags.String("swarm-addr")
|
addr := swarmOptions.Address
|
||||||
if err := host.ConfigureSwarm(discovery, master, swarmHost, addr); err != nil {
|
if err := host.ConfigureSwarm(discovery, master, swarmHost, addr); err != nil {
|
||||||
log.Errorf("Error configuring Swarm: %s", err)
|
log.Errorf("Error configuring Swarm: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package libmachine
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/docker/machine/drivers"
|
||||||
|
)
|
||||||
|
|
||||||
|
type EngineOptions struct {
|
||||||
|
Dns []string
|
||||||
|
GraphDir string
|
||||||
|
Ipv6 bool
|
||||||
|
Labels []string
|
||||||
|
LogLevel string
|
||||||
|
StorageDriver string
|
||||||
|
SelinuxEnabled bool
|
||||||
|
TlsCaCert string
|
||||||
|
TlsCert string
|
||||||
|
TlsKey string
|
||||||
|
TlsVerify bool
|
||||||
|
RegistryMirror []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type SwarmOptions struct {
|
||||||
|
Address string
|
||||||
|
Discovery string
|
||||||
|
Master bool
|
||||||
|
Host string
|
||||||
|
Strategy string
|
||||||
|
Heartbeat int
|
||||||
|
Overcommit float64
|
||||||
|
TlsCaCert string
|
||||||
|
TlsCert string
|
||||||
|
TlsKey string
|
||||||
|
TlsVerify bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type HostOptions struct {
|
||||||
|
Driver string
|
||||||
|
Memory int
|
||||||
|
Disk int
|
||||||
|
DriverOptions drivers.DriverOptions
|
||||||
|
EngineOptions *EngineOptions
|
||||||
|
SwarmOptions *SwarmOptions
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue