code: def allocate_subnet(self, subnet_lst, net_id=None):
          
  
          session = db.get_session()
          query_str = None
          for sub in subnet_lst:
              sub_que = (self.model.subnet_address != sub)
              if query_str is not None:
                  query_str = query_str & sub_que
              else:
                  query_str = sub_que
          with session.begin(subtransactions=True):
              select = (session.query(self.model).filter(
                  (self.model.allocated == 0) & query_str))
  
              # Selected segment can be allocated before update by someone else,
              # We retry until update success or DB_MAX_RETRIES retries
              for attempt in range(DB_MAX_RETRIES + 1):
                  alloc = select.first()
                  if not alloc:
                      LOG.info("No subnet resource available")
                      return
                  count = (session.query(self.model).
                           filter_by(subnet_address=alloc.subnet_address,
                           allocated=False).update({"allocated": True,
                                                    "network_id": net_id}))
                  if count:
                      return alloc.subnet_address
  
          LOG.error("ERROR: Failed to allocate subnet for net %(net)s",
                    {'net': net_id})
          return None
docs: Allocate subnet from pool.
  
          Return allocated db object or None.