diff --git a/doc/source/admin_util.rst b/doc/source/admin_util.rst index 92ec730471..f509480aa5 100644 --- a/doc/source/admin_util.rst +++ b/doc/source/admin_util.rst @@ -345,6 +345,10 @@ Routers nsxadmin -r routers -o nsx-update-dhcp-relay +- Enable standby relocation on NSX routers that were created without it:: + + nsxadmin -r routers -o nsx-enable-standby-relocation + Orphaned Routers ~~~~~~~~~~~~~~~~~ diff --git a/vmware_nsx/common/utils.py b/vmware_nsx/common/utils.py index 3824647c40..6a420352f4 100644 --- a/vmware_nsx/common/utils.py +++ b/vmware_nsx/common/utils.py @@ -87,6 +87,11 @@ def is_nsx_version_2_1_0(nsx_version): version.LooseVersion(v3_const.NSX_VERSION_2_1_0)) +def is_nsx_version_2_4_0(nsx_version): + return (version.LooseVersion(nsx_version) >= + version.LooseVersion(v3_const.NSX_VERSION_2_4_0)) + + def is_nsxv_version_6_2(nsx_version): return (version.LooseVersion(nsx_version) >= version.LooseVersion('6.2')) diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index fc5a364f3d..28522ec287 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -2940,6 +2940,10 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base, self._add_az_to_router(context, router['id'], r) router_db = self._get_router(context, r['id']) + enable_standby_relocation = False + if self.nsxlib.feature_supported( + nsxlib_consts.FEATURE_ROUTER_ALLOCATION_PROFILE): + enable_standby_relocation = True with db_api.CONTEXT_WRITER.using(context): self._process_extra_attr_router_create(context, router_db, r) # Create backend entries here in case neutron DB exception @@ -2950,7 +2954,7 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base, display_name=utils.get_name_and_uuid( router['name'] or 'router', router['id']), description=router.get('description'), - tags=tags) + tags=tags, enable_standby_relocation=enable_standby_relocation) except nsx_lib_exc.ManagerError: with excutils.save_and_reraise_exception(): LOG.error("Unable to create logical router for " diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/routers.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/routers.py index 378180e837..89a84ec0d8 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/routers.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/routers.py @@ -113,6 +113,33 @@ def update_nat_rules(resource, event, trigger, **kwargs): LOG.info("Did not find any NAT rule to update") +@admin_utils.output_header +def update_enable_standby_relocation(resource, event, trigger, **kwargs): + """Enable standby relocation on all routers """ + # This feature is supported only since nsx version 2.4 + nsxlib = utils.get_connected_nsxlib() + version = nsxlib.get_version() + if not nsx_utils.is_nsx_version_2_4_0(version): + LOG.info("Standby relocation update is only supported from 2.4 " + "onwards") + LOG.info("Version is %s", version) + return + + # Go over all neutron routers + plugin = RoutersPlugin() + admin_cxt = neutron_context.get_admin_context() + filters = utils.get_plugin_filters(admin_cxt) + neutron_routers = plugin.get_routers(admin_cxt, filters=filters) + for router in neutron_routers: + neutron_id = router['id'] + # get the router nsx id from the mapping table + nsx_id = nsx_db.get_nsx_router_id(admin_cxt.session, + neutron_id) + nsxlib.logical_router.update(lrouter_id=nsx_id, + enable_standby_relocation=True) + LOG.info("All routers where enabled with standby relocation") + + @admin_utils.output_header def list_orphaned_routers(resource, event, trigger, **kwargs): nsxlib = utils.get_connected_nsxlib() @@ -231,3 +258,6 @@ registry.subscribe(delete_backend_router, registry.subscribe(update_dhcp_relay, constants.ROUTERS, shell.Operations.NSX_UPDATE_DHCP_RELAY.value) +registry.subscribe(update_enable_standby_relocation, + constants.ROUTERS, + shell.Operations.NSX_ENABLE_STANDBY_RELOCATION.value) diff --git a/vmware_nsx/shell/resources.py b/vmware_nsx/shell/resources.py index 033bf33318..2e8864abbb 100644 --- a/vmware_nsx/shell/resources.py +++ b/vmware_nsx/shell/resources.py @@ -51,6 +51,7 @@ class Operations(enum.Enum): NSX_UPDATE_SECRET = 'nsx-update-secret' NSX_UPDATE_RULES = 'nsx-update-rules' NSX_UPDATE_DHCP_RELAY = 'nsx-update-dhcp-relay' + NSX_ENABLE_STANDBY_RELOCATION = 'nsx-enable-standby-relocation' NSX_UPDATE_IP = 'nsx-update-ip' NSX_RECREATE = 'nsx-recreate' NSX_REDISTRIBURE = 'nsx-redistribute' @@ -106,7 +107,9 @@ nsxv3_resources = { constants.ROUTERS: Resource(constants.ROUTERS, [Operations.LIST_MISMATCHES.value, Operations.NSX_UPDATE_RULES.value, - Operations.NSX_UPDATE_DHCP_RELAY.value]), + Operations.NSX_UPDATE_DHCP_RELAY.value, + Operations.NSX_ENABLE_STANDBY_RELOCATION.value + ]), constants.DHCP_BINDING: Resource(constants.DHCP_BINDING, [Operations.LIST.value, Operations.NSX_UPDATE.value,