From owner-p4-projects@FreeBSD.ORG Sun May 27 21:46:38 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 20FE216A49E; Sun, 27 May 2007 21:46:38 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id AD8EA16A4C9 for ; Sun, 27 May 2007 21:46:37 +0000 (UTC) (envelope-from ivoras@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 9168313C455 for ; Sun, 27 May 2007 21:46:37 +0000 (UTC) (envelope-from ivoras@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l4RLkbeL089908 for ; Sun, 27 May 2007 21:46:37 GMT (envelope-from ivoras@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l4RLkbnK089902 for perforce@freebsd.org; Sun, 27 May 2007 21:46:37 GMT (envelope-from ivoras@FreeBSD.org) Date: Sun, 27 May 2007 21:46:37 GMT Message-Id: <200705272146.l4RLkbnK089902@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to ivoras@FreeBSD.org using -f From: Ivan Voras To: Perforce Change Reviews Cc: Subject: PERFORCE change 120477 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 May 2007 21:46:38 -0000 http://perforce.freebsd.org/chv.cgi?CH=120477 Change 120477 by ivoras@ivoras_finstall on 2007/05/27 21:45:37 - Fix sysctl retrieval, wrt \0 characters - Implement GEOM confxml tree retrieval - Implement GetDrives() XML-RPC function Affected files ... .. //depot/projects/soc2007/ivoras_finstall/pybackend/freebsd.py#3 edit .. //depot/projects/soc2007/ivoras_finstall/pybackend/systoold.py#4 edit .. //depot/projects/soc2007/ivoras_finstall/pybackend/systoolengine.py#4 edit .. //depot/projects/soc2007/ivoras_finstall/pybackend/testtool/st.py#2 edit .. //depot/projects/soc2007/ivoras_finstall/pybackend/xmldict.py#3 edit Differences ... ==== //depot/projects/soc2007/ivoras_finstall/pybackend/freebsd.py#3 (text+ko) ==== @@ -22,15 +22,35 @@ # Interface to (most) FreeBSD's low-level utilities import os, sys +import xmldict cmd_sysctl = "/sbin/sysctl" cmd_geom = "/sbin/geom" cmd_mount = "/sbin/mount" +file_dmesg = "/var/run/dmesg.boot" + def get_sysctl(name): global cmd_sysctl - return os.popen("%s -b %s" % (cmd_sysctl, name)) + str = os.popen("%s -b %s" % (cmd_sysctl, name)).read().strip() + while str[-1] == "\0": + str = str[:-1] + return str def get_cmd_output(name): - return os.popen(name).read() + return os.popen(name).read().strip() + +def get_dmesg(): + global file_dmesg + return [x.strip() for x in file(file_dmesg, "r").readlines()] + +def get_geom_xml(): + return xmldict.buildxmldict(get_sysctl("kern.geom.confxml")) + +if __name__ == "__main__": + xml = get_geom_xml() + for cls in xml["mesh"]["class"]: + if cls["name"].data == "DISK": + for geom in cls["geom"]: + print geom["name"].data, geom["provider"]["mediasize"].data ==== //depot/projects/soc2007/ivoras_finstall/pybackend/systoold.py#4 (text+ko) ==== @@ -28,7 +28,7 @@ import os,sys from getopt import getopt, GetoptError from select import select -from SimpleXMLRPCServer import SimpleXMLRPCServer +from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler import globals from systoolengine import SysToolEngine @@ -65,19 +65,25 @@ sys.exit(1) +def ToUpper(str): + return str.upper() + engine = SysToolEngine() -server = SimpleXMLRPCServer((bind_host, bind_port), None, globals.debug_level > 0) +server = SimpleXMLRPCServer((bind_host, bind_port), SimpleXMLRPCRequestHandler, globals.debug_level > 0) server.register_introspection_functions() +server.register_function(ToUpper) server.register_instance(engine) +while not globals.exit_systoold: + try: + r,w,e = select([server.fileno()], [], [], 100) + if r: + # Only handle requests if there's a connection pending + # This is done to enable (somewhat) graceful exiting of this + # TCP connection handler loop + server.handle_request() + except KeyboardInterrupt: + break -while not globals.exit_systoold: - r,w,e = select([server.socket], [], [], 100) - print r - if r: - # Only handle requests if there's a connection pending - # This is done to enable (somewhat) graceful exiting of this - # TCP connection handler loop - server.handle_request() - +server.server_close() ==== //depot/projects/soc2007/ivoras_finstall/pybackend/systoolengine.py#4 (text+ko) ==== @@ -78,7 +78,33 @@ Examines "kern.drives" sysctl. This is NOT the list of valid GEOM leaves which can be mounted, but a list of found hardware.""" - return freebsd.get_sysctl("kern.disks").split(" ") + drive_list = freebsd.get_sysctl("kern.disks").split(" ") + dmesg = freebsd.get_dmesg() + drive_dict = {} + for drive in drive_list: + found = False + # try finding a line containing a "<" in hope that it's a description + for line in dmesg: + if line.startswith("%s:" % drive) and line.find("<") != -1: + drive_dict[drive] = {"name" : line[len(drive)+2:]} + found = True + if not found: + # try finding the longest line + drive_dict[drive] = {"name": ""} + for line in dmesg: + if line.startswith("%s:" % drive) and len(drive_dict[drive]["name"]) < len(line)-len(drive)-2: + drive_dict[drive] = {"name": line[len(drive)+2:]} + found = True + if not found: + drive_dict[drive]["name"] = "(unknown)" + geomxml = freebsd.get_geom_xml() + for cls in geomxml["mesh"]["class"]: + if cls["name"].data == "DISK": + for geom in cls["geom"]: + dev_name = geom["name"].data + if dev_name in drive_dict: + drive_dict[dev_name]["mediasize"] = int(geom["provider"]["mediasize"].data) / (1024*1024) # in MB, since XML-RPC doesn't have int64 + return drive_dict def GetMountPoints(self): ==== //depot/projects/soc2007/ivoras_finstall/pybackend/testtool/st.py#2 (text+ko) ==== @@ -23,4 +23,12 @@ # The purpose if this utility is mainly to test the XML-RPC calls in the # SysToolD +import sys +from xmlrpclib import ServerProxy + +server = ServerProxy("http://localhost:1025") +if not "systoold" in server.GetCaps(): + print "This is a bogus server" + sys.exit(1) +print server.GetDrives() ==== //depot/projects/soc2007/ivoras_finstall/pybackend/xmldict.py#3 (text+ko) ==== @@ -181,11 +181,15 @@ def builddict(self): """Builds a nested-dictionary-like structure from the xml. This method picks up tags on the main level and calls processTag() for nested tags.""" + global DEBUG d = Tag('', '') while True: tag, attrs, data = self.getnexttag() - if data != '': # data is actually between the last tag and this one + if data != '' and data != "\0": # data is actually between the last tag and this one sys.stderr.write("Warning: inline data between tags?!\n") + if DEBUG: + sys.stderr.write(" ^^^ |"+data+"|\n") + sys.stderr.write(" len=%d" % len(data)) if not tag: break if tag[-1] == '/': # an 'empty' tag (e.g. )