github.com/kunnos/engine@v1.13.1/cli/command/node/cmd.go (about)

     1  package node
     2  
     3  import (
     4  	"github.com/docker/docker/cli"
     5  	"github.com/docker/docker/cli/command"
     6  	apiclient "github.com/docker/docker/client"
     7  	"github.com/spf13/cobra"
     8  	"golang.org/x/net/context"
     9  )
    10  
    11  // NewNodeCommand returns a cobra command for `node` subcommands
    12  func NewNodeCommand(dockerCli *command.DockerCli) *cobra.Command {
    13  	cmd := &cobra.Command{
    14  		Use:   "node",
    15  		Short: "Manage Swarm nodes",
    16  		Args:  cli.NoArgs,
    17  		RunE:  dockerCli.ShowHelp,
    18  	}
    19  	cmd.AddCommand(
    20  		newDemoteCommand(dockerCli),
    21  		newInspectCommand(dockerCli),
    22  		newListCommand(dockerCli),
    23  		newPromoteCommand(dockerCli),
    24  		newRemoveCommand(dockerCli),
    25  		newPsCommand(dockerCli),
    26  		newUpdateCommand(dockerCli),
    27  	)
    28  	return cmd
    29  }
    30  
    31  // Reference returns the reference of a node. The special value "self" for a node
    32  // reference is mapped to the current node, hence the node ID is retrieved using
    33  // the `/info` endpoint.
    34  func Reference(ctx context.Context, client apiclient.APIClient, ref string) (string, error) {
    35  	if ref == "self" {
    36  		info, err := client.Info(ctx)
    37  		if err != nil {
    38  			return "", err
    39  		}
    40  		return info.Swarm.NodeID, nil
    41  	}
    42  	return ref, nil
    43  }