__Useful Scripts
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.
Recovery Plan network mapping
curl -O https://wissen.woitzel.eu/rp_netmap.py && python3 rp_netmap.py
What it does
Compares the subnets of one or more Prism Centrals by name, creates missing VLANs on both sides and writes the network mapping into a Recovery Plan. Python 3 only, no extra modules. The wizard asks for confirmation before every write; --apply is the explicit write switch of the command-line mode.
Usage
# guided wizard (no arguments = wizard)
python3 rp_netmap.py
# report only (read-only): compare ALL subnets of source and target, list the plans
python3 rp_netmap.py --source pc-a.example.local --target pc-b.example.local -k
# show a plan as JSON (check network_mapping_list / cluster references)
python3 rp_netmap.py --source pc-a... --target pc-b... -k --plan "RP-Prod" --dump
# dry run, then write the mapping of ALL matching subnets into the plan
python3 rp_netmap.py --source pc-a... --target pc-b... -k --plan "RP-Prod"
python3 rp_netmap.py --source pc-a... --target pc-b... -k --plan "RP-Prod" --apply
Wizard flow
- Number of Prism Centrals (1 is enough if the plans run between clusters of one PC), TLS check, then host, user and password of every PC. A previous run offers Use the saved values?.
- Pick the Recovery Plan (all plans of all PCs, with their clusters).
- The target Prism Central is read from the plan (its availability zone, or the clusters it names; same PC for plans inside one Prism Central). Only if the plan does not tell it, you are asked.
- Pick the source and the target cluster. The clusters named in the plan are preselected.
- Only the subnets of these two clusters are compared: mapped, not found in target, only in target, ambiguous, same name with different VLAN ID.
- Create the missing VLANs on both sides? - summary, then a second confirmation, then the VLANs are created.
- If every VLAN of the source cluster has a counterpart, the missing entries are offered for the plan's network mapping and written after a confirmation.
Options
| Option | Description |
|---|---|
-i, --interactive | Wizard (default when no arguments are given) |
--source HOST, --target HOST | Source / target Prism Central for report mode |
--source-user, --target-user | Users; else NTNX_SOURCE_USER / NTNX_TARGET_USER / NTNX_USER, else asked for |
-k, --insecure | Do not verify the TLS certificate (self-signed) |
--ignore-case | Ignore upper/lower case when matching names |
--rename REGEX=>REPL | Rewrite source names before comparing, e.g. '^DC1-=>DC2-' (repeatable) |
--include REGEX, --exclude REGEX | Only / not subnets whose name matches |
--plan NAME | Recovery Plan (on the source PC) for --dump / dry run / --apply |
--dump | Print the plan as JSON (read-only) |
--apply | Write the mapping of all matching subnets into --plan |
--csv FILE | Save the subnets without counterpart as CSV |
-v, -vv | More output on stderr (info / debug incl. API calls) |
--log-file FILE | Log the run with timestamps to a file |
--state-file FILE, --no-save | Other file for the saved inputs / do not load or save them |
-h, --help | Show the built-in help |
Passwords and saved inputs
Passwords are prompted (no echo), never passed as argument and never stored. Alternatively: NTNX_PASSWORD (all PCs), NTNX_SOURCE_PASSWORD / NTNX_TARGET_PASSWORD (first two PCs). Hosts, users and the TLS setting are saved to ./rp_netmap_last_run.json (chmod 600) in the directory the script is started from.
Notes
- Subnets are matched by name.
--renameonly applies to the source side. A name with several hits in the target is "ambiguous" and is never mapped. - New VLANs are plain VLAN subnets (name + VLAN ID, default virtual switch, no IP address management). The same VLAN ID may exist several times per cluster; only an already used name blocks the creation.
- Existing mapping entries of a plan are kept; only missing pairs are added. An entry that points to a different target network is reported, not changed.
- Plans inside one Prism Central (both sides the same availability zone): the entries are written source first, target second. Check the result in Prism after the first write.
- Report mode compares all subnets and needs exactly one source and one target PC; the wizard handles any number.