本文整理汇总了Golang中github.com/docker/docker/api/client.ServiceInspectWithRaw函数的典型用法代码示例。如果您正苦于以下问题:Golang ServiceInspectWithRaw函数的具体用法?Golang ServiceInspectWithRaw怎么用?Golang ServiceInspectWithRaw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceInspectWithRaw函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runPS
func runPS(dockerCli *client.DockerCli, opts psOptions) error {
client := dockerCli.Client()
ctx := context.Background()
service, _, err := client.ServiceInspectWithRaw(ctx, opts.serviceID)
if err != nil {
return err
}
filter := opts.filter.Value()
filter.Add("service", service.ID)
if filter.Include("node") {
nodeFilters := filter.Get("node")
for _, nodeFilter := range nodeFilters {
nodeReference, err := node.Reference(client, ctx, nodeFilter)
if err != nil {
return err
}
filter.Del("node", nodeFilter)
filter.Add("node", nodeReference)
}
}
tasks, err := client.TaskList(ctx, types.TaskListOptions{Filter: filter})
if err != nil {
return err
}
return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve))
}
示例2: runServiceScale
func runServiceScale(dockerCli *client.DockerCli, serviceID string, scale string) error {
client := dockerCli.Client()
ctx := context.Background()
service, _, err := client.ServiceInspectWithRaw(ctx, serviceID)
if err != nil {
return err
}
serviceMode := &service.Spec.Mode
if serviceMode.Replicated == nil {
return fmt.Errorf("scale can only be used with replicated mode")
}
uintScale, err := strconv.ParseUint(scale, 10, 64)
if err != nil {
return fmt.Errorf("invalid replicas value %s: %s", scale, err.Error())
}
serviceMode.Replicated.Replicas = &uintScale
err = client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, nil)
if err != nil {
return err
}
fmt.Fprintf(dockerCli.Out(), "%s scaled to %s\n", serviceID, scale)
return nil
}
示例3: runInspect
func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
client := dockerCli.Client()
ctx := context.Background()
getRef := func(ref string) (interface{}, []byte, error) {
service, _, err := client.ServiceInspectWithRaw(ctx, ref)
if err == nil || !apiclient.IsErrServiceNotFound(err) {
return service, nil, err
}
return nil, nil, fmt.Errorf("Error: no such service: %s", ref)
}
if !opts.pretty {
return inspect.Inspect(dockerCli.Out(), opts.refs, opts.format, getRef)
}
return printHumanFriendly(dockerCli.Out(), opts.refs, getRef)
}
示例4: runUpdate
func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, serviceID string) error {
client := dockerCli.Client()
ctx := context.Background()
service, _, err := client.ServiceInspectWithRaw(ctx, serviceID)
if err != nil {
return err
}
err = mergeService(&service.Spec, flags)
if err != nil {
return err
}
err = client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec)
if err != nil {
return err
}
fmt.Fprintf(dockerCli.Out(), "%s\n", serviceID)
return nil
}
示例5: runTasks
func runTasks(dockerCli *client.DockerCli, opts tasksOptions) error {
client := dockerCli.Client()
ctx := context.Background()
service, _, err := client.ServiceInspectWithRaw(ctx, opts.serviceID)
if err != nil {
return err
}
filter := opts.filter.Value()
filter.Add("service", service.ID)
if !opts.all && !filter.Include("desired_state") {
filter.Add("desired_state", string(swarm.TaskStateRunning))
filter.Add("desired_state", string(swarm.TaskStateAccepted))
}
tasks, err := client.TaskList(ctx, types.TaskListOptions{Filter: filter})
if err != nil {
return err
}
return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve))
}