From db2dd3b614dd6ae2a9f381cefdb20d32b8ae926d Mon Sep 17 00:00:00 2001 From: Abhishek Chanda Date: Tue, 20 Oct 2015 18:00:00 -0700 Subject: [PATCH] Show node attribute in node-status Adds node attributes to the node-status command when a single node ID is passed --- command/node_status.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/command/node_status.go b/command/node_status.go index cf58de8d47a8..b3cba519cbea 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -2,6 +2,7 @@ package command import ( "fmt" + "sort" "strings" ) @@ -103,6 +104,20 @@ func (c *NodeStatusCommand) Run(args []string) int { return 1 } + m := node.Attributes + keys := make([]string, len(m)) + for k := range m { + keys = append(keys, k) + } + sort.Strings(keys) + + var attributes []string + for _, k := range keys { + if k != "" { + attributes = append(attributes, fmt.Sprintf("%s:%s", k, m[k])) + } + } + // Format the output basic := []string{ fmt.Sprintf("ID|%s", node.ID), @@ -111,6 +126,7 @@ func (c *NodeStatusCommand) Run(args []string) int { fmt.Sprintf("Datacenter|%s", node.Datacenter), fmt.Sprintf("Drain|%v", node.Drain), fmt.Sprintf("Status|%s", node.Status), + fmt.Sprintf("Attributes|%s", strings.Join(attributes, ", ")), } var allocs []string