From: David Howells <dhowells@redhat.com> Date: Tue, 13 May 2014 14:02:16 +0000 (+0100) Subject: Add parsing for the CellServDB file X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=967190d3c17085181fdb2b9d822ef84eaaa3af2b;p=users%2Fdhowells%2Fkafs-utils.git Add parsing for the CellServDB file Add parsing for the CellServDB file if the DNS doesn't throw up AFSDB or SRV records for volume location database servers. Signed-off-by: David Howells <dhowells@redhat.com> --- diff --git a/suite/lib/cell.py b/suite/lib/cell.py index 9fdfa1e..57b4e24 100644 --- a/suite/lib/cell.py +++ b/suite/lib/cell.py @@ -58,10 +58,10 @@ class cell: def __str__(self): return self.__name - def add_server(self, dnstype, name): + def add_server(self, dnstype, name, addr=None): n = str(name).lower().rstrip(".") if n not in self.__vlserver_names: - s = vlserver(n) + s = vlserver(n, addr) self.__vlserver_names[n] = s self.__vlservers.append(s) @@ -84,7 +84,35 @@ class cell: verbose("Couldn't find any AFSDB records\n") # Then parse the local afsdb file - # ... TODO ... + # + # There is a problem here: the CellServDB file is liable to contain + # accented characters that aren't UTF-8, so we *have* to be set an + # appropriate encoding otherwise Python will raise an exception. + # Unfortunately, the character set for this file has not been + # standardised... + # + verbose("-- Searching CellServDB for cell: ", self.__name, " --\n") + found_cell = False + for line in open("/etc/openafs/CellServDB", "r", encoding="iso8859_1"): + line = str(line.rstrip()) + if line == "": + continue + comment_ix = line.find("#") + if comment_ix == 0: + continue + comment = "" + if comment_ix > 0: + comment = line[comment_ix + 1:].lstrip() + line = line[:comment_ix].rstrip() + if line[0] == ">": + # New cell name + if found_cell: + break + if line[1:] == self.__name: + found_cell = True + continue + if found_cell: + self.add_server("CellServDB", comment, line) self.__looked_up = True