code: def _get_total_available_slots(self, context, template_id, capacity):
          
          query = context.session.query(hd_models.HostingDevice.id)
          query = query.outerjoin(
              hd_models.SlotAllocation,
              hd_models.HostingDevice.id == hd_models.SlotAllocation
              .hosting_device_id)
          query = query.filter(
              hd_models.HostingDevice.template_id == template_id,
              hd_models.HostingDevice.admin_state_up == expr.true(),
              hd_models.HostingDevice.tenant_bound == expr.null())
          query = query.group_by(hd_models.HostingDevice.id)
          query = query.having(
              func.sum(hd_models.SlotAllocation.num_allocated) == expr.null())
          num_hosting_devices = query.count()
          return num_hosting_devices * capacity
docs: Returns available slots in idle devices based on <template_id>.
  
          Only slots in tenant unbound hosting devices are counted to ensure
          there is always hosting device slots available regardless of tenant.