diff --git a/doc/source/admin_util.rst b/doc/source/admin_util.rst index cce77f8cbe..16f020c9c0 100644 --- a/doc/source/admin_util.rst +++ b/doc/source/admin_util.rst @@ -704,6 +704,11 @@ Client Certificate nsxadmin -r certificate -o nsx-list +- Cleanup redundant migrated objects post V2T migration:: + + nsxadmin -r nsx-migrate-v2t -o clean-all + + Steps to create a TVD admin user ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py b/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py index f0f0543313..759872a5c0 100644 --- a/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py +++ b/vmware_nsx/shell/admin/plugins/nsxp/resources/migration.py @@ -13,11 +13,16 @@ # under the License. from neutron_lib.callbacks import registry +from oslo_log import log as logging from vmware_nsx.shell.admin.plugins.common import constants from vmware_nsx.shell.admin.plugins.common import utils as admin_utils +from vmware_nsx.shell.admin.plugins.nsxp.resources import utils as p_utils from vmware_nsx.shell.admin.plugins.nsxv3.resources import migration from vmware_nsx.shell import resources as shell +from vmware_nsxlib.v3.policy import constants as policy_constants + +LOG = logging.getLogger(__name__) @admin_utils.output_header @@ -27,6 +32,26 @@ def cleanup_db_mappings(resource, event, trigger, **kwargs): resource, event, trigger, **kwargs) +@admin_utils.output_header +def post_v2t_migration_cleanups(resource, event, trigger, **kwargs): + """Cleanup unneeded migrated resources after v2t migration is done""" + nsxpolicy = p_utils.get_connected_nsxpolicy() + # clean all migrated DFW sections + sections = nsxpolicy.comm_map.list(policy_constants.DEFAULT_DOMAIN) + for section in sections: + # Look for the tag marking the migrated sections + for tag in section.get('tags', []): + if tag['scope'] == 'v_origin': + LOG.info("Deleting migrated: %s", tag['tag']) + nsxpolicy.comm_map.delete(policy_constants.DEFAULT_DOMAIN, + section['id']) + continue + + registry.subscribe(cleanup_db_mappings, constants.NSX_MIGRATE_T_P, shell.Operations.CLEAN_ALL.value) + +registry.subscribe(post_v2t_migration_cleanups, + constants.NSX_MIGRATE_V_T, + shell.Operations.CLEAN_ALL.value) diff --git a/vmware_nsx/shell/resources.py b/vmware_nsx/shell/resources.py index 4eed39d70b..e022d54aa7 100644 --- a/vmware_nsx/shell/resources.py +++ b/vmware_nsx/shell/resources.py @@ -290,6 +290,8 @@ nsxp_resources = { [Operations.SET.value]), constants.NSX_MIGRATE_T_P: Resource(constants.NSX_MIGRATE_T_P, [Operations.CLEAN_ALL.value]), + constants.NSX_MIGRATE_V_T: Resource(constants.NSX_MIGRATE_V_T, + [Operations.CLEAN_ALL.value]), } nsxv3_resources_names = list(nsxv3_resources.keys())