def Delete()

in perfkitbenchmarker/benchmark_spec.py [0:0]


  def Delete(self):
    if self.deleted:
      return

    should_freeze = (
        hasattr(self, 'freeze_path') and self.freeze_path is not None
    )
    if should_freeze:
      self.Freeze()

    if self.container_registry:
      self.container_registry.Delete()
    if self.dpb_service:
      self.dpb_service.Delete()
    if hasattr(self, 'relational_db') and self.relational_db:
      self.relational_db.Delete(freeze=should_freeze)
    if hasattr(self, 'non_relational_db') and self.non_relational_db:
      self.non_relational_db.Delete(freeze=should_freeze)
    if hasattr(self, 'key') and self.key:
      self.key.Delete()
    if self.tpus:
      background_tasks.RunThreaded(lambda tpu: tpu.Delete(), self.tpus)
    if self.edw_service:
      self.edw_service.Delete()
    if hasattr(self, 'edw_compute_resource') and self.edw_compute_resource:
      self.edw_compute_resource.Delete()
    if self.example_resource:
      self.example_resource.Delete()
    if self.base_job:
      self.base_job.Delete()
    if self.nfs_service:
      self.nfs_service.Delete()
    if self.smb_service:
      self.smb_service.Delete()
    if hasattr(self, 'messaging_service') and self.messaging_service:
      self.messaging_service.Delete()
    if hasattr(self, 'memory_store') and self.memory_store:
      self.memory_store.Delete()
    if hasattr(self, 'ai_model') and self.ai_model:
      self.ai_model.Delete()
    if hasattr(self, 'data_discovery_service') and self.data_discovery_service:
      self.data_discovery_service.Delete()
    if hasattr(self, 'pinecone') and self.pinecone:
      self.pinecone.Delete()

    # Note: It is ok to delete capacity reservations before deleting the VMs,
    # and will actually save money (mere seconds of usage).
    if self.capacity_reservations:
      try:
        background_tasks.RunThreaded(
            lambda reservation: reservation.Delete(), self.capacity_reservations
        )
      except Exception:  # pylint: disable=broad-except
        logging.exception(
            'Got an exception deleting CapacityReservations. '
            'Attempting to continue tearing down.'
        )

    if self.vms:
      try:
        # Delete VMs first to detach any multi-attached disks.
        background_tasks.RunThreaded(self.DeleteVm, self.vms)
        background_tasks.RunThreaded(
            lambda vm: vm.DeleteScratchDisks(), self.vms
        )
      except Exception:
        logging.exception(
            'Got an exception deleting VMs. '
            'Attempting to continue tearing down.'
        )
    if hasattr(self, 'placement_groups'):
      for placement_group_object in self.placement_groups.values():
        placement_group_object.Delete()

    for firewall in self.firewalls.values():
      try:
        firewall.DisallowAllPorts()
      except Exception:
        logging.exception(
            'Got an exception disabling firewalls. '
            'Attempting to continue tearing down.'
        )

    if self.container_cluster:
      self.container_cluster.DeleteServices()
      self.container_cluster.DeleteContainers()
      self.container_cluster.Delete()

    if self.cluster:
      self.cluster.Delete()

    for net in self.networks.values():
      try:
        net.Delete()
      except Exception:
        logging.exception(
            'Got an exception deleting networks. '
            'Attempting to continue tearing down.'
        )

    if hasattr(self, 'vpn_service') and self.vpn_service:
      self.vpn_service.Delete()

    self.deleted = True