code: def domain_delete(domain, logger):
      
      if domain is not None:
          try:
              if domain.isActive():
                  domain.destroy()
          except libvirt.libvirtError:
              logger.exception("Unable to destroy the domain.")
          try:
              domain.undefine()
          except libvirt.libvirtError:
              try:
                  domain.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA)  # domain with snapshots
              except libvirt.libvirtError:
                  logger.exception("Unable to undefine the domain.")
docs: libvirt domain undefinition.
  
      @raise: libvirt.libvirtError.