code: def delete_all_hosting_devices_by_template(self, context, template,
                                                 force_delete=False):
          
          plugging_drv = self.get_hosting_device_plugging_driver(
              context, template['id'])
          hosting_device_drv = self.get_hosting_device_driver(context,
                                                              template['id'])
          if plugging_drv is None or hosting_device_drv is None:
              return
          is_vm = template['host_category'] == VM_CATEGORY
          query = context.session.query(hd_models.HostingDevice)
          query = query.filter(hd_models.HostingDevice.template_id ==
                               template['id'])
          for hd in query:
              if not (hd.auto_delete or force_delete):
                  # device manager is not responsible for life cycle
                  # management of this hosting device.
                  continue
              res = plugging_drv.get_hosting_device_resources(
                  context, hd.id, hd.complementary_id, self.l3_tenant_id(),
                  self.mgmt_nw_id())
              if is_vm:
                  self.svc_vm_mgr.delete_service_vm(context, hd.id)
              plugging_drv.delete_hosting_device_resources(
                  context, self.l3_tenant_id(), **res)
              with context.session.begin(subtransactions=True):
                  # remove all allocations in this hosting device
                  context.session.query(hd_models.SlotAllocation).filter_by(
                      hosting_device_id=hd['id']).delete()
                  context.session.delete(hd)
docs: Deletes all hosting devices based on <template>.