def _get_total_available_slots(self, context, template_id, capacity):
query = context.session.query(hd_models.HostingDevice.id)<EOL>query = query.outerjoin(<EOL>hd_models.SlotAllocation,<EOL>hd_models.HostingDevice.id == hd_models.SlotAllocation<EOL>.hosting_device_id)<EOL>query = query.filter(<EOL>hd_models.HostingDevice.template_id == template_id,<EOL>hd_models.HostingDevice.admin_state_up == expr.true(),<EOL>hd_models.HostingDevice.tenant_bound == expr.null())<EOL>query = query.group_by(hd_models.HostingDevice.id)<EOL>query = query.having(<EOL>func.sum(hd_models.SlotAllocation.num_allocated) == expr.null())<EOL>num_hosting_devices = query.count()<EOL>return num_hosting_devices * capacity<EOL>
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.