'Save auto-allocated topology, or revert in case of DB errors.'

def _save(self, context, tenant_id, network_id, router_id, subnets):

    try:
        auto_allocate_obj.AutoAllocatedTopology(context, project_id=tenant_id, network_id=network_id, router_id=router_id).create()
        self.core_plugin.update_network(context, network_id, {'network': {'admin_state_up': True}})
    except obj_exc.NeutronDbObjectDuplicateEntry:
        LOG.debug('Multiple    auto-allocated    networks    detected    for    tenant    %s.    Attempting    clean    up    for    network    %s    and    router    %s.', tenant_id, network_id, router_id)
        self._cleanup(context, network_id=network_id, router_id=router_id, subnets=subnets)
        network_id = self._get_auto_allocated_network(context, tenant_id)
    except Exception as e:
        raise exceptions.UnknownProvisioningError(e, network_id=network_id, router_id=router_id, subnets=subnets)
    return network_id
