本文整理汇总了Golang中github.com/docker/docker/api/types/swarm.JoinRequest类的典型用法代码示例。如果您正苦于以下问题:Golang JoinRequest类的具体用法?Golang JoinRequest怎么用?Golang JoinRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JoinRequest类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: runJoin
func runJoin(dockerCli command.Cli, flags *pflag.FlagSet, opts joinOptions) error {
client := dockerCli.Client()
ctx := context.Background()
req := swarm.JoinRequest{
JoinToken: opts.token,
ListenAddr: opts.listenAddr.String(),
AdvertiseAddr: opts.advertiseAddr,
RemoteAddrs: []string{opts.remote},
}
if flags.Changed(flagAvailability) {
availability := swarm.NodeAvailability(strings.ToLower(opts.availability))
switch availability {
case swarm.NodeAvailabilityActive, swarm.NodeAvailabilityPause, swarm.NodeAvailabilityDrain:
req.Availability = availability
default:
return fmt.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability)
}
}
err := client.SwarmJoin(ctx, req)
if err != nil {
return err
}
info, err := client.Info(ctx)
if err != nil {
return err
}
if info.Swarm.ControlAvailable {
fmt.Fprintln(dockerCli.Out(), "This node joined a swarm as a manager.")
} else {
fmt.Fprintln(dockerCli.Out(), "This node joined a swarm as a worker.")
}
return nil
}
开发者ID:docker,项目名称:docker,代码行数:37,代码来源:join.go
示例2: Join
// Join joins a daemon to an existing cluster.
func (d *SwarmDaemon) Join(req swarm.JoinRequest) error {
if req.ListenAddr == "" {
req.ListenAddr = d.listenAddr
}
status, out, err := d.SockRequest("POST", "/swarm/join", req)
if status != http.StatusOK {
return fmt.Errorf("joining swarm: invalid statuscode %v, %q", status, out)
}
if err != nil {
return fmt.Errorf("joining swarm: %v", err)
}
info, err := d.info()
if err != nil {
return err
}
d.Info = info
return nil
}
开发者ID:Mic92,项目名称:docker,代码行数:19,代码来源:daemon_swarm.go
注:本文中的github.com/docker/docker/api/types/swarm.JoinRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论