From: David Howells Date: Fri, 11 Apr 2014 15:46:18 +0000 (+0100) Subject: Implement "bos listhosts" and "bos getcell" X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c01805d20cd2ad60845745408d15cd07b87acd24;p=users%2Fdhowells%2Fkafs-utils.git Implement "bos listhosts" and "bos getcell" Signed-off-by: David Howells --- diff --git a/rpc-api/bos.xg b/rpc-api/bos.xg index e7273b3..4eb67f5 100644 --- a/rpc-api/bos.xg +++ b/rpc-api/bos.xg @@ -37,6 +37,9 @@ package BOZO_ +const BOSSERVICE_PORT = 7007; +const BOSSERVICE_ID = 1; + /* Error codes */ const BZNOTACTIVE = 39424; const BZNOENT = 39425; diff --git a/suite/argparse.py b/suite/argparse.py index 9c57d53..6acb714 100644 --- a/suite/argparse.py +++ b/suite/argparse.py @@ -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 index 0000000..b1801d0 --- /dev/null +++ b/suite/commands/bos/__init__.py @@ -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 +Copyright (C) 2008, Karl Hasselström + +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 index 0000000..32cb6f4 --- /dev/null +++ b/suite/commands/bos/getcell.py @@ -0,0 +1 @@ +alias = "listhosts" diff --git a/suite/commands/bos/listhosts.py b/suite/commands/bos/listhosts.py new file mode 100644 index 0000000..de94fd1 --- /dev/null +++ b/suite/commands/bos/listhosts.py @@ -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", "" ], + [ "cell", get_cell, "os", "" ], + [ "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 index 0000000..2bd046a --- /dev/null +++ b/suite/lib/bosserver.py @@ -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) + ">" diff --git a/suite/lib/cell.py b/suite/lib/cell.py index 7aa2e35..3dcff2f 100644 --- a/suite/lib/cell.py +++ b/suite/lib/cell.py @@ -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