def delete_all_hosting_devices_by_template(self, context, template,<EOL>force_delete=False):
plugging_drv = self.get_hosting_device_plugging_driver(<EOL>context, template['<STR_LIT:id>'])<EOL>hosting_device_drv = self.get_hosting_device_driver(context,<EOL>template['<STR_LIT:id>'])<EOL>if plugging_drv is None or hosting_device_drv is None:<EOL><INDENT>return<EOL><DEDENT>is_vm = template['<STR_LIT>'] == VM_CATEGORY<EOL>query = context.session.query(hd_models.HostingDevice)<EOL>query = query.filter(hd_models.HostingDevice.template_id ==<EOL>template['<STR_LIT:id>'])<EOL>for hd in query:<EOL><INDENT>if not (hd.auto_delete or force_delete):<EOL><INDENT>continue<EOL><DEDENT>res = plugging_drv.get_hosting_device_resources(<EOL>context, hd.id, hd.complementary_id, self.l3_tenant_id(),<EOL>self.mgmt_nw_id())<EOL>if is_vm:<EOL><INDENT>self.svc_vm_mgr.delete_service_vm(context, hd.id)<EOL><DEDENT>plugging_drv.delete_hosting_device_resources(<EOL>context, self.l3_tenant_id(), **res)<EOL>with context.session.begin(subtransactions=True):<EOL><INDENT>context.session.query(hd_models.SlotAllocation).filter_by(<EOL>hosting_device_id=hd['<STR_LIT:id>']).delete()<EOL>context.session.delete(hd)<EOL><DEDENT><DEDENT>
Deletes all hosting devices based on <template>.