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 newPromoteCommand(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: "promote NODE [NODE...]",
|
2016-07-29 13:41:52 -04:00
|
|
|
Short: "Promote one or more nodes to 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 runPromote(dockerCli, args)
|
2016-06-13 22:56:23 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-08 13:11:39 -04:00
|
|
|
func runPromote(dockerCli *command.DockerCli, nodes []string) error {
|
2016-06-30 20:33:43 -04:00
|
|
|
promote := func(node *swarm.Node) error {
|
2016-08-05 18:51:32 -04:00
|
|
|
if node.Spec.Role == swarm.NodeRoleManager {
|
|
|
|
fmt.Fprintf(dockerCli.Out(), "Node %s is already a manager.\n", node.ID)
|
|
|
|
return errNoRoleChange
|
|
|
|
}
|
2016-06-17 11:26:53 -04:00
|
|
|
node.Spec.Role = swarm.NodeRoleManager
|
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(), "Node %s promoted to a manager in the swarm.\n", nodeID)
|
|
|
|
}
|
|
|
|
return updateNodes(dockerCli, nodes, promote, success)
|
2016-06-13 22:56:23 -04:00
|
|
|
}
|