From 53cfd89c9fa5735ffd22b265d18e0dcf1d2cf106 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 9 Jul 2009 17:18:07 +0000 Subject: [PATCH] bunch of cleanups & fixes all over the place --- Makefile | 7 +++++- config/sfa-config-tty | 1 + config/sfa_config | 9 ++----- setup.py | 20 ++-------------- sfa.spec | 1 + sfa/client/genidump.py | 3 +-- sfa/client/sfi.py | 2 +- sfa/methods/create_gid.py | 2 ++ sfa/methods/register.py | 4 +++- sfa/plc/sfa-import-plc.py | 50 ++++++++++++++++++++------------------- sfa/plc/sfa-nuke-plc.py | 6 ++--- sfa/server/sfa-server.py | 0 sfa/trust/auth.py | 2 +- sfa/trust/gid.py | 2 +- sfa/trust/hierarchy.py | 2 +- sfa/util/geniserver.py | 5 +++- sfa/util/genitable.py | 36 +++++++++++++--------------- sfa/util/record.py | 5 +--- 18 files changed, 72 insertions(+), 85 deletions(-) mode change 100644 => 100755 sfa/server/sfa-server.py diff --git a/Makefile b/Makefile index 0ada9fea..a6965bbe 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,11 @@ RSYNC_EXCLUDES := --exclude .svn --exclude CVS --exclude '*~' --exclude TAGS $( RSYNC_COND_DRY_RUN := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,) RSYNC := rsync -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES) +BINS = ./config/sfa-config-tty ./sfa/plc/sfa-import-plc.py ./sfa/plc/sfa-nuke-plc.py \ + ./sfa/server/sfa-server.py \ + ./sfa/client/sfi.py ./sfa/client/getNodes.py ./sfa/client/getRecord.py \ + ./sfa/client/setRecord.py ./sfa/client/genidump.py + sync: ifeq (,$(SSHURL)) @echo "sync: You must define, either PLC, or PLCHOST & GUEST, on the command line" @@ -87,7 +92,7 @@ ifeq (,$(SSHURL)) @exit 1 else +$(RSYNC) ./sfa/ $(SSHURL)/usr/lib/python2.5/site-packages/sfa/ - +$(RSYNC) ./config/sfa-config-tty $(SSHURL)/usr/bin + +$(RSYNC) $(BINS) $(SSHURL)/usr/bin $(SSHCOMMAND) exec service sfa restart endif diff --git a/config/sfa-config-tty b/config/sfa-config-tty index 2cf51bc8..3e715d3f 100755 --- a/config/sfa-config-tty +++ b/config/sfa-config-tty @@ -48,6 +48,7 @@ usual_variables = ["SFA_REGISTRY_ROOT_AUTH", "SFA_REGISTRY_LEVEL1_AUTH", "SFA_PLC_USER", "SFA_PLC_PASSWORD", + "SFA_PLC_DB_HOST", "SFA_PLC_DB_USER", "SFA_PLC_DB_PASSWORD", ] diff --git a/config/sfa_config b/config/sfa_config index f8d59e93..1a7e46a7 100644 --- a/config/sfa_config +++ b/config/sfa_config @@ -73,19 +73,14 @@ SFA_PLC_USER='root@localhost.localdomain' # Password for user account SFA_PLC_PASSWORD='root' -# Hostname -# Fully qualified hostname of PLC interface +# Full URL of PLC interface SFA_PLC_URL='https://localhost:443/PLCAPI/' -# PLC Shell PATH -# This only applies if sfa services and PLC interface are running on the same machine -SFA_PLC_SHELL_PATH='/usr/share/plc_api' - # PLC DB Name SFA_PLC_DB_NAME='planetlab5' # PLC DB Host -SFA_PLC_DB_HOST='www.planet-lab.org' +SFA_PLC_DB_HOST='localhost' # PLC DB port SFA_PLC_DB_PORT=5432 diff --git a/setup.py b/setup.py index ded7f5ed..ef545cd2 100755 --- a/setup.py +++ b/setup.py @@ -32,7 +32,6 @@ data_files = [ ('/etc/sfa/', [ 'config/aggregates.xml', ]), ('/etc/init.d/', ['sfa/init.d/sfa']), ] -symlinks = [ '/usr/share/sfa' ] initscripts = [ '/etc/init.d/sfa' ] if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']: @@ -41,13 +40,14 @@ if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']: remove_dirs = ['/etc/sfa/'] + site_packages_path remove_files = [ '/usr/bin/sfa-config-tty', '/usr/bin/sfa-import-plc.py', + '/usr/bin/sfa-nuke-plc.py', '/usr/bin/sfa-server.py', '/usr/bin/sfi.py', '/usr/bin/getNodes.py', '/usr/bin/getRecord.py', '/usr/bin/setRecord.py', '/usr/bin/genidump.py', - ] + symlinks + initscripts + ] + initscripts # remove files for filepath in remove_files: @@ -75,19 +75,3 @@ else: scripts = scripts, ) - # create symlink to geniwrapper source in /usr/share - python_path = sys.path - site_packages_path = [ path + os.sep + 'sfa' for path in python_path if path.endswith('site-packages')] - # python path usualy has /usr/local/lib/ path , filter this out - site_packages_path = [x for x in site_packages_path if 'local' not in x] - - # we can not do this here as installation root might change paths - # - baris - # - # for src in site_packages_path: - # for dst in symlinks: - # try: - # os.symlink(src, dst) - # except: pass - # for initscript in initscripts: - # os.chmod(initscript, 00744) diff --git a/sfa.spec b/sfa.spec index 2c337eb8..a30ff712 100644 --- a/sfa.spec +++ b/sfa.spec @@ -76,6 +76,7 @@ rm -rf $RPM_BUILD_ROOT /etc/init.d/sfa %{_bindir}/sfa-config-tty %{_bindir}/sfa-import-plc.py* +%{_bindir}/sfa-nuke-plc.py* %{_bindir}/sfa-server.py* %files client diff --git a/sfa/client/genidump.py b/sfa/client/genidump.py index 5024fb2d..5ba11e49 100644 --- a/sfa/client/genidump.py +++ b/sfa/client/genidump.py @@ -10,9 +10,8 @@ from optparse import OptionParser from sfa.trust.certificate import Certificate from sfa.trust.credential import Credential -from sfa.trust.gid import create_uuid -from sfa.util.geniclient import GeniClient, ServerException +from sfa.util.geniclient import GeniClient from sfa.util.record import GeniRecord from sfa.util.rspec import Rspec diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index cca9e67a..aa13830e 100755 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -11,11 +11,11 @@ from optparse import OptionParser from sfa.trust.certificate import Keypair, Certificate from sfa.trust.credential import Credential -from sfa.trust.gid import create_uuid from sfa.util.geniclient import GeniClient from sfa.util.record import * from sfa.util.rspec import Rspec +from sfa.util.xmlrpcprotocol import ServerException # xxx todo xxx auto-load ~/.sfi/sfi_config diff --git a/sfa/methods/create_gid.py b/sfa/methods/create_gid.py index 2cd9e190..12fe0f68 100644 --- a/sfa/methods/create_gid.py +++ b/sfa/methods/create_gid.py @@ -6,6 +6,8 @@ from sfa.trust.certificate import Keypair from sfa.util.faults import * from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed + +from sfa.trust.gid import create_uuid from sfa.trust.auth import Auth class create_gid(Method): diff --git a/sfa/methods/register.py b/sfa/methods/register.py index 83a21f3a..9f5d019f 100644 --- a/sfa/methods/register.py +++ b/sfa/methods/register.py @@ -8,10 +8,12 @@ from sfa.util.faults import * from sfa.util.misc import * from sfa.util.method import Method from sfa.util.parameter import Parameter, Mixed -from sfa.trust.auth import Auth from sfa.util.record import GeniRecord from sfa.util.debug import log +from sfa.trust.auth import Auth +from sfa.trust.gid import create_uuid + class register(Method): """ Register an object with the registry. In addition to being stored in the diff --git a/sfa/plc/sfa-import-plc.py b/sfa/plc/sfa-import-plc.py index 4cb7513d..1ab6aed4 100755 --- a/sfa/plc/sfa-import-plc.py +++ b/sfa/plc/sfa-import-plc.py @@ -21,14 +21,16 @@ import getopt import sys import tempfile -from sfa.trust.certificate import convert_public_key, Keypair -from sfa.trust.trustedroot import * - -from sfa.trust.hierarchy import * from sfa.util.record import * -from sfa.util.genitable import * +from sfa.util.genitable import GeniTable from sfa.util.misc import * from sfa.util.config import * +from sfa.util.report import trace, error + +from sfa.trust.certificate import convert_public_key, Keypair +from sfa.trust.trustedroot import * +from sfa.trust.hierarchy import * +from sfa.trust.gid import create_uuid # get PL account settings from config module pl_auth = get_pl_auth() @@ -41,8 +43,8 @@ def connect_shell(): # connect to planetlab if "Url" in pl_auth: - from sfa.plc import remoteshell - shell = remoteshell.RemoteShell() + from sfa.plc.remoteshell import RemoteShell + shell = RemoteShell() else: import PLC.Shell shell = PLC.Shell.Shell(globals = globals()) @@ -110,7 +112,7 @@ def get_auth_table(auth_name): # into this authority yet. if not table.exists(): - report.trace("Import: creating table for authority " + auth_name) + trace("Import: creating table for authority " + auth_name) table.create() return table @@ -135,7 +137,7 @@ def import_person(parent_hrn, person): if len(hrn) > 64: hrn = hrn[:64] - report.trace("Import: importing person " + hrn) + trace("Import: importing person " + hrn) table = get_auth_table(parent_hrn) @@ -150,7 +152,7 @@ def import_person(parent_hrn, person): pkey =convert_public_key(key) else: # the user has no keys - report.trace(" person " + hrn + " does not have a PL public key") + trace(" person " + hrn + " does not have a PL public key") # if a key is unavailable, then we still need to put something in the # user's GID. So make one up. @@ -160,11 +162,11 @@ def import_person(parent_hrn, person): person_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey) person_record = table.resolve("user", hrn) if not person_record: - report.trace(" inserting user record for " + hrn) + trace(" inserting user record for " + hrn) person_record = GeniRecord(hrn=hrn, gid=person_gid, type="user", pointer=person['person_id']) table.insert(person_record) else: - report.trace(" updating user record for " + hrn) + trace(" updating user record for " + hrn) person_record = GeniRecord(hrn=hrn, gid=person_gid, type="user", pointer=person['person_id']) table.update(person_record) @@ -174,11 +176,11 @@ def import_slice(parent_hrn, slice): slicename = cleanup_string(slicename) if not slicename: - report.error("Import_Slice: failed to parse slice name " + slice['name']) + error("Import_Slice: failed to parse slice name " + slice['name']) return hrn = parent_hrn + "." + slicename - report.trace("Import: importing slice " + hrn) + trace("Import: importing slice " + hrn) table = get_auth_table(parent_hrn) @@ -187,7 +189,7 @@ def import_slice(parent_hrn, slice): pkey = Keypair(create=True) slice_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey) slice_record = GeniRecord(hrn=hrn, gid=slice_gid, type="slice", pointer=slice['slice_id']) - report.trace(" inserting slice record for " + hrn) + trace(" inserting slice record for " + hrn) table.insert(slice_record) def import_node(parent_hrn, node): @@ -196,7 +198,7 @@ def import_node(parent_hrn, node): nodename = cleanup_string(nodename) if not nodename: - report.error("Import_node: failed to parse node name " + node['hostname']) + error("Import_node: failed to parse node name " + node['hostname']) return hrn = parent_hrn + "." + nodename @@ -205,7 +207,7 @@ def import_node(parent_hrn, node): if len(hrn) > 64: hrn = hrn[:64] - report.trace("Import: importing node " + hrn) + trace("Import: importing node " + hrn) table = get_auth_table(parent_hrn) @@ -214,7 +216,7 @@ def import_node(parent_hrn, node): pkey = Keypair(create=True) node_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey) node_record = GeniRecord(hrn=hrn, gid=node_gid, type="node", pointer=node['node_id']) - report.trace(" inserting node record for " + hrn) + trace(" inserting node record for " + hrn) table.insert(node_record) def import_site(parent_hrn, site): @@ -235,7 +237,7 @@ def import_site(parent_hrn, site): hrn = ".".join([parent_hrn, "internet2", sitename]) sitename = sitename.replace("nlr", "") - report.trace("Import_Site: importing site " + hrn) + trace("Import_Site: importing site " + hrn) # create the authority if not AuthHierarchy.auth_exists(hrn): @@ -248,7 +250,7 @@ def import_site(parent_hrn, site): auth_record = table.resolve("authority", hrn) if not auth_record: auth_record = GeniRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=site['site_id']) - report.trace(" inserting authority record for " + hrn) + trace(" inserting authority record for " + hrn) table.insert(auth_record) if 'person_ids' in site: @@ -258,7 +260,7 @@ def import_site(parent_hrn, site): try: import_person(hrn, persons[0]) except Exception, e: - report.trace("Failed to import: %s (%s)" % (persons[0], e)) + trace("Failed to import: %s (%s)" % (persons[0], e)) if 'slice_ids' in site: for slice_id in site['slice_ids']: slices = shell.GetSlices(pl_auth, [slice_id]) @@ -266,7 +268,7 @@ def import_site(parent_hrn, site): try: import_slice(hrn, slices[0]) except Exception, e: - report.trace("Failed to import: %s (%s)" % (slices[0], e)) + trace("Failed to import: %s (%s)" % (slices[0], e)) if 'node_ids' in site: for node_id in site['node_ids']: nodes = shell.GetNodes(pl_auth, [node_id]) @@ -274,7 +276,7 @@ def import_site(parent_hrn, site): try: import_node(hrn, nodes[0]) except Exception, e: - report.trace("Failed to import: %s (%s)" % (nodes[0], e)) + trace("Failed to import: %s (%s)" % (nodes[0], e)) def create_top_level_auth_records(hrn): parent_hrn = get_authority(hrn) @@ -287,7 +289,7 @@ def create_top_level_auth_records(hrn): auth_record = table.resolve("authority", hrn) if not auth_record: auth_record = GeniRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=-1) - report.trace(" inserting authority record for " + hrn) + trace(" inserting authority record for " + hrn) table.insert(auth_record) def main(): diff --git a/sfa/plc/sfa-nuke-plc.py b/sfa/plc/sfa-nuke-plc.py index e347f2b9..e4095879 100755 --- a/sfa/plc/sfa-nuke-plc.py +++ b/sfa/plc/sfa-nuke-plc.py @@ -1,3 +1,4 @@ +#!/usr/bin/python ## # Delete all the database records for Geni. This tool is used to clean out Geni # records during testing. @@ -11,11 +12,10 @@ import sys from sfa.trust.hierarchy import * from sfa.util.record import * -from sfa.util.genitable import * +from sfa.util.genitable import GeniTable from sfa.util.config import * def process_options(): - global hrn (options, args) = getopt.getopt(sys.argv[1:], '', []) for opt in options: @@ -26,7 +26,7 @@ def main(): process_options() print "purging geni records from database" - geni_records_purge(get_default_dbinfo()) + GeniTable.geni_records_purge(get_default_dbinfo()) if __name__ == "__main__": main() diff --git a/sfa/server/sfa-server.py b/sfa/server/sfa-server.py old mode 100644 new mode 100755 diff --git a/sfa/trust/auth.py b/sfa/trust/auth.py index c8251d63..3b0af02a 100644 --- a/sfa/trust/auth.py +++ b/sfa/trust/auth.py @@ -12,7 +12,7 @@ from sfa.trust.trustedroot import TrustedRootList from sfa.trust.rights import RightList from sfa.util.faults import * from sfa.trust.hierarchy import Hierarchy -from sfa.util.genitable import * +from sfa.util.genitable import GeniTable from sfa.util.config import * from sfa.util.misc import * diff --git a/sfa/trust/gid.py b/sfa/trust/gid.py index 6c0436c4..c1670be6 100644 --- a/sfa/trust/gid.py +++ b/sfa/trust/gid.py @@ -7,8 +7,8 @@ ### $URL$ import xmlrpclib - import uuid + from sfa.trust.certificate import Certificate ## diff --git a/sfa/trust/hierarchy.py b/sfa/trust/hierarchy.py index 59007939..81ee1947 100644 --- a/sfa/trust/hierarchy.py +++ b/sfa/trust/hierarchy.py @@ -20,7 +20,7 @@ import os from sfa.util.report import * from sfa.trust.certificate import Keypair from sfa.trust.credential import * -from sfa.trust.gid import * +from sfa.trust.gid import GID, create_uuid from sfa.util.misc import * from sfa.util.config import * diff --git a/sfa/util/geniserver.py b/sfa/util/geniserver.py index 7159df50..ed82f01d 100644 --- a/sfa/util/geniserver.py +++ b/sfa/util/geniserver.py @@ -141,7 +141,10 @@ class SecureXMLRpcRequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler): It was copied out from SimpleXMLRPCServer.py and modified to shutdown the socket cleanly. """ - self.api = GeniAPI(peer_cert = self.server.peer_cert, interface = self.server.interface, key_file = self.server.key_file, cert_file = self.server.cert_file) + self.api = GeniAPI(peer_cert = self.server.peer_cert, + interface = self.server.interface, + key_file = self.server.key_file, + cert_file = self.server.cert_file) try: # get arguments request = self.rfile.read(int(self.headers["content-length"])) diff --git a/sfa/util/genitable.py b/sfa/util/genitable.py index 8155be48..ad276720 100644 --- a/sfa/util/genitable.py +++ b/sfa/util/genitable.py @@ -15,16 +15,16 @@ from sfa.trust.gid import * from sfa.util.record import * from sfa.util.debug import * -GENI_TABLE_PREFIX = "sfa$" - class GeniTable: + + GENI_TABLE_PREFIX = "sfa$" + def __init__(self, create=False, hrn="unspecified.default.registry", cninfo=None): - global GENI_TABLE_PREFIX self.hrn = hrn # pgsql doesn't like table names with "." in them, to replace it with "$" - self.tablename = GENI_TABLE_PREFIX + self.hrn.replace(".", "$") + self.tablename = GeniTable.GENI_TABLE_PREFIX + self.hrn.replace(".", "$") # establish a connection to the pgsql server self.cnx = DB(cninfo['dbname'], cninfo['address'], port=cninfo['port'], user=cninfo['user'], passwd=cninfo['password']) @@ -135,19 +135,15 @@ class GeniTable: result_rec_list.append(GeniRecord(dict=dict).as_dict()) return result_rec_list -def set_geni_table_prefix(x): - global GENI_TABLE_PREFIX - - GENI_TABLE_PREFIX = x - -def geni_records_purge(cninfo): - global GENI_TABLE_PREFIX - - cnx = DB(cninfo['dbname'], cninfo['address'], port=cninfo['port'], user=cninfo['user'], passwd=cninfo['password']) - tableList = cnx.get_tables() - for table in tableList: - if table.startswith(GENI_TABLE_PREFIX) or \ - table.startswith('public.' + GENI_TABLE_PREFIX) or \ - table.startswith('public."' + GENI_TABLE_PREFIX): - report.trace("dropping table " + table) - cnx.query("DROP TABLE " + table) + @staticmethod + def geni_records_purge(cninfo): + + cnx = DB(cninfo['dbname'], cninfo['address'], + port=cninfo['port'], user=cninfo['user'], passwd=cninfo['password']) + tableList = cnx.get_tables() + for table in tableList: + if table.startswith(GeniTable.GENI_TABLE_PREFIX) or \ + table.startswith('public.' + GeniTable.GENI_TABLE_PREFIX) or \ + table.startswith('public."' + GeniTable.GENI_TABLE_PREFIX): + report.trace("dropping table " + table) + cnx.query("DROP TABLE " + table) diff --git a/sfa/util/record.py b/sfa/util/record.py index 3075edb8..bfa166fe 100644 --- a/sfa/util/record.py +++ b/sfa/util/record.py @@ -229,10 +229,7 @@ class GeniRecord(dict): """ Given a list of field names, return a list of values for those public. """ - strs = [] - for fieldname in fieldnames: - strs.append(self.get_field_value_string(fieldname)) - return strs + return [ self.get_field_value_string (fieldname) for fieldname in fieldnames ] ## # Return the record in the form of a dictionary -- 2.43.0