V2T migration: Cleanup unused ports post migration

Change-Id: I36db2f1be84adb723774d09cc7192929ce0fe60f
This commit is contained in:
asarfaty 2021-02-02 07:22:12 +02:00 committed by Adit Sarfaty
parent ce8718de8d
commit 5e766b1afb
2 changed files with 21 additions and 0 deletions

View File

@ -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):

View File

@ -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