The purpose of this KB is to provide a script that can be used to clean up stale ports in NSX environments.
VMware NSX
Stale ports may arise in an environment for different reasons, automatic handling is planned for a future version.
This is a known issue impacting VMware NSX.
The following workaround procedures can be used to remove stale ports depending on the NSX release version.
NSX 3.2.1.x and higher
/opt/vmware/upgrade-coordinator-tomcat/temp#java -Xms5g -Xmx10g --add-opens=java.base/java.util=ALL-UNNAMED -Dcorfu-property-file-path=/opt/vmware/upgrade-coordinator-tomcat/conf/ufo-factory.properties -Djava.io.tmpdir=/opt/vmware/upgrade-coordinator-tomcat/temp -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -Dlog4j.configurationFile=/opt/vmware/upgrade-coordinator-tomcat/conf/log4j2.xml -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/opt/vmware/upgrade-coordinator-tomcat/conf/logging.properties -Dnsx-service-type=nsx-manager -DStaleLogicalPortCleanUp.dryRun=true -DStaleLogicalPortCleanUp.userName=admin -DStaleLogicalPortCleanUp.password='AdminPassword' -DStaleLogicalPortCleanUp.maxThreads=5 -DStaleLogicalPortCleanUp.batchSize=20 -DStaleLogicalPortCleanUp.maxTimeoutMinutes=30 -cp /opt/vmware/upgrade-coordinator-tomcat/temp/logical-migration.jar com.vmware.nsx.management.migration.impl.StaleLogicalPortCleanUp
Note on NSX 4.2.x, the first line of the output file has a warning "WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance."#java -Xms5g -Xmx10g --add-opens=java.base/java.util=ALL-UNNAMED -Dcorfu-property-file-path=/opt/vmware/upgrade-coordinator-tomcat/conf/ufo-factory.properties -Djava.io.tmpdir=/opt/vmware/upgrade-coordinator-tomcat/temp -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -Dlog4j.configurationFile=/opt/vmware/upgrade-coordinator-tomcat/conf/log4j2.xml -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/opt/vmware/upgrade-coordinator-tomcat/conf/logging.properties -Dnsx-service-type=nsx-manager -DStaleLogicalPortCleanUp.dryRun=false -DStaleLogicalPortCleanUp.userName=admin -DStaleLogicalPortCleanUp.password='AdminPassword' -DStaleLogicalPortCleanUp.maxThreads=5 -DStaleLogicalPortCleanUp.batchSize=20 -DStaleLogicalPortCleanUp.maxTimeoutMinutes=30 -cp /opt/vmware/upgrade-coordinator-tomcat/temp/logical-migration.jar com.vmware.nsx.management.migration.impl.StaleLogicalPortCleanUp
NSX 3.1.x
'NSX-3.1.X-stale-lports-cleanup-v1.py' and 'apiclient.py' to /root/ directory on any of the NSX Managers.NSX-3.1.X-stale-lports-cleanup-v1.py' using vi editor and add the password for the admin user in the field _nsxPwd = "" inside the "" and save the scriptall' to check all segments. Enter the segment UUID to scan a single segment.
python NSX-3.1.X-stale-lports-cleanup-v1.py allpython NSX-3.1.X-stale-lports-cleanup-v1.py <Segment UUID>python"in front of the script name is designating python to be the interpreter and the command must be run with the above syntaxNote: To find a segment UUID, on the NSX manager as admin user, run: get logical-switches
Security Only Environments
POST /policy/api/v1/infra/sites/<site-id>/enforcement-points/<enforcement-point>/compute-managers/<compute-manager-id>/action/vds-full-syncGET /api/v1/fabric/compute-managers12345678-####-####-####-123456789123:POST /policy/api/v1/infra/sites/default/enforcement-points/default/compute-managers/12345678-####-####-####-123456789123/action/vds-full-syncNote: Running this script on a Global Manager, in a Federated environment will return results saying that no stale logical ports are found. The stale ports created for the Global segments will be automatically cleaned after cleaning the stale ports from the associated Local Manager.
Related Knowledge Base articles
Manual port cleanup of stale ports can be found in KB - Steps to remove stale logical-port(s) in NSX-T after attempted delete