mirror of https://github.com/docker/docs.git
add discovery to machine config; show swarm membership
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
b908a9e655
commit
3a3ef6f45e
52
commands.go
52
commands.go
|
|
@ -41,14 +41,17 @@ type machineConfig struct {
|
|||
machineUrl string
|
||||
swarmMaster bool
|
||||
swarmHost string
|
||||
swarmDiscovery string
|
||||
}
|
||||
|
||||
type hostListItem struct {
|
||||
Name string
|
||||
Active bool
|
||||
DriverName string
|
||||
State state.State
|
||||
URL string
|
||||
Name string
|
||||
Active bool
|
||||
DriverName string
|
||||
State state.State
|
||||
URL string
|
||||
SwarmMaster bool
|
||||
SwarmDiscovery string
|
||||
}
|
||||
|
||||
type hostListItemByName []hostListItem
|
||||
|
|
@ -370,12 +373,15 @@ func cmdLs(c *cli.Context) {
|
|||
w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
|
||||
|
||||
if !quiet {
|
||||
fmt.Fprintln(w, "NAME\tACTIVE\tDRIVER\tSTATE\tURL")
|
||||
fmt.Fprintln(w, "NAME\tACTIVE\tDRIVER\tSTATE\tURL\tSWARM")
|
||||
}
|
||||
|
||||
items := []hostListItem{}
|
||||
hostListItems := make(chan hostListItem)
|
||||
|
||||
swarmMasters := make(map[string]string)
|
||||
swarmInfo := make(map[string]string)
|
||||
|
||||
for _, host := range hostList {
|
||||
if !quiet {
|
||||
tmpHost, err := store.GetActive()
|
||||
|
|
@ -383,6 +389,14 @@ func cmdLs(c *cli.Context) {
|
|||
log.Errorf("There's a problem with the active host: %s", err)
|
||||
}
|
||||
|
||||
if host.SwarmMaster {
|
||||
swarmMasters[host.SwarmDiscovery] = host.Name
|
||||
}
|
||||
|
||||
if host.SwarmDiscovery != "" {
|
||||
swarmInfo[host.Name] = host.SwarmDiscovery
|
||||
}
|
||||
|
||||
if tmpHost == nil {
|
||||
log.Errorf("There's a problem finding the active host")
|
||||
}
|
||||
|
|
@ -408,8 +422,17 @@ func cmdLs(c *cli.Context) {
|
|||
if item.Active {
|
||||
activeString = "*"
|
||||
}
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
|
||||
item.Name, activeString, item.DriverName, item.State, item.URL)
|
||||
|
||||
swarmInfo := ""
|
||||
|
||||
if item.SwarmDiscovery != "" {
|
||||
swarmInfo = swarmMasters[item.SwarmDiscovery]
|
||||
if item.SwarmMaster {
|
||||
swarmInfo = fmt.Sprintf("%s (master)", swarmInfo)
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n",
|
||||
item.Name, activeString, item.DriverName, item.State, item.URL, swarmInfo)
|
||||
}
|
||||
|
||||
w.Flush()
|
||||
|
|
@ -603,11 +626,13 @@ func getHostState(host Host, store Store, hostListItems chan<- hostListItem) {
|
|||
}
|
||||
|
||||
hostListItems <- hostListItem{
|
||||
Name: host.Name,
|
||||
Active: isActive,
|
||||
DriverName: host.Driver.DriverName(),
|
||||
State: currentState,
|
||||
URL: url,
|
||||
Name: host.Name,
|
||||
Active: isActive,
|
||||
DriverName: host.Driver.DriverName(),
|
||||
State: currentState,
|
||||
URL: url,
|
||||
SwarmMaster: host.SwarmMaster,
|
||||
SwarmDiscovery: host.SwarmDiscovery,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -652,5 +677,6 @@ func getMachineConfig(c *cli.Context) (*machineConfig, error) {
|
|||
machineUrl: machineUrl,
|
||||
swarmMaster: machine.SwarmMaster,
|
||||
swarmHost: machine.SwarmHost,
|
||||
swarmDiscovery: machine.SwarmDiscovery,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ type Driver struct {
|
|||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
storePath string
|
||||
keyPath string
|
||||
}
|
||||
|
|
@ -177,6 +178,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
d.RootSize = int64(flags.Int("amazonec2-root-size"))
|
||||
d.SwarmMaster = flags.Bool("swarm-master")
|
||||
d.SwarmHost = flags.String("swarm-host")
|
||||
d.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
|
||||
if d.AccessKey == "" {
|
||||
return fmt.Errorf("amazonec2 driver requires the --amazonec2-access-key option")
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ type Driver struct {
|
|||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
storePath string
|
||||
}
|
||||
|
||||
|
|
@ -163,6 +164,7 @@ func (driver *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
driver.SSHPort = flags.Int("azure-ssh-port")
|
||||
driver.SwarmMaster = flags.Bool("swarm-master")
|
||||
driver.SwarmHost = flags.String("swarm-host")
|
||||
driver.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ type Driver struct {
|
|||
DriverKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
storePath string
|
||||
}
|
||||
|
||||
|
|
@ -90,6 +91,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
d.Size = flags.String("digitalocean-size")
|
||||
d.SwarmMaster = flags.Bool("swarm-master")
|
||||
d.SwarmHost = flags.String("swarm-host")
|
||||
d.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
|
||||
if d.AccessToken == "" {
|
||||
return fmt.Errorf("digitalocean driver requires the --digitalocean-access-token option")
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ type Driver struct {
|
|||
publicSSHKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
}
|
||||
|
||||
// CreateFlags are the command line flags used to create a driver.
|
||||
|
|
@ -113,6 +114,7 @@ func (driver *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
driver.Project = flags.String("google-project")
|
||||
driver.SwarmMaster = flags.Bool("swarm-master")
|
||||
driver.SwarmHost = flags.String("swarm-host")
|
||||
driver.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
if driver.Project == "" {
|
||||
return fmt.Errorf("Please specify the Google Cloud Project name using the option --google-project.")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type Driver struct {
|
|||
memSize int
|
||||
CaCertPath string
|
||||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
@ -77,6 +80,9 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
d.vSwitch = flags.String("hyper-v-virtual-switch")
|
||||
d.diskSize = flags.Int("hyper-v-disk-size")
|
||||
d.memSize = flags.Int("hyper-v-memory")
|
||||
d.SwarmMaster = flags.Bool("swarm-master")
|
||||
d.SwarmHost = flags.String("swarm-host")
|
||||
d.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ type Driver struct {
|
|||
storePath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
client Client
|
||||
}
|
||||
|
||||
|
|
@ -231,6 +232,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
d.SSHPort = flags.Int("openstack-ssh-port")
|
||||
d.SwarmMaster = flags.Bool("swarm-master")
|
||||
d.SwarmHost = flags.String("swarm-host")
|
||||
d.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
|
||||
installDocker, err := strconv.ParseBool(flags.String("openstack-docker-install"))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ type CreateFlags struct {
|
|||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
@ -151,6 +152,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
d.EnableDockerInstall = flags.String("rackspace-docker-install") == "true"
|
||||
d.SwarmMaster = flags.Bool("swarm-master")
|
||||
d.SwarmHost = flags.String("swarm-host")
|
||||
d.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
|
||||
if d.Region == "" {
|
||||
return missingEnvOrOption("Region", "OS_REGION_NAME", "--rackspace-region")
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ type Driver struct {
|
|||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
}
|
||||
|
||||
type deviceConfig struct {
|
||||
|
|
@ -194,6 +195,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
|
||||
d.SwarmMaster = flags.Bool("swarm-master")
|
||||
d.SwarmHost = flags.String("swarm-host")
|
||||
d.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
|
||||
if err := validateClientConfig(d.Client); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ type Driver struct {
|
|||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
storePath string
|
||||
}
|
||||
|
||||
|
|
@ -102,6 +103,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
d.Boot2DockerURL = flags.String("virtualbox-boot2docker-url")
|
||||
d.SwarmMaster = flags.Bool("swarm-master")
|
||||
d.SwarmHost = flags.String("swarm-host")
|
||||
d.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ type Driver struct {
|
|||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
|
||||
storePath string
|
||||
}
|
||||
|
|
@ -102,6 +103,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
d.ISO = path.Join(d.storePath, isoFilename)
|
||||
d.SwarmMaster = flags.Bool("swarm-master")
|
||||
d.SwarmHost = flags.String("swarm-host")
|
||||
d.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ type Driver struct {
|
|||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
VAppID string
|
||||
storePath string
|
||||
}
|
||||
|
|
@ -178,6 +179,7 @@ func (driver *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
driver.PublicIP = flags.String("vmwarevcloudair-publicip")
|
||||
driver.SwarmMaster = flags.Bool("swarm-master")
|
||||
driver.SwarmHost = flags.String("swarm-host")
|
||||
driver.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
|
||||
// Check for required Params
|
||||
if driver.UserName == "" || driver.UserPassword == "" || driver.VDCID == "" || driver.PublicIP == "" {
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ type Driver struct {
|
|||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
|
||||
storePath string
|
||||
}
|
||||
|
|
@ -176,6 +177,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
d.HostIP = flags.String("vmwarevsphere-compute-ip")
|
||||
d.SwarmMaster = flags.Bool("swarm-master")
|
||||
d.SwarmHost = flags.String("swarm-host")
|
||||
d.SwarmDiscovery = flags.String("swarm-discovery")
|
||||
|
||||
d.ISO = path.Join(d.storePath, "boot2docker.iso")
|
||||
|
||||
|
|
|
|||
8
host.go
8
host.go
|
|
@ -42,6 +42,7 @@ type Host struct {
|
|||
ClientCertPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
storePath string
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +68,7 @@ func waitForDocker(addr string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func NewHost(name, driverName, storePath, caCert, privateKey string, swarmMaster bool, swarmHost string) (*Host, error) {
|
||||
func NewHost(name, driverName, storePath, caCert, privateKey string, swarmMaster bool, swarmHost string, swarmDiscovery string) (*Host, error) {
|
||||
driver, err := drivers.NewDriver(driverName, name, storePath, caCert, privateKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -80,6 +81,7 @@ func NewHost(name, driverName, storePath, caCert, privateKey string, swarmMaster
|
|||
PrivateKeyPath: privateKey,
|
||||
SwarmMaster: swarmMaster,
|
||||
SwarmHost: swarmHost,
|
||||
SwarmDiscovery: swarmDiscovery,
|
||||
storePath: storePath,
|
||||
}, nil
|
||||
}
|
||||
|
|
@ -168,6 +170,10 @@ func (h *Host) ConfigureSwarm(discovery string, master bool, host string, addr s
|
|||
parts := strings.Split(u.Host, ":")
|
||||
port := parts[1]
|
||||
|
||||
if err := waitForDocker(addr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd, err := d.GetSSHCommand(fmt.Sprintf("sudo docker pull %s", swarmDockerImage))
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
2
store.go
2
store.go
|
|
@ -38,7 +38,7 @@ func (s *Store) Create(name string, driverName string, flags drivers.DriverOptio
|
|||
|
||||
hostPath := filepath.Join(s.Path, name)
|
||||
|
||||
host, err := NewHost(name, driverName, hostPath, s.CaCertPath, s.PrivateKeyPath, flags.Bool("swarm-master"), flags.String("swarm-host"))
|
||||
host, err := NewHost(name, driverName, hostPath, s.CaCertPath, s.PrivateKeyPath, flags.Bool("swarm-master"), flags.String("swarm-host"), flags.String("swarm-discovery"))
|
||||
if err != nil {
|
||||
return host, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue