summaryrefslogtreecommitdiff
path: root/cloudinit/distros/rhel.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/distros/rhel.py')
-rw-r--r--cloudinit/distros/rhel.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index bf3c18d2..13fd5ec8 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -23,6 +23,8 @@
import os
from cloudinit import distros
+from cloudinit.distros import helpers as d_helpers
+
from cloudinit import helpers
from cloudinit import log as logging
from cloudinit import util
@@ -81,16 +83,29 @@ class Distro(distros.Distro):
def install_packages(self, pkglist):
self.package_command('install', pkglist)
- def _write_resolve(self, dns_servers, search_servers):
- contents = []
+ def _adjust_resolve(self, dns_servers, search_servers):
+ r_conf = d_helpers.ResolvConf(util.load_file("/etc/resolv.conf"))
+ try:
+ r_conf.parse()
+ except IOError:
+ util.logexc(LOG,
+ "Failed at parsing %s reverting to an empty instance",
+ "/etc/resolv.conf")
+ r_conf = d_helpers.ResolvConf('')
+ r_conf.parse()
if dns_servers:
for s in dns_servers:
- contents.append("nameserver %s" % (s))
+ try:
+ r_conf.add_nameserver(s)
+ except ValueError:
+ util.logexc(LOG, "Failed at adding nameserver %s", s)
if search_servers:
- contents.append("search %s" % (" ".join(search_servers)))
- if contents:
- contents.insert(0, _make_header())
- util.write_file("/etc/resolv.conf", "\n".join(contents), 0644)
+ for s in search_servers:
+ try:
+ r_conf.add_search_domain(s)
+ except ValueError:
+ util.logexc(LOG, "Failed at adding search domain %s", s)
+ util.write_file("/etc/resolv.conf", str(r_conf), 0644)
def _write_network(self, settings):
# TODO(harlowja) fix this... since this is the ubuntu format