def release_hosting_device_slots(self, context, hosting_device, resource,<EOL>num):
with context.session.begin(subtransactions=True):<EOL><INDENT>num_str = str(num) if num >= <NUM_LIT:0> else "<STR_LIT:all>"<EOL>res_info = {'<STR_LIT>': resource}<EOL>slot_info, query = self._get_or_create_slot_allocation(<EOL>context, hosting_device, res_info, create=False)<EOL>if slot_info is None:<EOL><INDENT>LOG.debug('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>', {'<STR_LIT>': num_str,<EOL>'<STR_LIT>': hosting_device['<STR_LIT:id>'],<EOL>'<STR_LIT:id>': resource['<STR_LIT:id>']})<EOL>return False<EOL><DEDENT>if num >= <NUM_LIT:0>:<EOL><INDENT>new_allocation = slot_info.num_allocated - num<EOL><DEDENT>else:<EOL><INDENT>new_allocation = <NUM_LIT:0><EOL><DEDENT>if new_allocation < <NUM_LIT:0>:<EOL><INDENT>LOG.debug('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': num_str, '<STR_LIT>': hosting_device['<STR_LIT:id>'],<EOL>'<STR_LIT:id>': resource['<STR_LIT:id>'],<EOL>'<STR_LIT>': slot_info.num_allocated})<EOL>self._dispatch_pool_maintenance_job(hosting_device['<STR_LIT>'])<EOL>return False<EOL><DEDENT>elif new_allocation == <NUM_LIT:0>:<EOL><INDENT>result = query.delete()<EOL>LOG.info('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': num_str, '<STR_LIT>': new_allocation,<EOL>'<STR_LIT>': hosting_device['<STR_LIT:id>']})<EOL>if (hosting_device['<STR_LIT>'] is not None and<EOL>context.session.query(hd_models.SlotAllocation).filter_by(<EOL>hosting_device_id=hosting_device['<STR_LIT:id>']).first() is<EOL>None):<EOL><INDENT>hosting_device['<STR_LIT>'] = None<EOL>context.session.add(hosting_device)<EOL>LOG.info('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': hosting_device['<STR_LIT:id>']})<EOL><DEDENT>self._dispatch_pool_maintenance_job(hosting_device['<STR_LIT>'])<EOL>return result == <NUM_LIT:1><EOL><DEDENT>LOG.info('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': num_str, '<STR_LIT>': new_allocation,<EOL>'<STR_LIT>': hosting_device['<STR_LIT:id>']})<EOL>slot_info.num_allocated = new_allocation<EOL>context.session.add(slot_info)<EOL><DEDENT>self._dispatch_pool_maintenance_job(hosting_device['<STR_LIT>'])<EOL>return True<EOL>
Free <num> slots in <hosting_device> from logical resource <id>.

        Returns True if deallocation was successful. False otherwise.