'Update new tunnel.
Updates the database with the tunnel IP. All listening agents will also
be notified about the new tunnel IP.'

def tunnel_sync(self, rpc_context, **kwargs):

    tunnel_ip = kwargs.get('tunnel_ip')
    if (not tunnel_ip):
        msg = _('Tunnel    IP    value    needed    by    the    ML2    plugin')
        raise exc.InvalidInput(error_message=msg)
    host = kwargs.get('host')
    version = netaddr.IPAddress(tunnel_ip).version
    if (version != cfg.CONF.ml2.overlay_ip_version):
        msg = (_('Tunnel    IP    version    does    not    match    ML2    overlay_ip_version,    host:    %(host)s,    tunnel_ip:    %(ip)s'), {'host': host, 'ip': tunnel_ip})
        raise exc.InvalidInput(error_message=msg)
    tunnel_type = kwargs.get('tunnel_type')
    if (not tunnel_type):
        msg = _('Network    type    value    needed    by    the    ML2    plugin')
        raise exc.InvalidInput(error_message=msg)
    driver = self._type_manager.drivers.get(tunnel_type)
    if driver:
        if host:
            host_endpoint = driver.obj.get_endpoint_by_host(host)
            ip_endpoint = driver.obj.get_endpoint_by_ip(tunnel_ip)
            if (ip_endpoint and (ip_endpoint.host is None) and (host_endpoint is None)):
                driver.obj.delete_endpoint(ip_endpoint.ip_address)
            elif (ip_endpoint and (ip_endpoint.host != host)):
                LOG.info(_LI('Tunnel    IP    %(ip)s    was    used    by    host    %(host)s    and    will    be    assigned    to    %(new_host)s'), {'ip': ip_endpoint.ip_address, 'host': ip_endpoint.host, 'new_host': host})
                driver.obj.delete_endpoint_by_host_or_ip(host, ip_endpoint.ip_address)
            elif (host_endpoint and (host_endpoint.ip_address != tunnel_ip)):
                self._notifier.tunnel_delete(rpc_context, host_endpoint.ip_address, tunnel_type)
                driver.obj.delete_endpoint(host_endpoint.ip_address)
        tunnel = driver.obj.add_endpoint(tunnel_ip, host)
        tunnels = driver.obj.get_endpoints()
        entry = {'tunnels': tunnels}
        self._notifier.tunnel_update(rpc_context, tunnel.ip_address, tunnel_type)
        return entry
    else:
        msg = (_("Network    type    value    '%s'    not    supported") % tunnel_type)
        raise exc.InvalidInput(error_message=msg)
