DNS Locations: location-del: remove location record

Remove unused location records

https://fedorahosted.org/freeipa/ticket/2008

Reviewed-By: Petr Spacek <pspacek@redhat.com>
This commit is contained in:
Martin Basti 2016-06-16 16:46:29 +02:00
parent bbf8227e3f
commit 3c50e42036
2 changed files with 43 additions and 3 deletions

View File

@ -78,6 +78,9 @@ class IPASystemRecords(object):
return weight, location, roles
def __get_location_suffix(self, location):
return location + DNSName('_locations') + self.domain_abs
def __init_data(self):
self.servers_data = {}
self.used_locations = set()
@ -104,9 +107,7 @@ class IPASystemRecords(object):
assert isinstance(weight, int)
if location:
suffix = (
location + DNSName('_locations') + self.domain_abs
)
suffix = self.__get_location_suffix(location)
else:
suffix = self.domain_abs
@ -388,6 +389,40 @@ class IPASystemRecords(object):
self.update_locations_records()
)
def remove_location_records(self, location):
"""
Remove all location records
:param location: DNSName object
:return: list of successfuly removed record names, list of record
names that cannot be removed and returned exception in tuples
[rname1, ...], [(rname2, exc), ...]
"""
success = []
failed = []
location = DNSName(location)
loc_records = []
for records in (
IPA_DEFAULT_MASTER_SRV_REC,
IPA_DEFAULT_ADTRUST_SRV_REC,
):
for name, _port in records:
loc_records.append(
name + self.__get_location_suffix(location))
for rname in loc_records:
try:
self.api_instance.Command.dnsrecord_del(
self.domain_abs, rname, del_all=True)
except errors.NotFound:
pass
except errors.PublicError as e:
failed.append((rname, e))
else:
success.append(rname)
return success, failed
@classmethod
def records_list_from_node(cls, name, node):
records = []

View File

@ -18,6 +18,7 @@ from ipalib import (
)
from ipalib.errors import DependentEntry
from ipalib.plugable import Registry
from ipaserver.dns_data_management import IPASystemRecords
from ipaserver.plugins.baseldap import (
LDAPCreate,
LDAPSearch,
@ -151,6 +152,10 @@ class location_del(LDAPDelete):
key=keys[-1],
dependent=location_member
)
system_records =IPASystemRecords(self.api)
_success, failed = system_records.remove_location_records(keys[-1])
if failed:
self.add_message(messages.AutomaticDNSRecordsUpdateFailed())
return dn