diff --git a/command/node_drain.go b/command/node_drain.go index 18bd695c4..f6475c7be 100644 --- a/command/node_drain.go +++ b/command/node_drain.go @@ -204,21 +204,8 @@ func (c *NodeDrainCommand) Run(args []string) int { return 1 } if len(nodes) > 1 { - // Format the nodes list that matches the prefix so that the user - // can create a more specific request - out := make([]string, len(nodes)+1) - out[0] = "ID|Datacenter|Name|Class|Drain|Status" - for i, node := range nodes { - out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%v|%s", - node.ID, - node.Datacenter, - node.Name, - node.NodeClass, - node.Drain, - node.Status) - } - // Dump the output - c.Ui.Error(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", formatList(out))) + c.Ui.Error(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", + formatNodeStubList(nodes, true))) return 1 } diff --git a/command/node_eligibility.go b/command/node_eligibility.go index 2db14ddc2..b0bcbc35b 100644 --- a/command/node_eligibility.go +++ b/command/node_eligibility.go @@ -21,7 +21,7 @@ Usage: nomad node eligibility [options] To remove existing allocations, use the node drain command. It is required that either -enable or -disable is specified, but not both. - The -self flag is useful to drain the local node. + The -self flag is useful to set the scheduling eligibility of the local node. General Options: @@ -123,7 +123,7 @@ func (c *NodeEligibilityCommand) Run(args []string) int { nodeID = sanatizeUUIDPrefix(nodeID) nodes, _, err := client.Nodes().PrefixList(nodeID) if err != nil { - c.Ui.Error(fmt.Sprintf("Error toggling drain mode: %s", err)) + c.Ui.Error(fmt.Sprintf("Error updating scheduling eligibility: %s", err)) return 1 } // Return error if no nodes are found @@ -132,28 +132,15 @@ func (c *NodeEligibilityCommand) Run(args []string) int { return 1 } if len(nodes) > 1 { - // Format the nodes list that matches the prefix so that the user - // can create a more specific request - out := make([]string, len(nodes)+1) - out[0] = "ID|Datacenter|Name|Class|Drain|Status" - for i, node := range nodes { - out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%v|%s", - node.ID, - node.Datacenter, - node.Name, - node.NodeClass, - node.Drain, - node.Status) - } - // Dump the output - c.Ui.Error(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", formatList(out))) + c.Ui.Error(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", + formatNodeStubList(nodes, true))) return 1 } // Prefix lookup matched a single node node, _, err := client.Nodes().Info(nodes[0].ID, nil) if err != nil { - c.Ui.Error(fmt.Sprintf("Error toggling drain mode: %s", err)) + c.Ui.Error(fmt.Sprintf("Error updating scheduling eligibility: %s", err)) return 1 } diff --git a/command/node_status.go b/command/node_status.go index c59b8d7e6..68c72342b 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -248,24 +248,12 @@ func (c *NodeStatusCommand) Run(args []string) int { return 1 } if len(nodes) > 1 { - // Format the nodes list that matches the prefix so that the user - // can create a more specific request - out := make([]string, len(nodes)+1) - out[0] = "ID|DC|Name|Class|Drain|Eligibility|Status" - for i, node := range nodes { - out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%v|%s|%s", - limit(node.ID, c.length), - node.Datacenter, - node.Name, - node.NodeClass, - node.Drain, - node.SchedulingEligibility, - node.Status) - } // Dump the output - c.Ui.Error(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", formatList(out))) + c.Ui.Error(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", + formatNodeStubList(nodes, c.verbose))) return 1 } + // Prefix lookup matched a single node node, _, err := client.Nodes().Info(nodes[0].ID, nil) if err != nil { @@ -641,3 +629,33 @@ func getHostResources(hostStats *api.HostStats, node *api.Node) ([]string, error } return resources, nil } + +// formatNodeStubList is used to return a table format of a list of node stubs. +func formatNodeStubList(nodes []*api.NodeListStub, verbose bool) string { + // Return error if no nodes are found + if len(nodes) == 0 { + return "" + } + // Truncate the id unless full length is requested + length := shortId + if verbose { + length = fullId + } + + // Format the nodes list that matches the prefix so that the user + // can create a more specific request + out := make([]string, len(nodes)+1) + out[0] = "ID|DC|Name|Class|Drain|Eligibility|Status" + for i, node := range nodes { + out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%v|%s|%s", + limit(node.ID, length), + node.Datacenter, + node.Name, + node.NodeClass, + node.Drain, + node.SchedulingEligibility, + node.Status) + } + + return formatList(out) +}