Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display OS name in nomad node status command. #12388

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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