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)
|
||||
}
|
||||
|
||||
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 {
|
||||
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.")
|
||||
|
|
@ -537,12 +547,12 @@ func cmdLs(c *cli.Context) {
|
|||
|
||||
for _, host := range hostList {
|
||||
if !quiet {
|
||||
if host.SwarmMaster {
|
||||
swarmMasters[host.SwarmDiscovery] = host.Name
|
||||
if host.SwarmOptions.Master {
|
||||
swarmMasters[host.SwarmOptions.Discovery] = host.Name
|
||||
}
|
||||
|
||||
if host.SwarmDiscovery != "" {
|
||||
swarmInfo[host.Name] = host.SwarmDiscovery
|
||||
if host.SwarmOptions.Discovery != "" {
|
||||
swarmInfo[host.Name] = host.SwarmOptions.Discovery
|
||||
}
|
||||
|
||||
go getHostState(*host, defaultStore, hostListItems)
|
||||
|
|
@ -1006,8 +1016,8 @@ func getHostState(host libmachine.Host, store libmachine.Store, hostListItems ch
|
|||
DriverName: host.Driver.DriverName(),
|
||||
State: currentState,
|
||||
URL: url,
|
||||
SwarmMaster: host.SwarmMaster,
|
||||
SwarmDiscovery: host.SwarmDiscovery,
|
||||
SwarmMaster: host.SwarmOptions.Master,
|
||||
SwarmDiscovery: host.SwarmOptions.Discovery,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1071,8 +1081,8 @@ func getMachineConfig(c *cli.Context) (*machineConfig, error) {
|
|||
serverCertPath: serverCert,
|
||||
serverKeyPath: serverKey,
|
||||
machineUrl: machineUrl,
|
||||
swarmMaster: machine.SwarmMaster,
|
||||
swarmHost: machine.SwarmHost,
|
||||
swarmDiscovery: machine.SwarmDiscovery,
|
||||
swarmMaster: machine.SwarmOptions.Master,
|
||||
swarmHost: machine.SwarmOptions.Host,
|
||||
swarmDiscovery: machine.SwarmOptions.Discovery,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,10 +43,9 @@ type Host struct {
|
|||
ServerCertPath string
|
||||
ServerKeyPath string
|
||||
ClientCertPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
StorePath string
|
||||
EngineOptions *EngineOptions
|
||||
SwarmOptions *SwarmOptions
|
||||
}
|
||||
|
||||
type DockerConfig struct {
|
||||
|
|
@ -71,7 +70,7 @@ func waitForDocker(addr string) error {
|
|||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -82,9 +81,8 @@ func NewHost(name, driverName, StorePath, caCert, privateKey string, swarmMaster
|
|||
Driver: driver,
|
||||
CaCertPath: caCert,
|
||||
PrivateKeyPath: privateKey,
|
||||
SwarmMaster: swarmMaster,
|
||||
SwarmHost: swarmHost,
|
||||
SwarmDiscovery: swarmDiscovery,
|
||||
EngineOptions: engineOptions,
|
||||
SwarmOptions: swarmOptions,
|
||||
StorePath: StorePath,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/docker/machine/drivers"
|
||||
"github.com/docker/machine/utils"
|
||||
)
|
||||
|
||||
|
|
@ -20,7 +19,11 @@ func New(store Store) (*Machine, error) {
|
|||
}, 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -41,12 +44,12 @@ func (m *Machine) Create(name string, driverName string, flags drivers.DriverOpt
|
|||
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 {
|
||||
return host, err
|
||||
}
|
||||
if flags != nil {
|
||||
if err := host.Driver.SetConfigFromFlags(flags); err != nil {
|
||||
if driverOptions != nil {
|
||||
if err := host.Driver.SetConfigFromFlags(driverOptions); err != nil {
|
||||
return host, err
|
||||
}
|
||||
}
|
||||
|
|
@ -71,13 +74,13 @@ func (m *Machine) Create(name string, driverName string, flags drivers.DriverOpt
|
|||
return host, err
|
||||
}
|
||||
|
||||
if flags.Bool("swarm") {
|
||||
if swarmOptions.Host != "" {
|
||||
log.Info("Configuring Swarm...")
|
||||
|
||||
discovery := flags.String("swarm-discovery")
|
||||
master := flags.Bool("swarm-master")
|
||||
swarmHost := flags.String("swarm-host")
|
||||
addr := flags.String("swarm-addr")
|
||||
discovery := swarmOptions.Discovery
|
||||
master := swarmOptions.Master
|
||||
swarmHost := swarmOptions.Host
|
||||
addr := swarmOptions.Address
|
||||
if err := host.ConfigureSwarm(discovery, master, swarmHost, addr); err != nil {
|
||||
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