func runServiceScale(dockerCli *client.DockerCli, serviceID string, scale string) error { client := dockerCli.Client() ctx := context.Background() service, err := client.ServiceInspect(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) if err != nil { return err } fmt.Fprintf(dockerCli.Out(), "%s scaled to %s\n", serviceID, scale) return nil }
func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error { client := dockerCli.Client() ctx := context.Background() getRef := func(ref string) (interface{}, []byte, error) { service, err := client.ServiceInspect(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) }
func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, serviceID string) error { client := dockerCli.Client() ctx := context.Background() service, err := client.ServiceInspect(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 }