cmd.go 1.2 KB

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