def _allocate_subnets(self, conf):
allocated_subnets = []<EOL>try:<EOL><INDENT>for net_spec in conf.get('<STR_LIT>', {}).values():<EOL><INDENT>if net_spec['<STR_LIT:type>'] != '<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>gateway = net_spec.get('<STR_LIT>')<EOL>if gateway:<EOL><INDENT>allocated_subnet = self._subnet_store.acquire(<EOL>self.paths.uuid(), gateway<EOL>)<EOL><DEDENT>else:<EOL><INDENT>allocated_subnet = self._subnet_store.acquire(<EOL>self.paths.uuid()<EOL>)<EOL>net_spec['<STR_LIT>'] = str(next(allocated_subnet.iter_hosts()))<EOL><DEDENT>allocated_subnets.append(allocated_subnet)<EOL><DEDENT><DEDENT>except:<EOL><INDENT>self._subnet_store.release(allocated_subnets)<EOL>raise<EOL><DEDENT>return allocated_subnets, conf<EOL>
Allocate all the subnets needed by the given configuration spec

Args:
    conf (dict): Configuration spec where to get the nets definitions
        from

Returns:
    tuple(list, dict): allocated subnets and modified conf