func runTasks(dockerCli *client.DockerCli, opts tasksOptions) error { client := dockerCli.Client() ctx := context.Background() nodeRef, err := nodeReference(client, ctx, opts.nodeID) if err != nil { return nil } node, err := client.NodeInspect(ctx, nodeRef) if err != nil { return err } filter := opts.filter.Value() filter.Add("node", node.ID) if !opts.all { 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)) }
func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error { client := dockerCli.Client() ctx := context.Background() getRef := func(ref string) (interface{}, []byte, error) { nodeRef, err := nodeReference(client, ctx, ref) if err != nil { return nil, nil, err } node, err := client.NodeInspect(ctx, nodeRef) return node, nil, err } if !opts.pretty { return inspect.Inspect(dockerCli.Out(), opts.nodeIds, opts.format, getRef) } return printHumanFriendly(dockerCli.Out(), opts.nodeIds, getRef) }
func runUpdate(dockerCli *client.DockerCli, nodeID string, mergeNode func(node *swarm.Node)) error { client := dockerCli.Client() ctx := context.Background() node, err := client.NodeInspect(ctx, nodeID) if err != nil { return err } mergeNode(&node) err = client.NodeUpdate(ctx, node.ID, node.Version, node.Spec) if err != nil { return err } return nil }
func updateNodes(dockerCli *client.DockerCli, nodes []string, mergeNode func(node *swarm.Node), success func(nodeID string)) error { client := dockerCli.Client() ctx := context.Background() for _, nodeID := range nodes { node, err := client.NodeInspect(ctx, nodeID) if err != nil { return err } mergeNode(&node) err = client.NodeUpdate(ctx, node.ID, node.Version, node.Spec) if err != nil { return err } success(nodeID) } return nil }