working _delete_domain

This commit is contained in:
David Kennedy 2024-12-11 14:12:42 -05:00
parent 1a9b671758
commit e0eb70abe2
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B

View file

@ -1038,28 +1038,46 @@ class Domain(TimeStampedModel, DomainHelper):
"""This domain should be deleted from the registry
may raises RegistryError, should be caught or handled correctly by caller"""
logger.info("Deleting subdomains for %s", self.name)
# check if any subdomains are in use by another domain
hosts = Host.objects.filter(name__regex=r".+{}".format(self.name))
logger.debug("Checking if any subdomains are in use by another domain")
for host in hosts:
if host.domain != self:
logger.error("Unable to delete host: %s is in use by another domain: %s", host.name, host.domain)
raise RegistryError(
code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION,
note=f"Host {host.name} is in use by {host.domain}",
)
logger.debug("No subdomains are in use by another domain")
# logger.info("Deleting subdomains for %s", self.name)
# # check if any subdomains are in use by another domain
# hosts = Host.objects.filter(name__regex=r".+{}".format(self.name))
# logger.debug("Checking if any subdomains are in use by another domain")
# for host in hosts:
# if host.domain != self:
# logger.error("Unable to delete host: %s is in use by another domain: %s", host.name, host.domain)
# raise RegistryError(
# code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION,
# note=f"Host {host.name} is in use by {host.domain}",
# )
# logger.debug("No subdomains are in use by another domain")
nameservers = [host.name for host in hosts]
hosts = self.createDeleteHostList(hostsToDelete=nameservers)
response_code = self.addAndRemoveHostsFromDomain(hostsToAdd=None, hostsToDelete=hosts)
if response_code != ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY:
raise RegistryError(code=response_code)
# nameservers = [host.name for host in hosts]
# hosts = self.createDeleteHostList(hostsToDelete=nameservers)
# response_code = self.addAndRemoveHostsFromDomain(hostsToAdd=[], hostsToDelete=hosts)
# if response_code != ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY:
# raise RegistryError(code=response_code)
logger.debug("Deleting subordinate hosts for %s", self.name)
self._delete_hosts_if_not_used(nameservers)
# logger.debug("Deleting subordinate hosts for %s", self.name)
# self._delete_hosts_if_not_used(nameservers)
(
deleted_values,
updated_values,
new_values,
oldNameservers,
) = self.getNameserverChanges(hosts=[])
_ = self._update_host_values(updated_values, oldNameservers) # returns nothing, just need to be run and errors
addToDomainList, addToDomainCount = self.createNewHostList(new_values)
deleteHostList, deleteCount = self.createDeleteHostList(deleted_values)
responseCode = self.addAndRemoveHostsFromDomain(hostsToAdd=addToDomainList, hostsToDelete=deleteHostList)
# if unable to update domain raise error and stop
if responseCode != ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY:
raise NameserverError(code=nsErrorCodes.BAD_DATA)
self._delete_hosts_if_not_used(hostsToDelete=deleted_values)
logger.debug("Deleting non-registrant contacts for %s", self.name)
contacts = PublicContact.objects.filter(domain=self)
for contact in contacts: