mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
c34d752419
Avoids ``` root@swarmatorium:~# docker node accept 3dnh6k13o44np9fwl83e7gh80 Node 3dnh6k13o44np9fwl83e7gh80 accepted in the swarm.root@swarmatorium:~# ``` Signed-off-by: Justin Cormack <justin.cormack@docker.com>
40 lines
930 B
Go
40 lines
930 B
Go
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"
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
func newAcceptCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
var flags *pflag.FlagSet
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "accept NODE [NODE...]",
|
|
Short: "Accept a node in the swarm",
|
|
Args: cli.RequiresMinArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return runAccept(dockerCli, flags, args)
|
|
},
|
|
}
|
|
|
|
flags = cmd.Flags()
|
|
return cmd
|
|
}
|
|
|
|
func runAccept(dockerCli *client.DockerCli, flags *pflag.FlagSet, args []string) error {
|
|
for _, id := range args {
|
|
if err := runUpdate(dockerCli, id, func(node *swarm.Node) {
|
|
node.Spec.Membership = swarm.NodeMembershipAccepted
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintf(dockerCli.Out(), "Node %s accepted in the swarm.\n", id)
|
|
}
|
|
|
|
return nil
|
|
}
|