def acquire_hosting_device_slots(self, context, hosting_device, resource,<EOL>resource_type, resource_service, num,<EOL>exclusive=False):
bound = hosting_device['<STR_LIT>']<EOL>if ((bound is not None and bound != resource['<STR_LIT>']) or<EOL>(exclusive and not self._exclusively_used(context, hosting_device,<EOL>resource['<STR_LIT>']))):<EOL><INDENT>LOG.debug(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': num,<EOL>'<STR_LIT>': '<STR_LIT>' if bound is None else bound + '<STR_LIT>',<EOL>'<STR_LIT>': hosting_device['<STR_LIT:id>'], '<STR_LIT>': resource['<STR_LIT:id>']})<EOL>return False<EOL><DEDENT>with context.session.begin(subtransactions=True):<EOL><INDENT>res_info = {'<STR_LIT>': resource, '<STR_LIT:type>': resource_type,<EOL>'<STR_LIT>': resource_service}<EOL>slot_info, query = self._get_or_create_slot_allocation(<EOL>context, hosting_device, res_info)<EOL>if slot_info is None:<EOL><INDENT>LOG.debug('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': num, '<STR_LIT>': hosting_device['<STR_LIT:id>'],<EOL>'<STR_LIT>': resource['<STR_LIT:id>']})<EOL>return False<EOL><DEDENT>new_allocation = num + slot_info.num_allocated<EOL>if hosting_device['<STR_LIT>']['<STR_LIT>'] < new_allocation:<EOL><INDENT>LOG.debug('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': num, '<STR_LIT>': hosting_device['<STR_LIT:id>'],<EOL>'<STR_LIT>': resource['<STR_LIT:id>']})<EOL>self._dispatch_pool_maintenance_job(hosting_device['<STR_LIT>'])<EOL>return False<EOL><DEDENT>if exclusive and bound is None:<EOL><INDENT>self._update_hosting_device_exclusivity(<EOL>context, hosting_device, resource['<STR_LIT>'])<EOL>bound = resource['<STR_LIT>']<EOL><DEDENT>elif not exclusive and bound is not None:<EOL><INDENT>self._update_hosting_device_exclusivity(context,<EOL>hosting_device, None)<EOL>bound = None<EOL><DEDENT>slot_info.num_allocated = new_allocation<EOL>context.session.add(slot_info)<EOL><DEDENT>self._dispatch_pool_maintenance_job(hosting_device['<STR_LIT>'])<EOL>LOG.info('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': num, '<STR_LIT>': '<STR_LIT>' if bound is None else bound + '<STR_LIT:U+0020>',<EOL>'<STR_LIT>': new_allocation, '<STR_LIT>': hosting_device['<STR_LIT:id>'],<EOL>'<STR_LIT>': resource['<STR_LIT:id>']})<EOL>return True<EOL>
Assign <num> slots in <hosting_device> to logical <resource>.

        If exclusive is True the hosting device is bound to the resource's
        tenant. Otherwise it is not bound to any tenant.

        Returns True if allocation was granted, False otherwise.