本文整理汇总了Golang中github.com/docker/docker/api/types/swarm.UpdateFlags.RotateWorkerToken方法的典型用法代码示例。如果您正苦于以下问题:Golang UpdateFlags.RotateWorkerToken方法的具体用法?Golang UpdateFlags.RotateWorkerToken怎么用?Golang UpdateFlags.RotateWorkerToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/docker/api/types/swarm.UpdateFlags
的用法示例。
在下文中一共展示了UpdateFlags.RotateWorkerToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateCluster
func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
var swarm types.Spec
if err := json.NewDecoder(r.Body).Decode(&swarm); err != nil {
return err
}
rawVersion := r.URL.Query().Get("version")
version, err := strconv.ParseUint(rawVersion, 10, 64)
if err != nil {
return fmt.Errorf("Invalid swarm version '%s': %s", rawVersion, err.Error())
}
var flags types.UpdateFlags
if value := r.URL.Query().Get("rotateWorkerToken"); value != "" {
rot, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("invalid value for rotateWorkerToken: %s", value)
}
flags.RotateWorkerToken = rot
}
if value := r.URL.Query().Get("rotateManagerToken"); value != "" {
rot, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("invalid value for rotateManagerToken: %s", value)
}
flags.RotateManagerToken = rot
}
if value := r.URL.Query().Get("rotateManagerUnlockKey"); value != "" {
rot, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("invalid value for rotateManagerUnlockKey: %s", value)
}
flags.RotateManagerUnlockKey = rot
}
if err := sr.backend.Update(version, swarm, flags); err != nil {
logrus.Errorf("Error configuring swarm: %v", err)
return err
}
return nil
}
示例2: newJoinTokenCommand
func newJoinTokenCommand(dockerCli *client.DockerCli) *cobra.Command {
var rotate, quiet bool
cmd := &cobra.Command{
Use: "join-token [OPTIONS] (worker|manager)",
Short: "Manage join tokens",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
worker := args[0] == "worker"
manager := args[0] == "manager"
if !worker && !manager {
return errors.New("unknown role " + args[0])
}
client := dockerCli.Client()
ctx := context.Background()
if rotate {
var flags swarm.UpdateFlags
swarm, err := client.SwarmInspect(ctx)
if err != nil {
return err
}
flags.RotateWorkerToken = worker
flags.RotateManagerToken = manager
err = client.SwarmUpdate(ctx, swarm.Version, swarm.Spec, flags)
if err != nil {
return err
}
if !quiet {
fmt.Fprintf(dockerCli.Out(), "Succesfully rotated %s join token.\n\n", args[0])
}
}
swarm, err := client.SwarmInspect(ctx)
if err != nil {
return err
}
if quiet {
if worker {
fmt.Fprintln(dockerCli.Out(), swarm.JoinTokens.Worker)
} else {
fmt.Fprintln(dockerCli.Out(), swarm.JoinTokens.Manager)
}
} else {
info, err := client.Info(ctx)
if err != nil {
return err
}
return printJoinCommand(ctx, dockerCli, info.Swarm.NodeID, worker, manager)
}
return nil
},
}
flags := cmd.Flags()
flags.BoolVar(&rotate, flagRotate, false, "Rotate join token")
flags.BoolVarP(&quiet, flagQuiet, "q", false, "Only display token")
return cmd
}