mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
Display OS name in nomad node status command. (#12388)
Signed-off-by: Shishir Mahajan <smahajan@roblox.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 <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
|
||||
|
||||
Reference in New Issue
Block a user