cmd.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package node
  2. import (
  3. "github.com/docker/docker/cli"
  4. "github.com/docker/docker/cli/command"
  5. apiclient "github.com/docker/docker/client"
  6. "github.com/spf13/cobra"
  7. "golang.org/x/net/context"
  8. )
  9. // NewNodeCommand returns a cobra command for `node` subcommands
  10. func NewNodeCommand(dockerCli *command.DockerCli) *cobra.Command {
  11. cmd := &cobra.Command{
  12. Use: "node",
  13. Short: "Manage Swarm nodes",
  14. Args: cli.NoArgs,
  15. RunE: dockerCli.ShowHelp,
  16. Tags: map[string]string{"version": "1.24"},
  17. }
  18. cmd.AddCommand(
  19. newDemoteCommand(dockerCli),
  20. newInspectCommand(dockerCli),
  21. newListCommand(dockerCli),
  22. newPromoteCommand(dockerCli),
  23. newRemoveCommand(dockerCli),
  24. newPsCommand(dockerCli),
  25. newUpdateCommand(dockerCli),
  26. )
  27. return cmd
  28. }
  29. // Reference returns the reference of a node. The special value "self" for a node
  30. // reference is mapped to the current node, hence the node ID is retrieved using
  31. // the `/info` endpoint.
  32. func Reference(ctx context.Context, client apiclient.APIClient, ref string) (string, error) {
  33. if ref == "self" {
  34. info, err := client.Info(ctx)
  35. if err != nil {
  36. return "", err
  37. }
  38. return info.Swarm.NodeID, nil
  39. }
  40. return ref, nil
  41. }