diff --git a/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py b/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py index f8b0362c9a..c5c45db7bc 100644 --- a/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py +++ b/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py @@ -50,6 +50,19 @@ def post_v2t_migration_cleanups(resource, event, trigger, **kwargs): section['id']) continue + # cleanup migrated DVS ports (belong to the edges that are not in use) + segments = nsxpolicy.segment.list() + for seg in segments: + # skip non-neutron segments + if not p_utils.is_neutron_resource(seg): + continue + ports = nsxpolicy.segment_port.list(seg['id']) + # find the non-neutron ports and delete them + for port in ports: + if not p_utils.is_neutron_resource(port): + nsxpolicy.segment_port.delete(seg['id'], port['id']) + LOG.error("Deleted migrated non-neutron port %s", port['id']) + @admin_utils.output_header def migration_tier0_redistribute(resource, event, trigger, **kwargs): diff --git a/vmware_nsx/shell/admin/plugins/nsxp/resources/utils.py b/vmware_nsx/shell/admin/plugins/nsxp/resources/utils.py index 71ccfba31d..e8e85bc3c2 100644 --- a/vmware_nsx/shell/admin/plugins/nsxp/resources/utils.py +++ b/vmware_nsx/shell/admin/plugins/nsxp/resources/utils.py @@ -137,3 +137,11 @@ class NsxPolicyPluginWrapper(plugin.NsxPolicyPlugin): fwaas_callbacks_v2.NsxpFwaasCallbacksV2, None) return + + +def is_neutron_resource(resource): + # Return True if the resource has the neutron marking tag + for tag in resource.get('tags', []): + if tag.get('scope') == 'os-api-version': + return True + return False