Delete unused subnets
curl -O https://wissen.woitzel.eu/unused_subnets.py && python3 unused_subnets.py -k
What it does
Connects to one Prism Central, lists every subnet (with its cluster) that no VM NIC points to and optionally deletes the ones you mark. Python 3 only, no extra modules.
Usage
python3 unused_subnets.py [--host HOST] [--user USER] [-k] [--csv FILE] [--list-only]
# ask for host, user and password
python3 unused_subnets.py
# everything on the command line
python3 unused_subnets.py --host pc.example.local --user admin -k
# read-only: list and save as CSV, never offer to delete
python3 unused_subnets.py --host pc.example.local --user admin -k --list-only --csv unused.csv
Options
| Option | Description |
|---|---|
--host HOST | Prism Central (host/IP); asked for if missing |
--user USER | User; else NTNX_USER, else asked for |
-k, --insecure | Do not verify the TLS certificate (self-signed) |
--csv FILE | Also save the list as CSV |
--list-only | Only list, never offer to delete |
-h, --help | Show the built-in help |
Password
Prompted (no echo). Never passed as argument, never stored. Alternatively set NTNX_PASSWORD (and NTNX_USER).
Mark and delete
After the list the script asks Mark subnets for deletion? [y/N]. Then:
| Key | Action |
|---|---|
| Up / Down | Move |
| Space | Mark / unmark and move on |
a | Mark all / none |
| Enter | Continue with the marked subnets |
q | Quit without deleting |
The marked subnets are shown again and need a final Delete these N subnet(s) now? [y/N] (default: no). Right before deleting the VMs are read again; a subnet that got a VM in the meantime is skipped. Subnets are deleted one by one, each with OK / FAIL.
Notes
- A VM counts whether it is powered on or off. Subnets are matched by UUID, so identical names on different clusters are not mixed up.
- Other consumers of a subnet (Files, Karbon, templates) are not checked. Prism may refuse such a delete - it shows up as FAIL.
- Without a terminal (pipe) or with
--list-onlythe script only lists; nothing is deleted.