]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
"vos listvldb -server xxx" takes a fileserver name, not a vlserver name
authorDavid Howells <dhowells@redhat.com>
Tue, 8 Apr 2014 17:08:30 +0000 (18:08 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 8 Apr 2014 17:08:30 +0000 (18:08 +0100)
"vos listvldb -server xxx" takes a fileserver name, not a vlserver name, so
provide a class for that and change the argument list.

Signed-off-by: David Howells <dhowells@redhat.com>
suite/argparse.py
suite/commands/vos/listvldb.py
suite/lib/addrcache.py
suite/lib/cell.py
suite/lib/fileserver.py [new file with mode: 0644]
suite/lib/vlserver.py

index f0ffcec4df28f15628d7a2784dc54237b2d69348..777b15f3681260021db6bc46572bf83c31e214e2 100644 (file)
@@ -17,9 +17,9 @@ def get_cell(switch, params):
     from afs.lib.cell import cell
     return cell(params[0])
 
-def get_vlserver(switch, params):
-    from afs.lib.vlserver import vlserver
-    return vlserver(params[0])
+def get_fileserver(switch, params):
+    from afs.lib.fileserver import fileserver
+    return fileserver(params[0])
 
 def get_volume_name(switch, params):
     return params
@@ -206,9 +206,3 @@ def parse_arguments(args, available_arguments):
             raise RuntimeError("Missing '-" + switch + "' argument")
 
     return result
-
-
-#if len(sys.argv) < 2:
-#    raise RuntimeError("Need command name")
-#
-#print(parse_arguments(sys.argv[2:], fs_mkmount_arguments))
index 41aa96ec818c2d6277cded5136a6898364c0de03..b0bb5324edc9a1f84f2bdd5942130ed068093711 100644 (file)
@@ -30,7 +30,7 @@ help = "Query the VLDB"
 
 command_arguments = [
     [ "name",           get_volume_name,        "os",         "<volume name or ID>" ],
-    [ "server",         get_vlserver,           "os",         "<machine name>" ],
+    [ "server",         get_fileserver,         "os",         "<machine name>" ],
     [ "partition",      get_partition_id,       "os",         "<partition name>" ],
     [ "locked",         get_dummy,              "fn" ],
     [ "quiet",          get_dummy,              "fn" ],
index e83d3189482503bf25e6a77aaab8e9e37956cec9..d1e9919add057b56c25fd23b42118da08f14ad29 100644 (file)
@@ -55,12 +55,13 @@ def name2addr(name):
     except OSError:
         pass
 
+    name = name.lower().rstrip(".")
     if name in cache_n2a:
         return cache_n2a[name]
 
     try:
         for A in dns.resolver.query(name, 'A'):
-            addrcache.add(name, A.address)
+            add(name, A.address)
     except dns.resolver.NoAnswer:
         pass
 
index 267c71527d0c992e18b6b31b602baff49843cf16..a721cec5a7247d853a96e6c4d33f0c4e1b5fca97 100644 (file)
@@ -58,7 +58,7 @@ class cell:
         return self.__name
 
     def add_server(self, dnstype, name):
-        n = str(name)
+        n = str(name).lower().rstrip(".")
         if n not in self.__vlserver_names:
             s = vlserver(n)
             self.__vlserver_names[n] = s
diff --git a/suite/lib/fileserver.py b/suite/lib/fileserver.py
new file mode 100644 (file)
index 0000000..2a7c6ee
--- /dev/null
@@ -0,0 +1,63 @@
+#
+# AFS Volume management toolkit: File server record
+# -*- coding: utf-8 -*-
+#
+
+__copyright__ = """
+Copyright (C) 2014 Red Hat, Inc. All Rights Reserved.
+Written by David Howells (dhowells@redhat.com)
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public Licence version 2 as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public Licence for more details.
+
+You should have received a copy of the GNU General Public Licence
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+from afs import exception
+import afs.lib.addrcache as addrcache
+from afs.lib.debug import debug
+import dns.resolver
+
+class FileServerError(exception.AFSException):
+    """Error raised by L{fileserver} objects."""
+
+class fileserver:
+    """Represents an AFS File server.  We hold the server address here."""
+    def __init__(self, name):
+        debug("New FileServer", name)
+        self.__name = name
+        self.__looked_up = False
+
+        # We want to maintain the record order provided by the DNS to entry
+        # force rotation, so we don't want to use an unordered set here.
+        #
+        # Note that the addrs are stored as text strings of the form "a.b.c.d"
+        self.__addrs = []
+
+    def __repr__(self):
+        return "<" + "AFSFS:" + self.__name + ">"
+
+    def __str__(self):
+        return self.__name
+
+    def look_up_addresses(self):
+        self.__addrs = addrcache.name2addr(self.__name)
+        self.__looked_up = True
+
+    def look_up(self):
+        if not self.__looked_up:
+            self.look_up_addresses()
+        if len(self.__addrs) == 0:
+            raise FileServerError("No FileServer addresses available")
+        return self.__addrs
+
+    def addrs(self):
+        return self.look_up()
index 9570fff0f1e729a43416544c06005f269df0a653..cf75631098356d03f8a3fb8eea7aa1fe76c48135 100644 (file)
@@ -50,33 +50,7 @@ class vlserver:
         return self.__name
 
     def look_up_addresses(self):
-        addr = False
-
-        # Try parsing as a numeric IPv4 address
-        try:
-            addr = inet_pton(AF_INET, self.__name)
-            self.__addrs.append(self.__name)
-        except OSError:
-            pass
-
-        # Try parsing as a numeric IPv6 address
-        if not addr:
-            try:
-                addr = inet_pton(AF_INET6, self.__name)
-                raise VLServerError("IPv6 is not currently supported")
-            except OSError:
-                pass
-
-        # Try looking up in the DNS
-        if not addr:
-            try:
-                for A in dns.resolver.query(self.__name, 'A'):
-                    if A.address not in self.__addrs:
-                        self.__addrs.append(A.address)
-                        addrcache.add(self.__name, A.address)
-            except dns.resolver.NoAnswer:
-                pass
-
+        self.__addrs = addrcache.name2addr(self.__name)
         self.__looked_up = True
 
     def look_up(self):