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