]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Implement "vos listaddrs"
authorDavid Howells <dhowells@redhat.com>
Wed, 9 Apr 2014 16:44:11 +0000 (17:44 +0100)
committerDavid Howells <dhowells@redhat.com>
Wed, 9 Apr 2014 20:28:08 +0000 (21:28 +0100)
Signed-off-by: David Howells <dhowells@redhat.com>
suite/argparse.py
suite/commands/vos/listaddrs.py [new file with mode: 0644]
suite/lib/addrcache.py
suite/lib/uuid.py [new file with mode: 0644]

index d27e4f1b947c205f0697e5b3a5d7ce8de697330a..6384a378420ae9658baf9bf520f069d68240adc4 100644 (file)
@@ -60,6 +60,11 @@ def get_partition_id(switch, params):
 def get_auth(switch, params):
     return params
 
+def get_uuid(switch, params):
+    from afs.lib.uuid import str2uuid
+    return str2uuid(params[0])
+
+
 def get_dummy(switch, params):
     return params
 
diff --git a/suite/commands/vos/listaddrs.py b/suite/commands/vos/listaddrs.py
new file mode 100644 (file)
index 0000000..68573af
--- /dev/null
@@ -0,0 +1,106 @@
+#
+# AFS Volume management toolkit: Volume location database list
+# -*- 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.argparse import *
+from afs.lib.debug import debug
+from afs.lib.uuid import uuid2str
+import afs.lib.addrcache as addrcache
+import kafs
+
+help = "Display all VLDB entries"
+
+command_arguments = [
+    [ "uuid",           get_uuid,               "os",         "<uuid of server>" ],
+    [ "host",           get_dummy,              "os",         "<address of host>" ],
+    [ "printuuid",      get_dummy,              "fn" ],
+    [ "cell",           get_cell,               "os",         "<cell name>" ],
+    [ "noauth",         get_auth,               "fn" ],
+    [ "localauth",      get_auth,               "fn" ],
+    [ "verbose",        get_dummy,              "fn" ],
+    [ "encrypt",        get_dummy,              "fn" ],
+    [ "noresolve",      get_dummy,              "fn" ],
+]
+
+cant_combine_arguments = [
+    ( "cell",           "localauth" ),
+    ( "noauth",         "localauth" ),
+    ( "uuid",           "host" ),
+]
+
+description = r"""
+Display all VLDB entries
+"""
+
+def list_one(params, vl_conn, attributes):
+    ret = kafs.VL_GetAddrsU(vl_conn, attributes)
+    if "printuuid" in params:
+        print("UUID:", uuid2str(ret.uuidp1))
+
+    addrs = ret.blkaddrs
+    for a in addrs:
+        print(addrcache.resolve(params, a))
+    if "printuuid" in params:
+        print()
+
+def list_all(params, vl_conn):
+    ret = kafs.VL_GetAddrs(vl_conn, 0, 0)
+    print("nentries", ret.nentries)
+
+    found = ret.nentries
+    limit = ret.nentries * 2
+    attributes = kafs.ListAddrByAttributes()
+    attributes.Mask |= kafs.VLADDR_INDEX
+    for index in range(1, 65536):
+        debug("Look up", index)
+
+        attributes.index = index
+        try:
+            list_one(params, vl_conn, attributes)
+            found -= 1
+        except kafs.RemoteAbort as msg:
+            if str(msg) == "Aborted 363524":
+                continue
+            elif str(msg) == "Aborted 363549":
+                break
+            else:
+                raise
+        if found <= 0:
+            break
+
+def main(params):
+    cell = params["cell"]
+    vl_conn = cell.open_vl_server(params)
+
+    if "uuid" not in params and "host" not in params:
+        return list_all(params, vl_conn)
+
+    attributes = kafs.ListAddrByAttributes()
+    attributes.Mask = 0
+    if "uuid" in params:
+        attributes.Mask |= kafs.VLADDR_UUID
+        attributes.uuid = params["uuid"]
+    if "host" in params:
+        attributes.Mask |= kafs.VLADDR_IPADDR
+        attributes.uuid = params["uuid"]
+
+    list_one(params, vl_conn, attributes)
index d1e9919add057b56c25fd23b42118da08f14ad29..6cfb4d90fbc5f63b656cbfc05e6f7587c0793a83 100644 (file)
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 from afs import exception
-from socket import inet_pton, AF_INET, AF_INET6;
+from socket import inet_pton, inet_ntoa, AF_INET, AF_INET6;
 import dns.reversename
 import dns.resolver
 
@@ -105,6 +105,24 @@ def addr2name(addr):
                 return name
 
             return None
-        except dns.resolver.NoAnswer:
+        except (dns.resolver.NoAnswer, dns.resolver.NXDOMAIN):
             return None
     return cache_a2n[addr]
+
+def int2addr(i):
+    inaddr = bytearray(4)
+    inaddr[0] = (i >> 24) & 0xff
+    inaddr[1] = (i >> 16) & 0xff
+    inaddr[2] = (i >>  8) & 0xff
+    inaddr[3] = (i >>  0) & 0xff
+    return inet_ntoa(bytes(inaddr))
+
+def resolve(params, addr):
+    if str(type(addr)) == "<class 'int'>":
+        addr = int2addr(addr)
+    if "noresolve" in params:
+        return addr
+    name = addr2name(addr)
+    if name == None:
+        return addr
+    return name
diff --git a/suite/lib/uuid.py b/suite/lib/uuid.py
new file mode 100644 (file)
index 0000000..35db3ba
--- /dev/null
@@ -0,0 +1,58 @@
+#
+# AFS Volume management toolkit: UUID handling
+# -*- 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
+"""
+
+def uuid2str(uuid):
+    """Convert an afsUUID-class object into a UUID string"""
+    s = "{:08x}-{:04x}-{:04x}-{:02x}-{:02x}-".format(uuid.time_low,
+                                                     uuid.time_mid,
+                                                     uuid.time_hi_and_version,
+                                                     uuid.clock_seq_hi_and_reserved,
+                                                     uuid.clock_seq_low)
+    for i in range(0, 6):
+        s += "{:02x}".format(uuid.node[i])
+    return s
+
+def str2uuid(s):
+    """Convert a UUID string into an afsUUID-class object"""
+    if (len(s) != 32 + 5 or
+        s[ 8] != "-" or
+        s[13] != "-" or
+        s[18] != "-" or
+        s[21] != "-" or
+        s[24] != "-"):
+        raise RuntimeError("Invalid UUID format")
+
+    from kafs import afsUUID
+    uuid = afsUUID()
+    uuid.time_low                       = int(s[0:8], 16)
+    uuid.time_mid                       = int(s[9:13], 16)
+    uuid.time_hi_and_version            = int(s[14:18], 16)
+    uuid.clock_seq_hi_and_reserved      = int(s[19:21], 16)
+    uuid.clock_seq_low                  = int(s[22:24], 16)
+    uuid.node[0]                        = int(s[25:27], 16)
+    uuid.node[1]                        = int(s[27:29], 16)
+    uuid.node[2]                        = int(s[29:31], 16)
+    uuid.node[3]                        = int(s[31:33], 16)
+    uuid.node[4]                        = int(s[33:35], 16)
+    uuid.node[5]                        = int(s[35:37], 16)
+    return uuid