예제 #1
0
파일: tasks.go 프로젝트: CheggEng/docker
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))
}
예제 #2
0
파일: inspect.go 프로젝트: CheggEng/docker
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)
}
예제 #3
0
파일: update.go 프로젝트: Florian-9/docker
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
}
예제 #4
0
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
}