2016-06-13 22:56:23 -04:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/cli"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/cli/command"
|
2016-09-06 14:46:37 -04:00
|
|
|
apiclient "github.com/docker/docker/client"
|
2016-09-06 20:04:43 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"golang.org/x/net/context"
|
2016-06-13 22:56:23 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewNodeCommand returns a cobra command for `node` subcommands
|
2016-09-08 13:11:39 -04:00
|
|
|
func NewNodeCommand(dockerCli *command.DockerCli) *cobra.Command {
|
2016-06-13 22:56:23 -04:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "node",
|
2016-09-12 11:37:00 -04:00
|
|
|
Short: "Manage Swarm nodes",
|
2016-06-13 22:56:23 -04:00
|
|
|
Args: cli.NoArgs,
|
2016-11-17 13:54:10 -05:00
|
|
|
RunE: dockerCli.ShowHelp,
|
2017-03-03 07:42:43 -05:00
|
|
|
Tags: map[string]string{"version": "1.24"},
|
2016-06-13 22:56:23 -04:00
|
|
|
}
|
|
|
|
cmd.AddCommand(
|
|
|
|
newDemoteCommand(dockerCli),
|
|
|
|
newInspectCommand(dockerCli),
|
|
|
|
newListCommand(dockerCli),
|
|
|
|
newPromoteCommand(dockerCli),
|
|
|
|
newRemoveCommand(dockerCli),
|
2016-07-29 05:20:59 -04:00
|
|
|
newPsCommand(dockerCli),
|
2016-06-13 22:56:23 -04:00
|
|
|
newUpdateCommand(dockerCli),
|
|
|
|
)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-06-28 13:39:49 -04:00
|
|
|
// Reference returns the reference of a node. The special value "self" for a node
|
2016-06-30 09:09:03 -04:00
|
|
|
// reference is mapped to the current node, hence the node ID is retrieved using
|
|
|
|
// the `/info` endpoint.
|
2016-09-06 20:04:43 -04:00
|
|
|
func Reference(ctx context.Context, client apiclient.APIClient, ref string) (string, error) {
|
2016-06-13 22:56:23 -04:00
|
|
|
if ref == "self" {
|
|
|
|
info, err := client.Info(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return info.Swarm.NodeID, nil
|
|
|
|
}
|
|
|
|
return ref, nil
|
|
|
|
}
|