Delete unused subnets
urlcurl -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 HOSTPrism Central (host/IP); asked for if missing
--user USERUser; else NTNX_USER, else asked for
-k, --insecureDo not verify the TLS certificate (self-signed)
--csv FILEAlso save the list as CSV
--list-onlyOnly list, never offer to delete
-h, --helpShow 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 |
|---|
aMark all / none
EnterContinue with the marked subnets
qQuit 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
--list-only the script only lists; nothing is deleted.