def acquire_hosting_device_slots(self, context, hosting_device, resource,
                                     resource_type, resource_service, num,
                                     exclusive=False):
        """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.
        """
        bound = hosting_device['tenant_bound']
        if ((bound is not None and bound != resource['tenant_id']) or
            (exclusive and not self._exclusively_used(context, hosting_device,
                                                      resource['tenant_id']))):
            LOG.debug(
                'Rejecting allocation of %(num)d slots in tenant %(bound)s '
                'hosting device %(device)s to logical resource %(r_id)s due '
                'to exclusive use conflict.',
                {'num': num,
                 'bound': 'unbound' if bound is None else bound + ' bound',
                 'device': hosting_device['id'], 'r_id': resource['id']})
            return False
        with context.session.begin(subtransactions=True):
            res_info = {'resource': resource, 'type': resource_type,
                        'service': resource_service}
            slot_info, query = self._get_or_create_slot_allocation(
                context, hosting_device, res_info)
            if slot_info is None:
                LOG.debug('Rejecting allocation of %(num)d slots in hosting '
                          'device %(device)s to logical resource %(r_id)s',
                          {'num': num, 'device': hosting_device['id'],
                           'r_id': resource['id']})
                return False
            new_allocation = num + slot_info.num_allocated
            if hosting_device['template']['slot_capacity'] < new_allocation:
                LOG.debug('Rejecting allocation of %(num)d slots in '
                          'hosting device %(device)s to logical resource '
                          '%(r_id)s due to insufficent slot availability.',
                          {'num': num, 'device': hosting_device['id'],
                           'r_id': resource['id']})
                self._dispatch_pool_maintenance_job(hosting_device['template'])
                return False
            # handle any changes to exclusive usage by tenant
            if exclusive and bound is None:
                self._update_hosting_device_exclusivity(
                    context, hosting_device, resource['tenant_id'])
                bound = resource['tenant_id']
            elif not exclusive and bound is not None:
                self._update_hosting_device_exclusivity(context,
                                                        hosting_device, None)
                bound = None
            slot_info.num_allocated = new_allocation
            context.session.add(slot_info)
        self._dispatch_pool_maintenance_job(hosting_device['template'])
        # report success
        LOG.info('Allocated %(num)d additional slots in tenant %(bound)s'
                 'bound hosting device %(hd_id)s. In total %(total)d '
                 'slots are now allocated in that hosting device for '
                 'logical resource %(r_id)s.',
                 {'num': num, 'bound': 'un-' if bound is None else bound + ' ',
                  'total': new_allocation, 'hd_id': hosting_device['id'],
                  'r_id': resource['id']})
        return True
def acquire_hosting_device_slots ( self , context , hosting_device , resource , resource_type , resource_service , num , exclusive = False ) : bound = hosting_device [ 'tenant_bound' ] if ( ( bound is not None and bound != resource [ 'tenant_id' ] ) or ( exclusive and not self . _exclusively_used ( context , hosting_device , resource [ 'tenant_id' ] ) ) ) : LOG . debug ( 'Rejecting allocation of %(num)d slots in tenant %(bound)s ' 'hosting device %(device)s to logical resource %(r_id)s due ' 'to exclusive use conflict.' , { 'num' : num , 'bound' : 'unbound' if bound is None else bound + ' bound' , 'device' : hosting_device [ 'id' ] , 'r_id' : resource [ 'id' ] } ) return False with context . session . begin ( subtransactions = True ) : res_info = { 'resource' : resource , 'type' : resource_type , 'service' : resource_service } slot_info , query = self . _get_or_create_slot_allocation ( context , hosting_device , res_info ) if slot_info is None : LOG . debug ( 'Rejecting allocation of %(num)d slots in hosting ' 'device %(device)s to logical resource %(r_id)s' , { 'num' : num , 'device' : hosting_device [ 'id' ] , 'r_id' : resource [ 'id' ] } ) return False new_allocation = num + slot_info . num_allocated if hosting_device [ 'template' ] [ 'slot_capacity' ] < new_allocation : LOG . debug ( 'Rejecting allocation of %(num)d slots in ' 'hosting device %(device)s to logical resource ' '%(r_id)s due to insufficent slot availability.' , { 'num' : num , 'device' : hosting_device [ 'id' ] , 'r_id' : resource [ 'id' ] } ) self . _dispatch_pool_maintenance_job ( hosting_device [ 'template' ] ) return False if exclusive and bound is None : self . _update_hosting_device_exclusivity ( context , hosting_device , resource [ 'tenant_id' ] ) bound = resource [ 'tenant_id' ] elif not exclusive and bound is not None : self . _update_hosting_device_exclusivity ( context , hosting_device , None ) bound = None slot_info . num_allocated = new_allocation context . session . add ( slot_info ) self . _dispatch_pool_maintenance_job ( hosting_device [ 'template' ] ) LOG . info ( 'Allocated %(num)d additional slots in tenant %(bound)s' 'bound hosting device %(hd_id)s. In total %(total)d ' 'slots are now allocated in that hosting device for ' 'logical resource %(r_id)s.' , { 'num' : num , 'bound' : 'un-' if bound is None else bound + ' ' , 'total' : new_allocation , 'hd_id' : hosting_device [ 'id' ] , 'r_id' : resource [ 'id' ] } ) return True
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.