Skip to content

Commit

Permalink
Display OS name in nomad node status command. (#12388)
Browse files Browse the repository at this point in the history
Signed-off-by: Shishir Mahajan <smahajan@roblox.com>
  • Loading branch information
shishir-a412ed authored Mar 28, 2022
1 parent 43b64b7 commit eea1b1f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions command/node_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type NodeStatusCommand struct {
Meta
length int
short bool
os bool
verbose bool
list_allocs bool
self bool
Expand Down Expand Up @@ -74,6 +75,9 @@ Node Status Options:
-verbose
Display full information.
-os
Display operating system name.
-json
Output the node in its JSON format.
Expand All @@ -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,
})
}
Expand All @@ -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, "")
Expand Down Expand Up @@ -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|"
}
Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions website/content/docs/commands/node/status.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -62,6 +64,13 @@ a72dfba2 dc1 node1 <none> false eligible ready
1f3f03ea dc1 node2 <none> false eligible ready
```

```shell-session
$ nomad node status -os
ID DC Name Class OS Drain Eligibility Status
a72dfba2 dc1 node1 <none> ubuntu false eligible ready
f73e3993 dc1 node2 <none> centos false eligible ready
```

List view, with running allocations:

```shell-session
Expand Down

0 comments on commit eea1b1f

Please sign in to comment.