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
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))
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" ],
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
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
--- /dev/null
+#
+# 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()
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):