Implement "bos listhosts" and "bos getcell"
authorDavid Howells <dhowells@redhat.com>
Fri, 11 Apr 2014 15:46:18 +0000 (16:46 +0100)
committerDavid Howells <dhowells@redhat.com>
Fri, 11 Apr 2014 15:46:18 +0000 (16:46 +0100)
Signed-off-by: David Howells <dhowells@redhat.com>
rpc-api/bos.xg
suite/argparse.py
suite/commands/bos/__init__.py [new file with mode: 0644]
suite/commands/bos/getcell.py [new file with mode: 0644]
suite/commands/bos/listhosts.py [new file with mode: 0644]
suite/lib/bosserver.py [new file with mode: 0644]
suite/lib/cell.py

index e7273b33fde3c8445299ea508d298d9a1bba8396..4eb67f52e953869ec0ff7feda59d2b8cb4c31cf8 100644 (file)
@@ -37,6 +37,9 @@
 
 package BOZO_
 
+const BOSSERVICE_PORT          = 7007;
+const BOSSERVICE_ID            = 1;
+
 /* Error codes */
 const BZNOTACTIVE              = 39424;
 const BZNOENT                  = 39425;
index 9c57d53b28ee8de01742f24bdf586260da254947..6acb7143a09c727173ee0dc45cbae35110d3cec6 100644 (file)
@@ -17,6 +17,10 @@ def get_cell(switch, params):
     from afs.lib.cell import cell
     return cell(params[0])
 
+def get_bosserver(switch, params):
+    from afs.lib.bosserver import bosserver
+    return bosserver(params[0])
+
 def get_fileserver(switch, params):
     from afs.lib.fileserver import fileserver
     return fileserver(params[0])
diff --git a/suite/commands/bos/__init__.py b/suite/commands/bos/__init__.py
new file mode 100644 (file)
index 0000000..b1801d0
--- /dev/null
@@ -0,0 +1,62 @@
+# -*- coding: utf-8 -*-
+
+__copyright__ = """
+Copyright (C) 2014 Red Hat, Inc. All Rights Reserved.
+Written by David Howells (dhowells@redhat.com)
+
+Derived from StGIT:
+
+Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
+Copyright (C) 2008, Karl Hasselström <kha@treskal.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
+"""
+
+import os
+
+def get_command(mod):
+    """Import and return the given command module."""
+    return __import__(__name__ + '.' + mod, globals(), locals(), ['*'])
+
+def get_command_list():
+    commands = []
+    for p in __path__:
+        for fn in os.listdir(p):
+            if not fn.startswith("_") and fn.endswith('.py'):
+                commands.append(fn[:-3])
+    return commands
+
+def py_commands(commands, f):
+    f.write('command_list = {\n')
+    for key, val in sorted(commands.iteritems()):
+        f.write('    %r: %r,\n' % (key, val))
+    f.write('    }\n')
+
+#def _command_list(commands):
+#    for cmd, (mod, help) in commands.iteritems():
+
+def pretty_command_list(commands, f):
+    cmd_len = max(len(cmd) for cmd in commands.iterkeys())
+    for cmd, help in cmds:
+        f.write('  %*s  %s\n' % (-cmd_len, cmd, help))
+
+def _write_underlined(s, u, f):
+    f.write(s + '\n')
+    f.write(u*len(s) + '\n')
+
+def asciidoc_command_list(commands, f):
+    for cmd, help in commands:
+        f.write('linkstgsub:%s[]::\n' % cmd)
+        f.write('    %s\n' % help)
+    f.write('\n')
diff --git a/suite/commands/bos/getcell.py b/suite/commands/bos/getcell.py
new file mode 100644 (file)
index 0000000..32cb6f4
--- /dev/null
@@ -0,0 +1 @@
+alias = "listhosts"
diff --git a/suite/commands/bos/listhosts.py b/suite/commands/bos/listhosts.py
new file mode 100644 (file)
index 0000000..de94fd1
--- /dev/null
@@ -0,0 +1,62 @@
+#
+# AFS Server management toolkit: Report server status
+# -*- 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 *
+import kafs
+
+help = "Display the contents of the CellServDB file"
+
+command_arguments = [
+    [ "server",         get_bosserver,          "rs",         "<machine name>" ],
+    [ "cell",           get_cell,               "os",         "<cell name>" ],
+    [ "noauth",         get_auth,               "fn" ],
+    [ "localauth",      get_auth,               "fn" ],
+    [ "verbose",        get_dummy,              "fn" ],
+    [ "encrypt",        get_dummy,              "fn" ],
+]
+
+cant_combine_arguments = [
+    ( "cell",           "localauth" ),
+    ( "noauth",         "localauth" ),
+]
+
+description = r"""
+Display the contents of the CellServDB file
+"""
+
+def main(params):
+    cell = params["cell"]
+    bos_conn = cell.open_bos_server(params["server"], params)
+
+    ret = kafs.BOZO_GetCellName(bos_conn)
+    cellname = ret.name
+    print("Cell name is", cellname)
+
+    try:
+        i = 0
+        while True:
+            ret = kafs.BOZO_GetCellHost(bos_conn, i)
+            i += 1
+            print("Host", i, "is", ret.name)
+    except kafs.AbortBZDOM:
+        pass
diff --git a/suite/lib/bosserver.py b/suite/lib/bosserver.py
new file mode 100644 (file)
index 0000000..2bd046a
--- /dev/null
@@ -0,0 +1,35 @@
+#
+# AFS Volume management toolkit: BOS 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
+from afs.lib.debug import debug
+from afs.lib.server import server
+
+class bosserver(server):
+    """Represents an AFS BOS server.  We hold the server address here."""
+    def __init__(self, name):
+        debug("New BosServer", name)
+        server.__init__(self, name)
+
+    def __repr__(self):
+        return "<" + "AFSBOS:" + server.__str_(self) + ">"
index 7aa2e353c14636174bfe1d8e3636d0ead46c0745..3dcff2fb6738d71ed8c650b6e1561456a86dcefa 100644 (file)
@@ -170,3 +170,14 @@ class cell:
                                           kafs.VOLSERVICE_ID,
                                           key, security)
         return vol_conn
+
+    # Open a BOS Server connection
+    def open_bos_server(self, server, params=None):
+        key, security = self.determine_security(params)
+
+        debug("Trying", server.addr())
+        bos_conn = kafs.rx_new_connection(server.addr(),
+                                          kafs.BOSSERVICE_PORT,
+                                          kafs.BOSSERVICE_ID,
+                                          key, security)
+        return bos_conn