From eea1b1f27c72fa13d14bf661f224edde1f5dce66 Mon Sep 17 00:00:00 2001 From: Shishir Date: Mon, 28 Mar 2022 06:28:14 -0700 Subject: [PATCH] Display OS name in nomad node status command. (#12388) Signed-off-by: Shishir Mahajan --- command/node_status.go | 23 +++++++++++++++++++ website/content/docs/commands/node/status.mdx | 9 ++++++++ 2 files changed, 32 insertions(+) diff --git a/command/node_status.go b/command/node_status.go index c12b0cb9a4e4..5f68b49eba6a 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -28,6 +28,7 @@ type NodeStatusCommand struct { Meta length int short bool + os bool verbose bool list_allocs bool self bool @@ -74,6 +75,9 @@ Node Status Options: -verbose Display full information. + -os + Display operating system name. + -json Output the node in its JSON format. @@ -96,6 +100,7 @@ func (c *NodeStatusCommand) AutocompleteFlags() complete.Flags { "-short": complete.PredictNothing, "-stats": complete.PredictNothing, "-t": complete.PredictAnything, + "-os": complete.PredictAnything, "-verbose": complete.PredictNothing, }) } @@ -122,6 +127,7 @@ func (c *NodeStatusCommand) Run(args []string) int { flags := c.Meta.FlagSet(c.Name(), FlagSetClient) flags.Usage = func() { c.Ui.Output(c.Help()) } flags.BoolVar(&c.short, "short", false, "") + flags.BoolVar(&c.os, "os", false, "") flags.BoolVar(&c.verbose, "verbose", false, "") flags.BoolVar(&c.list_allocs, "allocs", false, "") flags.BoolVar(&c.self, "self", false, "") @@ -186,6 +192,10 @@ func (c *NodeStatusCommand) Run(args []string) int { out[0] = "ID|DC|Name|Class|" + if c.os { + out[0] += "OS|" + } + if c.verbose { out[0] += "Address|Version|" } @@ -196,12 +206,25 @@ func (c *NodeStatusCommand) Run(args []string) int { out[0] += "|Running Allocs" } + queryOptions := &api.QueryOptions{AllowStale: true} + var nodeInfo *api.Node + for i, node := range nodes { + if c.os { + nodeInfo, _, err = client.Nodes().Info(node.ID, queryOptions) + if err != nil { + c.Ui.Error(fmt.Sprintf("Error getting node info: %s", err)) + return 1 + } + } out[i+1] = fmt.Sprintf("%s|%s|%s|%s", limit(node.ID, c.length), node.Datacenter, node.Name, node.NodeClass) + if c.os { + out[i+1] += fmt.Sprintf("|%s", nodeInfo.Attributes["os.name"]) + } if c.verbose { out[i+1] += fmt.Sprintf("|%s|%s", node.Address, node.Version) diff --git a/website/content/docs/commands/node/status.mdx b/website/content/docs/commands/node/status.mdx index e667299a0f43..2a715ca5cace 100644 --- a/website/content/docs/commands/node/status.mdx +++ b/website/content/docs/commands/node/status.mdx @@ -47,6 +47,8 @@ capability. - `-verbose`: Show full information. +- `-os`: Display operating system name. + - `-json` : Output the node in its JSON format. - `-t` : Format and display node using a Go template. @@ -62,6 +64,13 @@ a72dfba2 dc1 node1 false eligible ready 1f3f03ea dc1 node2 false eligible ready ``` +```shell-session +$ nomad node status -os +ID DC Name Class OS Drain Eligibility Status +a72dfba2 dc1 node1 ubuntu false eligible ready +f73e3993 dc1 node2 centos false eligible ready +``` + List view, with running allocations: ```shell-session