diff --git a/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py b/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py index 7c70e9cb4c..c11b1a1a29 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 e0290d6967..3ebd3367cf 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