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>
| 32 | 31 |
deleted file mode 100644 |
| ... | ... |
@@ -1,47 +0,0 @@ |
| 1 |
-package swarm |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "golang.org/x/net/context" |
|
| 5 |
- |
|
| 6 |
- "github.com/docker/docker/api/client" |
|
| 7 |
- "github.com/docker/docker/api/client/inspect" |
|
| 8 |
- "github.com/docker/docker/cli" |
|
| 9 |
- "github.com/spf13/cobra" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-type inspectOptions struct {
|
|
| 13 |
- format string |
|
| 14 |
-} |
|
| 15 |
- |
|
| 16 |
-func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
| 17 |
- var opts inspectOptions |
|
| 18 |
- |
|
| 19 |
- cmd := &cobra.Command{
|
|
| 20 |
- Use: "inspect [OPTIONS]", |
|
| 21 |
- Short: "Inspect the swarm", |
|
| 22 |
- Args: cli.NoArgs, |
|
| 23 |
- RunE: func(cmd *cobra.Command, args []string) error {
|
|
| 24 |
- return runInspect(dockerCli, opts) |
|
| 25 |
- }, |
|
| 26 |
- } |
|
| 27 |
- |
|
| 28 |
- flags := cmd.Flags() |
|
| 29 |
- flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template") |
|
| 30 |
- return cmd |
|
| 31 |
-} |
|
| 32 |
- |
|
| 33 |
-func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
|
|
| 34 |
- client := dockerCli.Client() |
|
| 35 |
- ctx := context.Background() |
|
| 36 |
- |
|
| 37 |
- swarm, err := client.SwarmInspect(ctx) |
|
| 38 |
- if err != nil {
|
|
| 39 |
- return err |
|
| 40 |
- } |
|
| 41 |
- |
|
| 42 |
- getRef := func(_ string) (interface{}, []byte, error) {
|
|
| 43 |
- return swarm, nil, nil |
|
| 44 |
- } |
|
| 45 |
- |
|
| 46 |
- return inspect.Inspect(dockerCli.Out(), []string{""}, opts.format, getRef)
|
|
| 47 |
-} |
| ... | ... |
@@ -3,6 +3,7 @@ package system |
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"strings" |
| 6 |
+ "time" |
|
| 6 | 7 |
|
| 7 | 8 |
"golang.org/x/net/context" |
| 8 | 9 |
|
| ... | ... |
@@ -30,7 +31,8 @@ func NewInfoCommand(dockerCli *client.DockerCli) *cobra.Command {
|
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 | 32 |
func runInfo(dockerCli *client.DockerCli) error {
|
| 33 |
- info, err := dockerCli.Client().Info(context.Background()) |
|
| 33 |
+ ctx := context.Background() |
|
| 34 |
+ info, err := dockerCli.Client().Info(ctx) |
|
| 34 | 35 |
if err != nil {
|
| 35 | 36 |
return err |
| 36 | 37 |
} |
| ... | ... |
@@ -83,8 +85,20 @@ func runInfo(dockerCli *client.DockerCli) error {
|
| 83 | 83 |
} |
| 84 | 84 |
fmt.Fprintf(dockerCli.Out(), " Is Manager: %v\n", info.Swarm.ControlAvailable) |
| 85 | 85 |
if info.Swarm.ControlAvailable {
|
| 86 |
+ fmt.Fprintf(dockerCli.Out(), " ClusterID: %s\n", info.Swarm.Cluster.ID) |
|
| 86 | 87 |
fmt.Fprintf(dockerCli.Out(), " Managers: %d\n", info.Swarm.Managers) |
| 87 | 88 |
fmt.Fprintf(dockerCli.Out(), " Nodes: %d\n", info.Swarm.Nodes) |
| 89 |
+ fmt.Fprintf(dockerCli.Out(), " Name: %s\n", info.Swarm.Cluster.Spec.Annotations.Name) |
|
| 90 |
+ fmt.Fprintf(dockerCli.Out(), " Orchestration:\n") |
|
| 91 |
+ fmt.Fprintf(dockerCli.Out(), " Task History Retention: %d\n", info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit) |
|
| 92 |
+ fmt.Fprintf(dockerCli.Out(), " Raft:\n") |
|
| 93 |
+ fmt.Fprintf(dockerCli.Out(), " Snapshot interval: %d\n", info.Swarm.Cluster.Spec.Raft.SnapshotInterval) |
|
| 94 |
+ fmt.Fprintf(dockerCli.Out(), " Heartbeat tick: %d\n", info.Swarm.Cluster.Spec.Raft.HeartbeatTick) |
|
| 95 |
+ fmt.Fprintf(dockerCli.Out(), " Election tick: %d\n", info.Swarm.Cluster.Spec.Raft.ElectionTick) |
|
| 96 |
+ fmt.Fprintf(dockerCli.Out(), " Dispatcher:\n") |
|
| 97 |
+ fmt.Fprintf(dockerCli.Out(), " Heartbeat period: %s\n", units.HumanDuration(time.Duration(info.Swarm.Cluster.Spec.Dispatcher.HeartbeatPeriod))) |
|
| 98 |
+ fmt.Fprintf(dockerCli.Out(), " CA configuration:\n") |
|
| 99 |
+ fmt.Fprintf(dockerCli.Out(), " Expiry duration: %s\n", units.HumanDuration(info.Swarm.Cluster.Spec.CAConfig.NodeCertExpiry)) |
|
| 88 | 100 |
} |
| 89 | 101 |
fmt.Fprintf(dockerCli.Out(), " Node Address: %s\n", info.Swarm.NodeAddr) |
| 90 | 102 |
} |
| ... | ... |
@@ -729,6 +729,11 @@ func (c *Cluster) Info() types.Info {
|
| 729 | 729 |
|
| 730 | 730 |
if c.isActiveManager() {
|
| 731 | 731 |
info.ControlAvailable = true |
| 732 |
+ swarm, err := c.Inspect() |
|
| 733 |
+ if err != nil {
|
|
| 734 |
+ info.Error = err.Error() |
|
| 735 |
+ } |
|
| 736 |
+ info.Cluster = swarm |
|
| 732 | 737 |
if r, err := c.client.ListNodes(ctx, &swarmapi.ListNodesRequest{}); err == nil {
|
| 733 | 738 |
info.Nodes = len(r.Nodes) |
| 734 | 739 |
for _, n := range r.Nodes {
|
| ... | ... |
@@ -246,18 +246,22 @@ func (d *SwarmDaemon) listServices(c *check.C) []swarm.Service {
|
| 246 | 246 |
return services |
| 247 | 247 |
} |
| 248 | 248 |
|
| 249 |
-func (d *SwarmDaemon) updateSwarm(c *check.C, f ...specConstructor) {
|
|
| 249 |
+func (d *SwarmDaemon) getSwarm(c *check.C) swarm.Swarm {
|
|
| 250 | 250 |
var sw swarm.Swarm |
| 251 | 251 |
status, out, err := d.SockRequest("GET", "/swarm", nil)
|
| 252 | 252 |
c.Assert(err, checker.IsNil) |
| 253 | 253 |
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
| 254 | 254 |
c.Assert(json.Unmarshal(out, &sw), checker.IsNil) |
| 255 |
+ return sw |
|
| 256 |
+} |
|
| 255 | 257 |
|
| 258 |
+func (d *SwarmDaemon) updateSwarm(c *check.C, f ...specConstructor) {
|
|
| 259 |
+ sw := d.getSwarm(c) |
|
| 256 | 260 |
for _, fn := range f {
|
| 257 | 261 |
fn(&sw.Spec) |
| 258 | 262 |
} |
| 259 | 263 |
url := fmt.Sprintf("/swarm/update?version=%d", sw.Version.Index)
|
| 260 |
- status, out, err = d.SockRequest("POST", url, sw.Spec)
|
|
| 264 |
+ status, out, err := d.SockRequest("POST", url, sw.Spec)
|
|
| 261 | 265 |
c.Assert(err, checker.IsNil) |
| 262 | 266 |
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
| 263 | 267 |
} |
| ... | ... |
@@ -3,7 +3,6 @@ |
| 3 | 3 |
package main |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
- "encoding/json" |
|
| 7 | 6 |
"io/ioutil" |
| 8 | 7 |
"strings" |
| 9 | 8 |
"time" |
| ... | ... |
@@ -17,12 +16,8 @@ func (s *DockerSwarmSuite) TestSwarmUpdate(c *check.C) {
|
| 17 | 17 |
d := s.AddDaemon(c, true, true) |
| 18 | 18 |
|
| 19 | 19 |
getSpec := func() swarm.Spec {
|
| 20 |
- out, err := d.Cmd("swarm", "inspect")
|
|
| 21 |
- c.Assert(err, checker.IsNil) |
|
| 22 |
- var sw []swarm.Swarm |
|
| 23 |
- c.Assert(json.Unmarshal([]byte(out), &sw), checker.IsNil) |
|
| 24 |
- c.Assert(len(sw), checker.Equals, 1) |
|
| 25 |
- return sw[0].Spec |
|
| 20 |
+ sw := d.getSwarm(c) |
|
| 21 |
+ return sw.Spec |
|
| 26 | 22 |
} |
| 27 | 23 |
|
| 28 | 24 |
out, err := d.Cmd("swarm", "update", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s")
|
| ... | ... |
@@ -44,12 +39,8 @@ func (s *DockerSwarmSuite) TestSwarmInit(c *check.C) {
|
| 44 | 44 |
d := s.AddDaemon(c, false, false) |
| 45 | 45 |
|
| 46 | 46 |
getSpec := func() swarm.Spec {
|
| 47 |
- out, err := d.Cmd("swarm", "inspect")
|
|
| 48 |
- c.Assert(err, checker.IsNil) |
|
| 49 |
- var sw []swarm.Swarm |
|
| 50 |
- c.Assert(json.Unmarshal([]byte(out), &sw), checker.IsNil) |
|
| 51 |
- c.Assert(len(sw), checker.Equals, 1) |
|
| 52 |
- return sw[0].Spec |
|
| 47 |
+ sw := d.getSwarm(c) |
|
| 48 |
+ return sw.Spec |
|
| 53 | 49 |
} |
| 54 | 50 |
|
| 55 | 51 |
out, err := d.Cmd("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s")
|