mirror of https://github.com/docker/docs.git
Remove swarm inspect and use info instead
Remove the swarm inspect command and use docker info instead to display swarm information if the current node is a manager. Signed-off-by: Vincent Demeester <vincent@sbr.pm> (cherry picked from commit e6923f6d75c2bd1b22cc1229214ffceca3251cc6) Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
parent
0ffa19daa8
commit
a91bc28e62
|
@ -25,7 +25,6 @@ func NewSwarmCommand(dockerCli *client.DockerCli) *cobra.Command {
|
||||||
newJoinTokenCommand(dockerCli),
|
newJoinTokenCommand(dockerCli),
|
||||||
newUpdateCommand(dockerCli),
|
newUpdateCommand(dockerCli),
|
||||||
newLeaveCommand(dockerCli),
|
newLeaveCommand(dockerCli),
|
||||||
newInspectCommand(dockerCli),
|
|
||||||
)
|
)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
package swarm
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
"github.com/docker/docker/api/client"
|
|
||||||
"github.com/docker/docker/api/client/inspect"
|
|
||||||
"github.com/docker/docker/cli"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
type inspectOptions struct {
|
|
||||||
format string
|
|
||||||
}
|
|
||||||
|
|
||||||
func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
||||||
var opts inspectOptions
|
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
|
||||||
Use: "inspect [OPTIONS]",
|
|
||||||
Short: "Inspect the swarm",
|
|
||||||
Args: cli.NoArgs,
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
return runInspect(dockerCli, opts)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
flags := cmd.Flags()
|
|
||||||
flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
|
|
||||||
return cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
|
|
||||||
client := dockerCli.Client()
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
swarm, err := client.SwarmInspect(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
getRef := func(_ string) (interface{}, []byte, error) {
|
|
||||||
return swarm, nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return inspect.Inspect(dockerCli.Out(), []string{""}, opts.format, getRef)
|
|
||||||
}
|
|
|
@ -3,6 +3,7 @@ package system
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
@ -30,7 +31,8 @@ func NewInfoCommand(dockerCli *client.DockerCli) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runInfo(dockerCli *client.DockerCli) error {
|
func runInfo(dockerCli *client.DockerCli) error {
|
||||||
info, err := dockerCli.Client().Info(context.Background())
|
ctx := context.Background()
|
||||||
|
info, err := dockerCli.Client().Info(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -83,8 +85,20 @@ func runInfo(dockerCli *client.DockerCli) error {
|
||||||
}
|
}
|
||||||
fmt.Fprintf(dockerCli.Out(), " Is Manager: %v\n", info.Swarm.ControlAvailable)
|
fmt.Fprintf(dockerCli.Out(), " Is Manager: %v\n", info.Swarm.ControlAvailable)
|
||||||
if info.Swarm.ControlAvailable {
|
if info.Swarm.ControlAvailable {
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " ClusterID: %s\n", info.Swarm.Cluster.ID)
|
||||||
fmt.Fprintf(dockerCli.Out(), " Managers: %d\n", info.Swarm.Managers)
|
fmt.Fprintf(dockerCli.Out(), " Managers: %d\n", info.Swarm.Managers)
|
||||||
fmt.Fprintf(dockerCli.Out(), " Nodes: %d\n", info.Swarm.Nodes)
|
fmt.Fprintf(dockerCli.Out(), " Nodes: %d\n", info.Swarm.Nodes)
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " Name: %s\n", info.Swarm.Cluster.Spec.Annotations.Name)
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " Orchestration:\n")
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " Task History Retention: %d\n", info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit)
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " Raft:\n")
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " Snapshot interval: %d\n", info.Swarm.Cluster.Spec.Raft.SnapshotInterval)
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " Heartbeat tick: %d\n", info.Swarm.Cluster.Spec.Raft.HeartbeatTick)
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " Election tick: %d\n", info.Swarm.Cluster.Spec.Raft.ElectionTick)
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " Dispatcher:\n")
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " Heartbeat period: %s\n", units.HumanDuration(time.Duration(info.Swarm.Cluster.Spec.Dispatcher.HeartbeatPeriod)))
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " CA configuration:\n")
|
||||||
|
fmt.Fprintf(dockerCli.Out(), " Expiry duration: %s\n", units.HumanDuration(info.Swarm.Cluster.Spec.CAConfig.NodeCertExpiry))
|
||||||
}
|
}
|
||||||
fmt.Fprintf(dockerCli.Out(), " Node Address: %s\n", info.Swarm.NodeAddr)
|
fmt.Fprintf(dockerCli.Out(), " Node Address: %s\n", info.Swarm.NodeAddr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -729,6 +729,11 @@ func (c *Cluster) Info() types.Info {
|
||||||
|
|
||||||
if c.isActiveManager() {
|
if c.isActiveManager() {
|
||||||
info.ControlAvailable = true
|
info.ControlAvailable = true
|
||||||
|
swarm, err := c.Inspect()
|
||||||
|
if err != nil {
|
||||||
|
info.Error = err.Error()
|
||||||
|
}
|
||||||
|
info.Cluster = swarm
|
||||||
if r, err := c.client.ListNodes(ctx, &swarmapi.ListNodesRequest{}); err == nil {
|
if r, err := c.client.ListNodes(ctx, &swarmapi.ListNodesRequest{}); err == nil {
|
||||||
info.Nodes = len(r.Nodes)
|
info.Nodes = len(r.Nodes)
|
||||||
for _, n := range r.Nodes {
|
for _, n := range r.Nodes {
|
||||||
|
|
|
@ -246,18 +246,22 @@ func (d *SwarmDaemon) listServices(c *check.C) []swarm.Service {
|
||||||
return services
|
return services
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SwarmDaemon) updateSwarm(c *check.C, f ...specConstructor) {
|
func (d *SwarmDaemon) getSwarm(c *check.C) swarm.Swarm {
|
||||||
var sw swarm.Swarm
|
var sw swarm.Swarm
|
||||||
status, out, err := d.SockRequest("GET", "/swarm", nil)
|
status, out, err := d.SockRequest("GET", "/swarm", nil)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
||||||
c.Assert(json.Unmarshal(out, &sw), checker.IsNil)
|
c.Assert(json.Unmarshal(out, &sw), checker.IsNil)
|
||||||
|
return sw
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *SwarmDaemon) updateSwarm(c *check.C, f ...specConstructor) {
|
||||||
|
sw := d.getSwarm(c)
|
||||||
for _, fn := range f {
|
for _, fn := range f {
|
||||||
fn(&sw.Spec)
|
fn(&sw.Spec)
|
||||||
}
|
}
|
||||||
url := fmt.Sprintf("/swarm/update?version=%d", sw.Version.Index)
|
url := fmt.Sprintf("/swarm/update?version=%d", sw.Version.Index)
|
||||||
status, out, err = d.SockRequest("POST", url, sw.Spec)
|
status, out, err := d.SockRequest("POST", url, sw.Spec)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -17,12 +16,8 @@ func (s *DockerSwarmSuite) TestSwarmUpdate(c *check.C) {
|
||||||
d := s.AddDaemon(c, true, true)
|
d := s.AddDaemon(c, true, true)
|
||||||
|
|
||||||
getSpec := func() swarm.Spec {
|
getSpec := func() swarm.Spec {
|
||||||
out, err := d.Cmd("swarm", "inspect")
|
sw := d.getSwarm(c)
|
||||||
c.Assert(err, checker.IsNil)
|
return sw.Spec
|
||||||
var sw []swarm.Swarm
|
|
||||||
c.Assert(json.Unmarshal([]byte(out), &sw), checker.IsNil)
|
|
||||||
c.Assert(len(sw), checker.Equals, 1)
|
|
||||||
return sw[0].Spec
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := d.Cmd("swarm", "update", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s")
|
out, err := d.Cmd("swarm", "update", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s")
|
||||||
|
@ -44,12 +39,8 @@ func (s *DockerSwarmSuite) TestSwarmInit(c *check.C) {
|
||||||
d := s.AddDaemon(c, false, false)
|
d := s.AddDaemon(c, false, false)
|
||||||
|
|
||||||
getSpec := func() swarm.Spec {
|
getSpec := func() swarm.Spec {
|
||||||
out, err := d.Cmd("swarm", "inspect")
|
sw := d.getSwarm(c)
|
||||||
c.Assert(err, checker.IsNil)
|
return sw.Spec
|
||||||
var sw []swarm.Swarm
|
|
||||||
c.Assert(json.Unmarshal([]byte(out), &sw), checker.IsNil)
|
|
||||||
c.Assert(len(sw), checker.Equals, 1)
|
|
||||||
return sw[0].Spec
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := d.Cmd("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s")
|
out, err := d.Cmd("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s")
|
||||||
|
|
|
@ -118,6 +118,8 @@ type Info struct {
|
||||||
RemoteManagers []Peer
|
RemoteManagers []Peer
|
||||||
Nodes int
|
Nodes int
|
||||||
Managers int
|
Managers int
|
||||||
|
|
||||||
|
Cluster Swarm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peer represents a peer.
|
// Peer represents a peer.
|
||||||
|
|
Loading…
Reference in New Issue