demote.go 838 B

1234567891011121314151617181920212223242526272829303132
  1. package node
  2. import (
  3. "fmt"
  4. "github.com/docker/docker/api/client"
  5. "github.com/docker/docker/cli"
  6. "github.com/docker/engine-api/types/swarm"
  7. "github.com/spf13/cobra"
  8. )
  9. func newDemoteCommand(dockerCli *client.DockerCli) *cobra.Command {
  10. return &cobra.Command{
  11. Use: "demote NODE [NODE...]",
  12. Short: "Demote one or more nodes from manager in the swarm",
  13. Args: cli.RequiresMinArgs(1),
  14. RunE: func(cmd *cobra.Command, args []string) error {
  15. return runDemote(dockerCli, args)
  16. },
  17. }
  18. }
  19. func runDemote(dockerCli *client.DockerCli, nodes []string) error {
  20. demote := func(node *swarm.Node) error {
  21. node.Spec.Role = swarm.NodeRoleWorker
  22. return nil
  23. }
  24. success := func(nodeID string) {
  25. fmt.Fprintf(dockerCli.Out(), "Manager %s demoted in the swarm.\n", nodeID)
  26. }
  27. return updateNodes(dockerCli, nodes, demote, success)
  28. }