mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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:
@@ -78,6 +78,9 @@ class IPASystemRecords(object):
|
|||||||
|
|
||||||
return weight, location, roles
|
return weight, location, roles
|
||||||
|
|
||||||
|
def __get_location_suffix(self, location):
|
||||||
|
return location + DNSName('_locations') + self.domain_abs
|
||||||
|
|
||||||
def __init_data(self):
|
def __init_data(self):
|
||||||
self.servers_data = {}
|
self.servers_data = {}
|
||||||
self.used_locations = set()
|
self.used_locations = set()
|
||||||
@@ -104,9 +107,7 @@ class IPASystemRecords(object):
|
|||||||
assert isinstance(weight, int)
|
assert isinstance(weight, int)
|
||||||
|
|
||||||
if location:
|
if location:
|
||||||
suffix = (
|
suffix = self.__get_location_suffix(location)
|
||||||
location + DNSName('_locations') + self.domain_abs
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
suffix = self.domain_abs
|
suffix = self.domain_abs
|
||||||
|
|
||||||
@@ -388,6 +389,40 @@ class IPASystemRecords(object):
|
|||||||
self.update_locations_records()
|
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
|
@classmethod
|
||||||
def records_list_from_node(cls, name, node):
|
def records_list_from_node(cls, name, node):
|
||||||
records = []
|
records = []
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ from ipalib import (
|
|||||||
)
|
)
|
||||||
from ipalib.errors import DependentEntry
|
from ipalib.errors import DependentEntry
|
||||||
from ipalib.plugable import Registry
|
from ipalib.plugable import Registry
|
||||||
|
from ipaserver.dns_data_management import IPASystemRecords
|
||||||
from ipaserver.plugins.baseldap import (
|
from ipaserver.plugins.baseldap import (
|
||||||
LDAPCreate,
|
LDAPCreate,
|
||||||
LDAPSearch,
|
LDAPSearch,
|
||||||
@@ -151,6 +152,10 @@ class location_del(LDAPDelete):
|
|||||||
key=keys[-1],
|
key=keys[-1],
|
||||||
dependent=location_member
|
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
|
return dn
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user