cmd.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. }
  17. cmd.AddCommand(
  18. newDemoteCommand(dockerCli),
  19. newInspectCommand(dockerCli),
  20. newListCommand(dockerCli),
  21. newPromoteCommand(dockerCli),
  22. newRemoveCommand(dockerCli),
  23. newPsCommand(dockerCli),
  24. newUpdateCommand(dockerCli),
  25. )
  26. return cmd
  27. }
  28. // Reference returns the reference of a node. The special value "self" for a node
  29. // reference is mapped to the current node, hence the node ID is retrieved using
  30. // the `/info` endpoint.
  31. func Reference(ctx context.Context, client apiclient.APIClient, ref string) (string, error) {
  32. if ref == "self" {
  33. info, err := client.Info(ctx)
  34. if err != nil {
  35. return "", err
  36. }
  37. return info.Swarm.NodeID, nil
  38. }
  39. return ref, nil
  40. }