Skip to content

Commit b32c39c

Browse files
moore-automationEd Moore
andauthored
Rename to nac-analytics with multi-product CLI (#3)
* Rename to nac-analytics with multi-product CLI and documentation restructure. Rebrand from nac-nd to nac-analytics with a product-scoped CLI (nac-analytics nexus-dashboard <verb>, nd alias). Split core and Nexus Dashboard into nac_analytics/core/ and products/nexus_dashboard/. Slim README with captured product help; per-verb reference under docs/. Add capture-help script with CI drift check. Reorganise examples under examples/nexus_dashboard/. * Simplify docs to match nac-validate: plain-text help, no capture script. Replace ANSI help blocks with hand-maintained plain-text --help excerpts in README and docs/commands. Verb pages keep prose and examples only. Remove scripts/capture-help.py and the CI drift check. --------- Co-authored-by: Ed Moore <edmoor@cisco.com>
1 parent af839e9 commit b32c39c

73 files changed

Lines changed: 1089 additions & 532 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
# nac-nd credentials (gitignored when copied to `.env`).
1+
# nac-analytics credentials (gitignored when copied to `.env`).
22
#
3-
# Connection, domain, fabric(s), TLS and timing live in `nac-nd.yaml` — copy
3+
# `ND_*` variables scope to the Nexus Dashboard product (future products use
4+
# their own prefixes, e.g. `CC_*`). Connection, domain, fabric(s), TLS and timing
5+
# also live in `nac-analytics.yaml` under `nexus_dashboard:` — copy
46
# `config.example.yaml` to get started.
57
#
6-
# Precedence: CLI flags → environment variables → nac-nd.yaml → `.env` in cwd
8+
# Precedence: CLI flags → environment variables → nac-analytics.yaml → `.env` in cwd
79

810
# Required
911
ND_USER=admin
1012
ND_PASSWORD=change-me
1113

12-
# Optional overrides (uncomment to use instead of nac-nd.yaml values)
14+
# Optional overrides (uncomment to use instead of nac-analytics.yaml values)
1315
# ND_HOST=nd.example.com
1416
# ND_DOMAIN=DefaultAuth
1517
# ND_FABRIC=FABRIC-A
@@ -18,4 +20,4 @@ ND_PASSWORD=change-me
1820
# ND_JOB_TIMEOUT_MINUTES=60
1921
# ND_POLL_INTERVAL=15
2022
# ND_DELTA_DETAIL=resources
21-
# ND_CONFIG=/path/to/nac-nd.yaml
23+
# ND_CONFIG=/path/to/nac-analytics.yaml

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
# [tool.bandit]. The toml extra supplies the pyproject config reader.
3636
- name: Run bandit security scan
3737
run: >
38-
uvx --from "bandit[toml]" bandit -c pyproject.toml -r nac_nd/ -ll
38+
uvx --from "bandit[toml]" bandit -c pyproject.toml -r nac_analytics/ -ll
3939
-f json -o bandit-security-report.json
4040
4141
- name: Upload security report
@@ -68,7 +68,7 @@ jobs:
6868
run: uv run ruff format --check --diff .
6969

7070
- name: Mypy
71-
run: uv run mypy nac_nd
71+
run: uv run mypy nac_analytics
7272

7373
test:
7474
name: Tests

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ junit.xml
2828
.env
2929
.env.*
3030
!.env.example
31+
nac-analytics.yaml
3132
nac-nd.yaml
3233

3334
# Local analysis artefacts (may contain TF variables / credentials)

README.md

Lines changed: 66 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,190 +1,97 @@
1-
# nac-nd
1+
# nac-analytics
22

33
> **In development** — install from source today; PyPI release planned.
4+
> Formerly **nac-nd**. Today it covers Cisco ACI via Nexus Dashboard 4.2.1+; the intent is to grow beyond Nexus Dashboard and add support for additional Cisco products, so one tool can drive change analytics across platforms.
45
5-
CLI for change analysis on Cisco ACI fabrics via Nexus Dashboard 4.2.1+. Upload a candidate configuration, compare snapshots, or check compliance.
6+
CLI for change analysis on Cisco ACI fabrics via Nexus Dashboard 4.2.1+.
67

7-
**Requirements:** Nexus Dashboard 4.2.1+, Python 3.10+, an ACI fabric registered in Nexus Dashboard.
8+
Commands are grouped per Cisco product: `nac-analytics <product> <command>`.
9+
Today the product is `nexus-dashboard` (alias `nd`); more products are planned.
10+
11+
## Installation
812

9-
## Install (from source)
13+
**Requirements:** Nexus Dashboard 4.2.1+, Python 3.10+, an ACI fabric registered in Nexus Dashboard.
1014

1115
```bash
12-
git clone https://github.com/netascode/nac-nd.git
13-
cd nac-nd
16+
git clone https://github.com/netascode/nac-analytics.git
17+
cd nac-analytics
1418
uv sync --group dev
15-
uv run nac-nd --help
19+
uv run nac-analytics --help
1620
```
1721

18-
PyPI install (`pip install nac-nd` / `uv tool install nac-nd`) will be added when the first release is published.
19-
2022
## Quick start
2123

2224
```bash
23-
cp config.example.yaml nac-nd.yaml # edit host, fabric, domain
24-
cp .env.example .env # set ND_USER and ND_PASSWORD (gitignored)
25-
uv run nac-nd doctor
25+
cp config.example.yaml nac-analytics.yaml # edit host, fabric, domain
26+
cp .env.example .env # set ND_USER and ND_PASSWORD
27+
uv run nac-analytics nd doctor
2628
```
2729

28-
Run `nac-nd <command> --help` for all options.
29-
30-
## Configuration
31-
32-
Settings resolve in order: **CLI flags → environment variables → YAML → `.env` in cwd**.
33-
34-
| YAML key | Environment variable | Notes |
35-
| --- | --- | --- |
36-
| `host` | `ND_HOST` | Nexus Dashboard hostname (optional `http://` prefix) |
37-
| `username` / `user` | `ND_USER` | |
38-
| `password` | `ND_PASSWORD` | Keep in env/CI secrets, not YAML |
39-
| `domain` | `ND_DOMAIN` | Default `DefaultAuth` |
40-
| `fabric` | `ND_FABRIC` | Default fabric for commands |
41-
| `fabrics` || List for `compliance --all` |
42-
| `verify_ssl` / `verify_tls` | `ND_VERIFY_SSL` | `ND_VERIFY_TLS` accepted as alias |
43-
| `ca_bundle` | `ND_CA_BUNDLE` | |
44-
| `job_timeout_minutes` | `ND_JOB_TIMEOUT_MINUTES` | |
45-
| `poll_interval` | `ND_POLL_INTERVAL` | |
46-
| `delta_detail` | `ND_DELTA_DETAIL` | Overrides `--detail` default |
47-
48-
Config file locations: `--config path`, `ND_CONFIG`, `./nac-nd.yaml`, or `~/.config/nac-nd/config.yaml`.
49-
50-
## Commands
51-
52-
All primary inputs use **positional arguments** (not flags):
30+
## Exit codes
5331

54-
| Command | Syntax |
32+
| Code | Meaning |
5533
| --- | --- |
56-
| `prechange` | `nac-nd prechange <plan.json> [<baseline>]` or `nac-nd prechange --job-id <id>` |
57-
| `snapshots` | `nac-nd snapshots <selector>` |
58-
| `delta` | `nac-nd delta [<pre>] [<post>]` |
59-
60-
`prechange` and `delta` are **gate commands**: they fail on new `critical`/`major` anomalies by default, write JUnit to `prechange-report.xml` / `delta-report.xml`, and print a one-line verdict on stderr. Use `--output text` for a full human-readable report.
61-
62-
### doctor — check connectivity
63-
64-
```bash
65-
nac-nd doctor
66-
```
67-
68-
### prechange — Terraform plan (Network as Code)
69-
70-
Use with [Network as Code](https://netascode.cisco.com) projects: run `terraform plan`, export JSON, analyse before apply.
71-
72-
```bash
73-
terraform plan -out=plan.tfplan
74-
terraform show -json plan.tfplan > plan.json
75-
nac-nd prechange plan.json
76-
```
77-
78-
- **Exit 0** — DECISION: PASS
79-
- **Exit 3** — DECISION: FAIL
80-
- Writes `prechange-report.xml` automatically
81-
- Use `--fail-on none` to report only (always exit 0)
82-
- Use `--output text` for the full change-approval report on stdout
83-
84-
Optional baseline positional (defaults to `latest`):
85-
86-
```bash
87-
nac-nd prechange plan.json latest-1
88-
```
89-
90-
Resume or fetch an existing analysis (no re-upload) — useful after a timeout while ND was still queued:
91-
92-
```bash
93-
nac-nd prechange --job-id <job-id> --fail-on none
94-
```
95-
96-
`--job-id` waits if the job is still running, then writes the report from the completed result.
97-
98-
### prechange — APIC MO JSON
99-
100-
```bash
101-
nac-nd prechange examples/minimal-change.json --output text
102-
```
103-
104-
### snapshots — pin a snapshot ID
105-
106-
```bash
107-
SNAPSHOT_ID=$(nac-nd snapshots latest)
108-
```
109-
110-
Text output is the snapshot ID only (for `$()` capture). Use `--output json` for the full record.
111-
112-
### delta — compare snapshots
113-
114-
```bash
115-
nac-nd delta # latest-1 vs latest (ad-hoc only)
116-
nac-nd delta abc-123 # pinned pre, post defaults to latest
117-
nac-nd delta abc-123 def-456 # both pinned
118-
```
119-
120-
Writes `delta-report.xml` by default. Selectors: `latest`, `latest-N`, or a snapshot ID.
121-
122-
### compliance — rule status
123-
124-
```bash
125-
nac-nd compliance
126-
nac-nd --config nac-nd.yaml compliance --all --fail-on-violations
127-
```
128-
129-
## CI/CD
130-
131-
Gate commands need **no extra flags** in CI — fail on exit code, not by parsing output:
132-
133-
```yaml
134-
- name: Pre-change analysis
135-
run: nac-nd prechange plan.json
136-
137-
- name: Pin baseline snapshot
138-
id: baseline
139-
run: echo "snapshot_id=$(nac-nd snapshots latest)" >> "$GITHUB_OUTPUT"
34+
| 0 | Success; threshold not breached |
35+
| 1 | Unexpected error |
36+
| 2 | Analysis job failed, stopped, vanished, or timed out |
37+
| 3 | New anomalies at `--fail-on` (or compliance violations with `--fail-on-violations`) |
38+
| 4 | Bad input, config, or configuration rejected by Nexus Dashboard |
39+
| 5 | Authentication or authorisation failure |
14040

141-
- run: terraform apply -auto-approve plan.tfplan
41+
## Nexus Dashboard commands
14242

143-
- name: Post-apply delta
144-
run: nac-nd delta "${{ steps.baseline.outputs.snapshot_id }}"
14543
```
146-
147-
Pin the baseline snapshot ID saved **before** apply. Do not rely on `nac-nd delta` with no arguments in CI — another snapshot may arrive between stages.
148-
149-
Optional: upload auto-generated reports:
150-
151-
```yaml
152-
- uses: actions/upload-artifact@v4
153-
if: always()
154-
with:
155-
name: nd-reports
156-
path: |
157-
prechange-report.xml
158-
delta-report.xml
44+
$ nac-analytics nexus-dashboard --help
45+
46+
Usage: nac-analytics nexus-dashboard [OPTIONS] COMMAND [ARGS]...
47+
48+
Change analysis for Cisco Nexus Dashboard 4.2.1+ (GA REST APIs, ACI).
49+
50+
Configuration:
51+
ND_HOST Nexus Dashboard hostname or IP
52+
ND_USER Login username
53+
ND_PASSWORD Login password
54+
ND_DOMAIN Login domain
55+
ND_FABRIC Default ACI fabric name
56+
ND_VERIFY_SSL Verify TLS certificate (ND_VERIFY_TLS accepted)
57+
ND_CA_BUNDLE Path to CA bundle
58+
ND_JOB_TIMEOUT_MINUTES Minutes to wait for analysis jobs
59+
ND_POLL_INTERVAL Seconds between job status polls
60+
ND_DELTA_DETAIL Default --detail for prechange and delta
61+
ND_CONFIG Path to YAML config file
62+
63+
In YAML, nest these under a `nexus_dashboard:` section. Settings load from
64+
CLI flags, then environment variables, nac-analytics.yaml, or .env.
65+
66+
Options:
67+
--help Show this message and exit.
68+
69+
Commands:
70+
prechange Analyse a candidate configuration against a fabric's current state.
71+
delta Compare two snapshots of a fabric and report what changed.
72+
snapshots Resolve a fabric snapshot and print its ID (for CI baseline pinning).
73+
compliance Report compliance rule status for a fabric (or every fabric with --all).
74+
doctor Check connectivity, credentials, and fabric visibility.
15975
```
16076

161-
### Local full pipeline
77+
Verb-level usage and examples: [command reference](docs/commands/README.md).
16278

163-
After exporting a Terraform plan from `examples/terraform`:
79+
## Configuration
16480

165-
```bash
166-
PLAN_FILE=examples/terraform/plan.json ./examples/ci-pipeline.sh
167-
```
81+
Precedence: CLI flags → environment variables → YAML → `.env` in cwd.
16882

169-
See [examples/README.md](examples/README.md) for APIC credentials and apply steps.
83+
Settings are scoped per product. See [config.example.yaml](config.example.yaml) and [Configuration](docs/configuration.md) for the full variable list and YAML layout.
17084

171-
## Exit codes
85+
## Documentation
17286

173-
| Code | Meaning |
87+
| Topic | Link |
17488
| --- | --- |
175-
| 0 | Success; threshold not breached |
176-
| 1 | Unexpected error |
177-
| 2 | Analysis job failed, stopped, vanished, or timed out |
178-
| 3 | New anomalies at `--fail-on` (or compliance violations with `--fail-on-violations`) |
179-
| 4 | Bad input, config, or configuration rejected by Nexus Dashboard |
180-
| 5 | Authentication or authorisation failure |
89+
| Documentation hub | [docs/README.md](docs/README.md) |
90+
| Command reference (global + verbs) | [docs/commands/README.md](docs/commands/README.md) |
91+
| Configuration | [docs/configuration.md](docs/configuration.md) |
92+
| Development | [docs/development.md](docs/development.md) |
93+
| Examples & CI pipeline | [examples/README.md](examples/README.md) |
18194

18295
## Development
18396

184-
```bash
185-
uv sync --group dev
186-
uv run pytest
187-
uv run ruff check .
188-
uv run ruff format --check .
189-
uv run python -m mypy nac_nd
190-
```
97+
Contributors: see [Development](docs/development.md).

config.example.yaml

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,44 @@
1-
# nac-nd YAML configuration (safe to commit).
1+
# nac-analytics YAML configuration (safe to commit).
22
#
3-
# Copy to `nac-nd.yaml` or `~/.config/nac-nd/config.yaml`, or pass
3+
# Copy to `nac-analytics.yaml` or `~/.config/nac-analytics/config.yaml`, or pass
44
# `--config /path/to/this/file`.
55
#
6+
# Settings are scoped per Cisco product. Nest a product's settings under its
7+
# section (`nexus_dashboard:` today; more products later). Each product reads
8+
# only its own section.
9+
#
610
# Keep secrets out of this file — use `.env` or the environment for
711
# ND_USER and ND_PASSWORD (see `.env.example`).
12+
#
13+
# ---------------------------------------------------------------------------
14+
# Supported variables — nexus_dashboard section
15+
# ---------------------------------------------------------------------------
16+
# Key Env var Description
17+
# host ND_HOST Hostname or IP (HTTPS assumed when no scheme given).
18+
# domain ND_DOMAIN Login domain (DefaultAuth, local, or your LDAP domain).
19+
# verify_ssl ND_VERIFY_SSL Verify TLS cert (ND_VERIFY_TLS also accepted).
20+
# ca_bundle ND_CA_BUNDLE Path to a CA bundle for private/self-signed certs.
21+
# fabric ND_FABRIC Default fabric when a command needs one and --fabric is omitted.
22+
# fabrics — Fabrics `compliance --all` checks (defaults to [fabric]).
23+
# job_timeout_minutes ND_JOB_TIMEOUT_MINUTES Minutes to wait for a pre-change analysis job.
24+
# poll_interval ND_POLL_INTERVAL Seconds between job status polls.
25+
# delta_detail ND_DELTA_DETAIL Default detail: none, resources, anomalies, policy-diff, full
26+
# (prechange defaults to `full`; delta to `resources`).
27+
#
28+
# Credentials (secrets — set via environment, not here):
29+
# username ND_USER Login username.
30+
# password ND_PASSWORD Login password.
31+
# ---------------------------------------------------------------------------
832

9-
# Nexus Dashboard hostname or IP (HTTPS is assumed when no scheme is given).
10-
host: nd.example.com
11-
12-
# Login domain (DefaultAuth, local, or your LDAP domain name).
13-
domain: DefaultAuth
14-
15-
# TLS verification. Set false only on trusted lab clusters with self-signed certs.
16-
verify_ssl: true
17-
# ca_bundle: /path/to/nd-cluster-ca.pem
18-
19-
# Default fabric when a command needs one and --fabric is omitted.
20-
fabric: FABRIC-A
21-
22-
# Every fabric `compliance --all` checks (defaults to [fabric] when omitted).
23-
fabrics:
24-
- FABRIC-A
25-
- FABRIC-B
26-
27-
# Pre-change analysis can sit in ND's queue before running; raise on slow clusters.
28-
job_timeout_minutes: 30
29-
poll_interval: 15
30-
31-
# Default for `delta --detail` and YAML override for both gate commands.
32-
# prechange defaults to `full` when unset; delta defaults to `resources`.
33-
# Values: none, resources, anomalies, policy-diff, full
34-
delta_detail: resources
33+
nexus_dashboard:
34+
host: nd.example.com
35+
domain: DefaultAuth
36+
verify_ssl: true
37+
# ca_bundle: /path/to/nd-cluster-ca.pem
38+
fabric: FABRIC-A
39+
fabrics:
40+
- FABRIC-A
41+
- FABRIC-B
42+
job_timeout_minutes: 30
43+
poll_interval: 15
44+
delta_detail: resources

0 commit comments

Comments
 (0)