[node-patches] Change in ovirt-node[master]: network: Allow removal of all DNS and NTP servers

fabiand at fedoraproject.org fabiand at fedoraproject.org
Fri Oct 26 05:53:00 UTC 2012


Fabian Deutsch has uploaded a new change for review.

Change subject: network: Allow removal of all DNS and NTP servers
......................................................................

network: Allow removal of all DNS and NTP servers

Previously it was not possible to retrieve DNS servers via DNS after
they were set manually. Now this is possible again.

Change-Id: Ia557267e8edd8dfe6db05aa3a54dad60e58b8b85
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/ovirt-config-setup.py
M scripts/ovirtnode/network.py
2 files changed, 43 insertions(+), 30 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/46/8846/1

diff --git a/scripts/ovirt-config-setup.py b/scripts/ovirt-config-setup.py
index c903c63..f5341bf 100755
--- a/scripts/ovirt-config-setup.py
+++ b/scripts/ovirt-config-setup.py
@@ -1493,14 +1493,17 @@
             ntp_servers.append(self.ntp_host1.value())
         if not self.ntp_host2.value() == "":
             ntp_servers.append(self.ntp_host2.value())
-        if len(dns_servers) > 0:
-            dns_servers = ",".join(dns_servers)
-            augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_DNS",
-                    '"' + dns_servers + '"')
-        if len(ntp_servers) > 0:
-            ntp_servers = ",".join(ntp_servers)
-            augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_NTP",
-                    '"' + ntp_servers + '"')
+
+        # Save DNS servers
+        dns_servers = ",".join(dns_servers)
+        augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_DNS",
+                '"' + dns_servers + '"')
+
+        # Save NTP servers
+        ntp_servers = ",".join(ntp_servers)
+        augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_NTP",
+                '"' + ntp_servers + '"')
+
         aug.load()
 
         # Then apply the configuration
diff --git a/scripts/ovirtnode/network.py b/scripts/ovirtnode/network.py
index 23ba228..0eb5ffe 100644
--- a/scripts/ovirtnode/network.py
+++ b/scripts/ovirtnode/network.py
@@ -207,34 +207,44 @@
         OVIRT_VARS = _functions.parse_defaults()
         if "OVIRT_DNS" in OVIRT_VARS:
             DNS = OVIRT_VARS["OVIRT_DNS"]
+            have_nopeerdns = True
             try:
-                if DNS is not None:
-                    tui_cmt = ("Please make changes through the TUI. " + \
-                               "Manual edits to this file will be " + \
-                               "lost on reboot")
-                    _functions.augtool("set", \
-                                       "/files/etc/resolv.conf/#comment[1]", \
-                                       tui_cmt)
-                    DNS = DNS.split(",")
-                    i = 1
-                    for server in DNS:
-                        logger.debug("Setting DNS server %d: %s" % (i, server))
-                        setting = "/files/etc/resolv.conf/nameserver[%s]" % i
-                        _functions.augtool("set", setting, server)
-                        i = i + i
-                    _functions.ovirt_store_config("/etc/resolv.conf")
-                else:
-                    logger.debug("No DNS servers given.")
+                if DNS is None or DNS == "":
+                    logger.debug("No DNS servers given, removing PEERDNS")
+                    have_nopeerdns = False
+
+                # Write resolv.conf any way, sometimes without servers
+                tui_cmt = ("Please make changes through the TUI. " + \
+                           "Manual edits to this file will be " + \
+                           "lost on reboot")
+                _functions.augtool("set", \
+                                   "/files/etc/resolv.conf/#comment[1]", \
+                                   tui_cmt)
+                DNS = DNS.split(",")
+                i = 1
+                for server in DNS:
+                    logger.debug("Setting DNS server %d: %s" % (i, server))
+                    setting = "/files/etc/resolv.conf/nameserver[%s]" % i
+                    _functions.augtool("set", setting, server)
+                    i = i + i
+                _functions.ovirt_store_config("/etc/resolv.conf")
             except:
                 logger.warn("Failed to set DNS servers")
             finally:
-                if len(DNS) < 2:
-                    _functions.augtool("rm", \
-                                    "/files/etc/resolv.conf/nameserver[2]", "")
+                # Remove all spare DNS servers
+                for n in range(len(DNS), 2):
+                    path = "/files/etc/resolv.conf/nameserver[%d]" % (n + 1)
+                    _functions.augtool("rm", path, "")
+
+                # Set or remove PEERDNS for all ifcfg-*
                 for nic in glob("/etc/sysconfig/network-scripts/ifcfg-*"):
-                    if not "ifcfg-lo" in nic:
-                        path = "/files%s/PEERDNS" % nic
+                    if "ifcfg-lo" in nic:
+                        continue
+                    path = "/files%s/PEERDNS" % nic
+                    if have_nopeerdns:
                         _functions.augtool("set", path, "no")
+                    else
+                        _functions.augtool("rm", path, "")
 
     def configure_ntp(self):
         if "OVIRT_NTP" in OVIRT_VARS:


--
To view, visit http://gerrit.ovirt.org/8846
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia557267e8edd8dfe6db05aa3a54dad60e58b8b85
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list