MCPcopy Index your code
hub / github.com/docker/cli / Reference

Function Reference

cli/command/node/cmd.go:46–67  ·  view source on GitHub ↗

Reference returns the reference of a node. The special value "self" for a node reference is mapped to the current node, hence the node ID is retrieved using the `/info` endpoint.

(ctx context.Context, apiClient client.APIClient, ref string)

Source from the content-addressed store, hash-verified

44// reference is mapped to the current node, hence the node ID is retrieved using
45// the `/info` endpoint.
46func Reference(ctx context.Context, apiClient client.APIClient, ref string) (string, error) {
47 if ref == "self" {
48 res, err := apiClient.Info(ctx, client.InfoOptions{})
49 if err != nil {
50 return "", err
51 }
52 if res.Info.Swarm.NodeID == "" {
53 // If there's no node ID in /info, the node probably
54 // isn't a manager. Call a swarm-specific endpoint to
55 // get a more specific error message.
56 //
57 // FIXME(thaJeztah): this should not require calling a Swarm endpoint, and we could just suffice with info / ping (which has swarm status).
58 _, err = apiClient.NodeList(ctx, client.NodeListOptions{})
59 if err != nil {
60 return "", err
61 }
62 return "", errors.New("node ID not found in /info")
63 }
64 return res.Info.Swarm.NodeID, nil
65 }
66 return ref, nil
67}

Callers 2

runInspectFunction · 0.85
runPsFunction · 0.85

Calls 2

InfoMethod · 0.45
NodeListMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…