summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorMartin Basti <mbasti@redhat.com>2016-03-02 13:29:27 +0100
committerMartin Basti <mbasti@redhat.com>2016-04-13 17:47:53 +0200
commitb23ad42269c606f234f4f8c545e3c763e648f551 (patch)
tree927114d363b496383e44be9427620a1de95ee02b /ipalib
parent54e3859595e1f5f2e669b8af20afdac1187d8cd7 (diff)
downloadfreeipa-b23ad42269c606f234f4f8c545e3c763e648f551.tar.gz
freeipa-b23ad42269c606f234f4f8c545e3c763e648f551.tar.xz
freeipa-b23ad42269c606f234f4f8c545e3c763e648f551.zip
host-del --updatedns: print warnings instead of error
When DNS records do not exist, print warnings instead of hard error https://fedorahosted.org/freeipa/ticket/5627 Reviewed-By: Petr Spacek <pspacek@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/messages.py11
-rw-r--r--ipalib/plugins/host.py26
2 files changed, 35 insertions, 2 deletions
diff --git a/ipalib/messages.py b/ipalib/messages.py
index 5cd0ea176..872b455c1 100644
--- a/ipalib/messages.py
+++ b/ipalib/messages.py
@@ -360,6 +360,17 @@ class ResultFormattingError(PublicMessage):
type = "warning"
+class FailedToRemoveHostDNSRecords(PublicMessage):
+ """
+ **13020** Failed to remove host DNS records
+ """
+
+ errno = 13020
+ type = "warning"
+ format = _("DNS record(s) of host %(host)s could not be removed. "
+ "(%(reason)s)")
+
+
def iter_messages(variables, base):
"""Return a tuple with all subclasses
"""
diff --git a/ipalib/plugins/host.py b/ipalib/plugins/host.py
index 20b5776dd..04bb2991a 100644
--- a/ipalib/plugins/host.py
+++ b/ipalib/plugins/host.py
@@ -23,6 +23,7 @@ import string
import six
from ipalib import api, errors, util
+from ipalib import messages
from ipalib import Str, Flag, Bytes
from ipalib.plugable import Registry
from ipalib.plugins.baseldap import (LDAPQuery, LDAPObject, LDAPCreate,
@@ -122,6 +123,10 @@ host_pwd_chars = string.digits + string.ascii_letters + '_,.@+-='
def remove_ptr_rec(ipaddr, host, domain):
+ """
+ Remove PTR record of IP address (ipaddr)
+ :return: True if PTR record was removed, False if record was not found
+ """
api.log.debug('deleting PTR record of ipaddr %s', ipaddr)
try:
revzone, revname = get_reverse_zone(ipaddr)
@@ -134,6 +139,9 @@ def remove_ptr_rec(ipaddr, host, domain):
api.Command['dnsrecord_del'](revzone, revname, **delkw)
except errors.NotFound:
api.log.debug('PTR record of ipaddr %s not found', ipaddr)
+ return False
+
+ return True
def update_sshfp_record(zone, record, entry_attrs):
@@ -760,16 +768,20 @@ class host_del(LDAPDelete):
parts = fqdn.split('.')
domain = unicode('.'.join(parts[1:]))
# Get all resources for this host
+ rec_removed = False
try:
record = api.Command['dnsrecord_show'](
domain, parts[0])['result']
except errors.NotFound:
- self.obj.handle_not_found(*keys)
+ pass
else:
# remove PTR records first
for attr in ('arecord', 'aaaarecord'):
for val in record.get(attr, []):
- remove_ptr_rec(val, parts[0], domain)
+ rec_removed = (
+ remove_ptr_rec(val, parts[0], domain) or
+ rec_removed
+ )
try:
# remove all A, AAAA, SSHFP records of the host
api.Command['dnsrecord_mod'](
@@ -781,6 +793,16 @@ class host_del(LDAPDelete):
)
except errors.EmptyModlist:
pass
+ else:
+ rec_removed = True
+
+ if not rec_removed:
+ self.add_message(
+ messages.FailedToRemoveHostDNSRecords(
+ host=fqdn,
+ reason=_("No A, AAAA, SSHFP or PTR records found.")
+ )
+ )
if self.api.Command.ca_is_enabled()['result']:
try: