]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Add parsing for the CellServDB file
authorDavid Howells <dhowells@redhat.com>
Tue, 13 May 2014 14:02:16 +0000 (15:02 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 13 May 2014 16:36:35 +0000 (17:36 +0100)
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>
suite/lib/cell.py

index 9fdfa1eef7187b9a9d0e63d93bc115de52d0efb8..57b4e24464009ca00b451111d1f89592110016dc 100644 (file)
@@ -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