def allocate_subnet(self, subnet_lst, net_id=None):
session = db.get_session()<EOL>query_str = None<EOL>for sub in subnet_lst:<EOL><INDENT>sub_que = (self.model.subnet_address != sub)<EOL>if query_str is not None:<EOL><INDENT>query_str = query_str & sub_que<EOL><DEDENT>else:<EOL><INDENT>query_str = sub_que<EOL><DEDENT><DEDENT>with session.begin(subtransactions=True):<EOL><INDENT>select = (session.query(self.model).filter(<EOL>(self.model.allocated == <NUM_LIT:0>) & query_str))<EOL>for attempt in range(DB_MAX_RETRIES + <NUM_LIT:1>):<EOL><INDENT>alloc = select.first()<EOL>if not alloc:<EOL><INDENT>LOG.info("<STR_LIT>")<EOL>return<EOL><DEDENT>count = (session.query(self.model).<EOL>filter_by(subnet_address=alloc.subnet_address,<EOL>allocated=False).update({"<STR_LIT>": True,<EOL>"<STR_LIT>": net_id}))<EOL>if count:<EOL><INDENT>return alloc.subnet_address<EOL><DEDENT><DEDENT><DEDENT>LOG.error("<STR_LIT>",<EOL>{'<STR_LIT>': net_id})<EOL>return None<EOL>
Allocate subnet from pool.

        Return allocated db object or None.