Skip to content

Commit

Permalink
rename topology to info and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamilcuk committed Sep 29, 2024
1 parent 371b916 commit 6ddbd62
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
36 changes: 28 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Set of tools and utilities to ease interacting with HashiCorp Nomad scheduling s
* [Installation](#installation)
* [Shell completion](#shell-completion)
* [Usage](#usage)
* [watch - get all logs and events of a Nomad job in terminal](#watch---get-all-logs-and-events-of-a-nomad-job-in-terminal)
* [go - create, run and watch a Nomad job from command line](#go---create-run-and-watch-a-nomad-job-from-command-line)
* [`watch` - get all logs and events of a Nomad job in terminal](#watch---get-all-logs-and-events-of-a-nomad-job-in-terminal)
* [`go` - create, run and watch a Nomad job from command line](#go---create-run-and-watch-a-nomad-job-from-command-line)
* [`constrainteval` - evaluate constraint in command line](#constrainteval---evaluate-constraint-in-command-line)
* [`listattributes` - list all available node attributes on number of nodes](#listattributes---list-all-available-node-attributes-on-number-of-nodes)
* [`listattributes` - List nodes with given attributes or show all available attributes.](#listattributes---list-nodes-with-given-attributes-or-show-all-available-attributes)
* [`listnodeattributes` - list all available node attributes](#listnodeattributes---list-all-available-node-attributes)
* [`port` - list ports allocated by job or allocation](#port---list-ports-allocated-by-job-or-allocation)
* [`vardir` - manipulate nomad variable keys as files](#vardir---manipulate-nomad-variable-keys-as-files)
* [`cp` - copy files to/from/between nomad allocations](#cp---copy-files-tofrombetween-nomad-allocations)
Expand All @@ -22,6 +23,7 @@ Set of tools and utilities to ease interacting with HashiCorp Nomad scheduling s
* [`downloadrelease` - download specific Nomad executable version](#downloadrelease---download-specific-nomad-executable-version)
* [`task` - find task and allocation and execute action on it](#task---find-task-and-allocation-and-execute-action-on-it)
* [`nodenametoid` - convert node name to id](#nodenametoid---convert-node-name-to-id)
* [`info topology` - show some information about Nomad node usage](#info-topology---show-some-information-about-nomad-node-usage)
* [import nomad_tools](#import-nomad_tools)
* [History](#history)
* [Contributing](#contributing)
Expand Down Expand Up @@ -71,7 +73,7 @@ completion installation instruction.
This module installs command line tool `nomadtools` with several modes of
operation:

## watch - get all logs and events of a Nomad job in terminal
## `watch` - get all logs and events of a Nomad job in terminal

`nomadtools watch` is meant to watch over a job change that you type in
terminal. It prints all relevant messages - messages about allocation,
Expand Down Expand Up @@ -102,7 +104,7 @@ status (if there is one task).

Internally, watch uses Nomad event stream to get the events in real time.

## go - create, run and watch a Nomad job from command line
## `go` - create, run and watch a Nomad job from command line

Mimics operation of `docker run`, it is built on top of `watch` mode to
execute a single Nomad job created dynamically from command line arguments.
Expand Down Expand Up @@ -142,7 +144,7 @@ evaluating the constraint given on command line arguments. Useful for
searching for which hosts contain what value of a attribute.

```
$ nomadtools constrainteval attr.cpu.arch
$ nomadtools constrainteval '${attr.cpu.arch}' = amd64
name attr.cpu.arch
node1 amd64
node2 amd64
Expand All @@ -153,15 +155,26 @@ attributes of nodes downloaded from Nomad. This is used to speed up. The
program needs to make one query for every single node in Nomad, which for a
lot of nodes is costly.

## `listattributes` - list all available node attributes on number of nodes
## `listattributes` - List nodes with given attributes or show all available attributes.

```
$ nomadtools listattributes attr.cpu.arch
name attr.cpu.arch
node1 amd64
node2 amd64
```

Bash completion works.

## `listnodeattributes` - list all available node attributes

Lists all node attributes or attribute of given nodes.
Additionally with a leading dot lists the whole json return from Nomad API.

This is meant to be used with `grep` and other unix tools for easy parsing.

```
$ nomadtools listattributes | grep datacenter
$ nomadtools listnodeattributes node1 | grep datacenter
dc.datacenter dc
```

Expand Down Expand Up @@ -340,6 +353,13 @@ $ nomadtools nodenametoid node1
3e50c2ef-16bd-0253-6635-1a55c25e74ca
```

## `info topology` - show some information about Nomad node usage

```
$ nomadtools info topology
dc node1 ready 2000B/15988MB 1000MHz/12000MHz 1allocs [mariadb.mariadb[0] mariadb services 2000MB 1000MHz]
```

## import nomad_tools

This project is licensed under GPL. The internal API of this project can be
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PyYAML>=6.0.1
requests>=2.31.0
typing_extensions>=4.7.1
websocket-client>=1.6.1
clickdc>=0.0.6
clickdc>=0.1.0
clickforward>=0.0.1
python-dotenv>=0.21.1
packaging>=16.1
Expand Down
4 changes: 2 additions & 2 deletions src/nomad_tools/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
entry_nodenametoid,
entry_port,
entry_task,
entry_topology,
entry_info,
entry_vardir,
entry_watch,
)
Expand Down Expand Up @@ -81,7 +81,7 @@ def cli():
cli.add_command(entry_listnodeattributes.cli)
cli.add_command(entry_nodenametoid.cli)
cli.add_command(entry_port.cli)
cli.add_command(entry_topology.cli)
cli.add_command(entry_info.cli)
cli.add_command(entry_task.cli)
cli.add_command(entry_vardir.cli)
cli.add_command(entry_watch.cli)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@

import click

from .aliasedgroup import AliasedGroup
from . import common_click
from .common_nomad import mynomad

log = logging.getLogger(__name__)


@click.command(
"topology",
help="Like the topology web interface",
"info",
cls=AliasedGroup,
help="Get information about current Nomad state",
)
@common_click.common_options()
@common_click.verbose_option()
def cli():
pass


@cli.command(help="Like topology web interface")
def topology():
logging.basicConfig()
allocations = mynomad.get(
"allocations", params=dict(resources=True, task_states=False)
Expand Down

0 comments on commit 6ddbd62

Please sign in to comment.