'Event handler for router update migration to distributed.'

@registry.receives(resources.ROUTER, [events.PRECOMMIT_UPDATE])
def _handle_distributed_migration(self, resource, event, trigger, context, router_id, router, router_db, **kwargs):

    if (not self._validate_router_migration(context, router_db, router)):
        return
    migrating_to_distributed = ((not router_db.extra_attributes.distributed) and (router.get('distributed') is True))
    if migrating_to_distributed:
        self.l3plugin._migrate_router_ports(context, router_db, old_owner=const.DEVICE_OWNER_ROUTER_INTF, new_owner=const.DEVICE_OWNER_DVR_INTERFACE)
        self.l3plugin.set_extra_attr_value(context, router_db, 'distributed', True)
    else:
        self.l3plugin._migrate_router_ports(context, router_db, old_owner=const.DEVICE_OWNER_DVR_INTERFACE, new_owner=const.DEVICE_OWNER_ROUTER_INTF)
        self.l3plugin.set_extra_attr_value(context, router_db, 'distributed', False)
    cur_agents = self.l3plugin.list_l3_agents_hosting_router(context, router_db['id'])['agents']
    for agent in cur_agents:
        self.l3plugin._unbind_router(context, router_db['id'], agent['id'])
