demote.go 808 B

12345678910111213141516171819202122232425262728293031
  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 a node 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) {
  21. node.Spec.Role = swarm.NodeRoleWorker
  22. }
  23. success := func(nodeID string) {
  24. fmt.Fprintf(dockerCli.Out(), "Manager %s demoted in the swarm.\n", nodeID)
  25. }
  26. return updateNodes(dockerCli, nodes, demote, success)
  27. }