def _update_redundancy_routers(self, context, updated_router,<EOL>update_specification, requested_ha_settings,<EOL>updated_router_db, gateway_changed):
router_requested = update_specification['<STR_LIT>']<EOL>ha_settings_db = updated_router_db.ha_settings<EOL>ha_enabled_requested = requested_ha_settings.get(ha.ENABLED, False)<EOL>if not (updated_router[ha.ENABLED] or ha_enabled_requested):<EOL><INDENT>return<EOL><DEDENT>ports = self._get_router_interfaces(updated_router_db)<EOL>e_context = context.elevated()<EOL>if not updated_router[ha.ENABLED] and ha_enabled_requested:<EOL><INDENT>router_requested.update(requested_ha_settings)<EOL>router_requested[EXTERNAL_GW_INFO] = (<EOL>updated_router[EXTERNAL_GW_INFO])<EOL>requested_ha_settings = self._ensure_create_ha_compliant(<EOL>router_requested, updated_router_db.hosting_info.router_type)<EOL>self._create_redundancy_routers(<EOL>e_context, updated_router, requested_ha_settings,<EOL>updated_router_db, ports, expire_db=True)<EOL>return<EOL><DEDENT>rr_ids = self._get_redundancy_router_ids(context, updated_router['<STR_LIT:id>'])<EOL>ha_details_update_spec = requested_ha_settings.get(ha.DETAILS)<EOL>if (updated_router[ha.ENABLED] and not requested_ha_settings.get(<EOL>ha.ENABLED, updated_router[ha.ENABLED])):<EOL><INDENT>self._delete_ha_group(e_context, updated_router_db.gw_port_id)<EOL>self._remove_redundancy_routers(e_context, rr_ids, ports, True)<EOL>with context.session.begin(subtransactions=True):<EOL><INDENT>context.session.delete(ha_settings_db)<EOL><DEDENT><DEDENT>elif ha_details_update_spec:<EOL><INDENT>old_redundancy_level = ha_settings_db.redundancy_level<EOL>ha_settings_db.update(ha_details_update_spec)<EOL>diff = (ha_details_update_spec.get(ha.REDUNDANCY_LEVEL,<EOL>old_redundancy_level) -<EOL>old_redundancy_level)<EOL>with context.session.begin(subtransactions=True):<EOL><INDENT>context.session.add(ha_settings_db)<EOL><DEDENT>if diff < <NUM_LIT:0>:<EOL><INDENT>to_remove = rr_ids[len(rr_ids) + diff:]<EOL>rr_ids = rr_ids[:len(rr_ids) + diff]<EOL>self._remove_redundancy_routers(e_context, to_remove, ports)<EOL><DEDENT>elif diff > <NUM_LIT:0>:<EOL><INDENT>start = old_redundancy_level + <NUM_LIT:1><EOL>stop = start + diff<EOL>self._add_redundancy_routers(e_context, start, stop,<EOL>updated_router, ports,<EOL>ha_settings_db, False)<EOL><DEDENT>if gateway_changed is True:<EOL><INDENT>self._change_ha_for_gateway(e_context, updated_router,<EOL>updated_router_db, ha_settings_db,<EOL>router_requested, expire=True)<EOL><DEDENT>else:<EOL><INDENT>self.notify_routers_updated(e_context, rr_ids)<EOL><DEDENT><DEDENT>elif gateway_changed is True:<EOL><INDENT>self._change_ha_for_gateway(e_context, updated_router,<EOL>updated_router_db, ha_settings_db,<EOL>router_requested)<EOL><DEDENT>other_updates_spec = {'<STR_LIT>': {}}<EOL>if '<STR_LIT>' in update_specification['<STR_LIT>']:<EOL><INDENT>other_updates_spec['<STR_LIT>']['<STR_LIT>'] = (<EOL>update_specification['<STR_LIT>']['<STR_LIT>'])<EOL><DEDENT>if '<STR_LIT:name>' in update_specification['<STR_LIT>']:<EOL><INDENT>other_updates_spec['<STR_LIT>']['<STR_LIT:name>'] = (<EOL>update_specification['<STR_LIT>']['<STR_LIT:name>'])<EOL><DEDENT>if (other_updates_spec['<STR_LIT>'] or<EOL>'<STR_LIT>' in update_specification['<STR_LIT>']):<EOL><INDENT>self._process_other_router_updates(e_context, updated_router_db,<EOL>other_updates_spec)<EOL><DEDENT>context.session.expire(updated_router_db)<EOL>self._extend_router_dict_ha(updated_router, updated_router_db)<EOL>
To be called in update_router() AFTER router has been
        updated in DB.