__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

OptionDescription
--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:

KeyAction
Up / DownMove
SpaceMark / unmark and move on
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

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

  1. 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?.
  2. Pick the Recovery Plan (all plans of all PCs, with their clusters).
  3. 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.
  4. Pick the source and the target cluster. The clusters named in the plan are preselected.
  5. Only the subnets of these two clusters are compared: mapped, not found in target, only in target, ambiguous, same name with different VLAN ID.
  6. Create the missing VLANs on both sides? - summary, then a second confirmation, then the VLANs are created.
  7. 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.

Menus: Up / Down, Enter to select, a digit jumps to the entry, Ctrl+C aborts.

Options

OptionDescription
-i, --interactiveWizard (default when no arguments are given)
--source HOST, --target HOSTSource / target Prism Central for report mode
--source-user, --target-userUsers; else NTNX_SOURCE_USER / NTNX_TARGET_USER / NTNX_USER, else asked for
-k, --insecureDo not verify the TLS certificate (self-signed)
--ignore-caseIgnore upper/lower case when matching names
--rename REGEX=>REPLRewrite source names before comparing, e.g. '^DC1-=>DC2-' (repeatable)
--include REGEX, --exclude REGEXOnly / not subnets whose name matches
--plan NAMERecovery Plan (on the source PC) for --dump / dry run / --apply
--dumpPrint the plan as JSON (read-only)
--applyWrite the mapping of all matching subnets into --plan
--csv FILESave the subnets without counterpart as CSV
-v, -vvMore output on stderr (info / debug incl. API calls)
--log-file FILELog the run with timestamps to a file
--state-file FILE, --no-saveOther file for the saved inputs / do not load or save them
-h, --helpShow 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