2016-06-13 22:56:23 -04:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2016-06-13 22:56:23 -04:00
|
|
|
"github.com/docker/docker/cli"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/cli/command"
|
2016-06-13 22:56:23 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2016-09-08 13:11:39 -04:00
|
|
|
func newDemoteCommand(dockerCli *command.DockerCli) *cobra.Command {
|
2016-06-17 11:26:53 -04:00
|
|
|
return &cobra.Command{
|
2016-06-13 22:56:23 -04:00
|
|
|
Use: "demote NODE [NODE...]",
|
2016-07-29 13:41:52 -04:00
|
|
|
Short: "Demote one or more nodes from manager in the swarm",
|
2016-06-13 22:56:23 -04:00
|
|
|
Args: cli.RequiresMinArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2016-06-17 11:26:53 -04:00
|
|
|
return runDemote(dockerCli, args)
|
2016-06-13 22:56:23 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-08 13:11:39 -04:00
|
|
|
func runDemote(dockerCli *command.DockerCli, nodes []string) error {
|
2016-06-30 20:33:43 -04:00
|
|
|
demote := func(node *swarm.Node) error {
|
2016-08-05 18:51:32 -04:00
|
|
|
if node.Spec.Role == swarm.NodeRoleWorker {
|
|
|
|
fmt.Fprintf(dockerCli.Out(), "Node %s is already a worker.\n", node.ID)
|
|
|
|
return errNoRoleChange
|
|
|
|
}
|
2016-06-17 11:26:53 -04:00
|
|
|
node.Spec.Role = swarm.NodeRoleWorker
|
2016-06-30 20:33:43 -04:00
|
|
|
return nil
|
2016-06-13 22:56:23 -04:00
|
|
|
}
|
2016-06-17 11:26:53 -04:00
|
|
|
success := func(nodeID string) {
|
|
|
|
fmt.Fprintf(dockerCli.Out(), "Manager %s demoted in the swarm.\n", nodeID)
|
|
|
|
}
|
|
|
|
return updateNodes(dockerCli, nodes, demote, success)
|
2016-06-13 22:56:23 -04:00
|
|
|
}
|