diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-10-10 14:03:08 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-10-10 14:03:08 -0700 |
commit | f8b71af537aab3aef04a1e5ceba19e90a1445948 (patch) | |
tree | 9fe1f4e1f25d35709472f531dd2d5028dceae34f /cloudinit/distros/rhel.py | |
parent | 4a3eab9f5a49f8ebdf30b8378fa58c342b3d9c8a (diff) | |
parent | 6e0f6f3db662751c2b0bf837f2affe51b1f328a3 (diff) | |
download | vyos-cloud-init-f8b71af537aab3aef04a1e5ceba19e90a1445948.tar.gz vyos-cloud-init-f8b71af537aab3aef04a1e5ceba19e90a1445948.zip |
Merge the resolv.conf branch in
preparation for having a new branch
for all of these changes.
Diffstat (limited to 'cloudinit/distros/rhel.py')
-rw-r--r-- | cloudinit/distros/rhel.py | 29 |
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 |