2016-06-13 19:56:23 -07:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/client"
|
|
|
|
"github.com/docker/docker/cli"
|
|
|
|
"github.com/docker/engine-api/types/swarm"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newDemoteCommand(dockerCli *client.DockerCli) *cobra.Command {
|
2016-06-17 11:26:53 -04:00
|
|
|
return &cobra.Command{
|
2016-06-13 19:56:23 -07:00
|
|
|
Use: "demote NODE [NODE...]",
|
|
|
|
Short: "Demote a node from manager in the swarm",
|
|
|
|
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 19:56:23 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-17 11:26:53 -04:00
|
|
|
func runDemote(dockerCli *client.DockerCli, nodes []string) error {
|
|
|
|
demote := func(node *swarm.Node) {
|
|
|
|
node.Spec.Role = swarm.NodeRoleWorker
|
2016-06-13 19:56:23 -07: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 19:56:23 -07:00
|
|
|
}
|